snesuploader.ll 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. ; ModuleID = '/Users/david/Devel/arch/avr/code/snesram/poc/avr_usbload/commandline/snesuploader.c'
  2. target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
  3. target triple = "i386-apple-darwin9"
  4. %struct.__sFILE = type <{ i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }>
  5. %struct.__sFILEX = type opaque
  6. %struct.__sbuf = type <{ i8*, i32 }>
  7. %struct.usb_dev_handle = type opaque
  8. @"\01LC" = internal constant [3 x i8] c"*\0A\00" ; <[3 x i8]*> [#uses=1]
  9. @"\01LC1" = internal constant [6 x i8] c"%08x:\00" ; <[6 x i8]*> [#uses=1]
  10. @"\01LC2" = internal constant [6 x i8] c" %02x\00" ; <[6 x i8]*> [#uses=1]
  11. @"\01LC3" = internal constant [3 x i8] c" |\00" ; <[3 x i8]*> [#uses=1]
  12. @"\01LC4" = internal constant [3 x i8] c"%c\00" ; <[3 x i8]*> [#uses=1]
  13. @"\01LC5" = internal constant [2 x i8] c".\00" ; <[2 x i8]*> [#uses=1]
  14. @"\01LC6" = internal constant [3 x i8] c"|\0A\00" ; <[3 x i8]*> [#uses=1]
  15. @__stderrp = external global %struct.__sFILE* ; <%struct.__sFILE**> [#uses=8]
  16. @"\01LC7" = internal constant [55 x i8] c"Could not find USB device \22%s\22 with vid=0x%x pid=0x%x\0A\00" ; <[55 x i8]*> [#uses=1]
  17. @"\01LC8" = internal constant [45 x i8] c"Open USB device \22%s\22 with vid=0x%x pid=0x%x\0A\00" ; <[45 x i8]*> [#uses=1]
  18. @"\01LC9" = internal constant [7 x i8] c"upload\00" ; <[7 x i8]*> [#uses=1]
  19. @"\01LC10" = internal constant [2 x i8] c"r\00" ; <[2 x i8]*> [#uses=1]
  20. @"\01LC11" = internal constant [21 x i8] c"Cannot open file %s \00" ; <[21 x i8]*> [#uses=1]
  21. @"\01LC12" = internal constant [70 x i8] c"Addr: 0x%06x Bank: 0x%02x HiAddr: 0x%02x LoAddr: 0x%04x Crc: 0x%04x\0A\00" ; <[70 x i8]*> [#uses=1]
  22. @"\01LC13" = internal constant [15 x i8] c"USB error: %s\0A\00" ; <[15 x i8]*> [#uses=1]
  23. @"\01LC14" = internal constant [25 x i8] c"only %d bytes received.\0A\00" ; <[25 x i8]*> [#uses=1]
  24. @"\01LC15" = internal constant [4 x i8] c"crc\00" ; <[4 x i8]*> [#uses=1]
  25. @"\01LC16" = internal constant [30 x i8] c"Request CRC for Addr: 0x%06x\0A\00" ; <[30 x i8]*> [#uses=1]
  26. @"\01LC17" = internal constant [8 x i8] c"usage:\0A\00" ; <[8 x i8]*> [#uses=1]
  27. @"\01LC18" = internal constant [31 x i8] c" %s upload filename.. upload\0A\00" ; <[31 x i8]*> [#uses=1]
  28. define void @dump_packet(i32 %addr, i32 %len, i8* %packet) nounwind {
  29. entry:
  30. %addr.addr = alloca i32 ; <i32*> [#uses=2]
  31. %len.addr = alloca i32 ; <i32*> [#uses=2]
  32. %packet.addr = alloca i8* ; <i8**> [#uses=6]
  33. %i = alloca i16, align 2 ; <i16*> [#uses=10]
  34. %j = alloca i16, align 2 ; <i16*> [#uses=17]
  35. %sum = alloca i16, align 2 ; <i16*> [#uses=5]
  36. %clear = alloca i8, align 1 ; <i8*> [#uses=4]
  37. store i32 %addr, i32* %addr.addr
  38. store i32 %len, i32* %len.addr
  39. store i8* %packet, i8** %packet.addr
  40. store i16 0, i16* %sum
  41. store i8 0, i8* %clear
  42. store i16 0, i16* %i
  43. br label %for.cond
  44. for.cond: ; preds = %for.inc98, %entry
  45. %tmp = load i16* %i ; <i16> [#uses=1]
  46. %conv = zext i16 %tmp to i32 ; <i32> [#uses=1]
  47. %tmp1 = load i32* %len.addr ; <i32> [#uses=1]
  48. %cmp = icmp ult i32 %conv, %tmp1 ; <i1> [#uses=1]
  49. br i1 %cmp, label %for.body, label %for.end103
  50. for.body: ; preds = %for.cond
  51. store i16 0, i16* %sum
  52. store i16 0, i16* %j
  53. br label %for.cond3
  54. for.cond3: ; preds = %for.inc, %for.body
  55. %tmp4 = load i16* %j ; <i16> [#uses=1]
  56. %conv5 = zext i16 %tmp4 to i32 ; <i32> [#uses=1]
  57. %cmp6 = icmp slt i32 %conv5, 16 ; <i1> [#uses=1]
  58. br i1 %cmp6, label %for.body8, label %for.end
  59. for.body8: ; preds = %for.cond3
  60. %tmp9 = load i16* %sum ; <i16> [#uses=1]
  61. %conv10 = zext i16 %tmp9 to i32 ; <i32> [#uses=1]
  62. %tmp11 = load i16* %i ; <i16> [#uses=1]
  63. %conv12 = zext i16 %tmp11 to i32 ; <i32> [#uses=1]
  64. %tmp13 = load i16* %j ; <i16> [#uses=1]
  65. %conv14 = zext i16 %tmp13 to i32 ; <i32> [#uses=1]
  66. %add = add i32 %conv12, %conv14 ; <i32> [#uses=1]
  67. %tmp15 = load i8** %packet.addr ; <i8*> [#uses=1]
  68. %arrayidx = getelementptr i8* %tmp15, i32 %add ; <i8*> [#uses=1]
  69. %tmp16 = load i8* %arrayidx ; <i8> [#uses=1]
  70. %conv17 = zext i8 %tmp16 to i32 ; <i32> [#uses=1]
  71. %add18 = add i32 %conv10, %conv17 ; <i32> [#uses=1]
  72. %conv19 = trunc i32 %add18 to i16 ; <i16> [#uses=1]
  73. store i16 %conv19, i16* %sum
  74. br label %for.inc
  75. for.inc: ; preds = %for.body8
  76. %tmp20 = load i16* %j ; <i16> [#uses=1]
  77. %inc = add i16 %tmp20, 1 ; <i16> [#uses=1]
  78. store i16 %inc, i16* %j
  79. br label %for.cond3
  80. for.end: ; preds = %for.cond3
  81. %tmp21 = load i16* %sum ; <i16> [#uses=1]
  82. %tobool = icmp ne i16 %tmp21, 0 ; <i1> [#uses=1]
  83. br i1 %tobool, label %if.end, label %if.then
  84. if.then: ; preds = %for.end
  85. store i8 1, i8* %clear
  86. br label %for.inc98
  87. if.end: ; preds = %for.end
  88. %tmp22 = load i8* %clear ; <i8> [#uses=1]
  89. %tobool23 = icmp ne i8 %tmp22, 0 ; <i1> [#uses=1]
  90. br i1 %tobool23, label %if.then24, label %if.end25
  91. if.then24: ; preds = %if.end
  92. %call = call i32 (i8*, ...)* @printf(i8* getelementptr ([3 x i8]* @"\01LC", i32 0, i32 0)) ; <i32> [#uses=0]
  93. store i8 0, i8* %clear
  94. br label %if.end25
  95. if.end25: ; preds = %if.then24, %if.end
  96. %tmp26 = load i32* %addr.addr ; <i32> [#uses=1]
  97. %tmp27 = load i16* %i ; <i16> [#uses=1]
  98. %conv28 = zext i16 %tmp27 to i32 ; <i32> [#uses=1]
  99. %add29 = add i32 %tmp26, %conv28 ; <i32> [#uses=1]
  100. %call30 = call i32 (i8*, ...)* @printf(i8* getelementptr ([6 x i8]* @"\01LC1", i32 0, i32 0), i32 %add29) ; <i32> [#uses=0]
  101. store i16 0, i16* %j
  102. br label %for.cond31
  103. for.cond31: ; preds = %for.inc47, %if.end25
  104. %tmp32 = load i16* %j ; <i16> [#uses=1]
  105. %conv33 = zext i16 %tmp32 to i32 ; <i32> [#uses=1]
  106. %cmp34 = icmp slt i32 %conv33, 16 ; <i1> [#uses=1]
  107. br i1 %cmp34, label %for.body36, label %for.end50
  108. for.body36: ; preds = %for.cond31
  109. %tmp37 = load i16* %i ; <i16> [#uses=1]
  110. %conv38 = zext i16 %tmp37 to i32 ; <i32> [#uses=1]
  111. %tmp39 = load i16* %j ; <i16> [#uses=1]
  112. %conv40 = zext i16 %tmp39 to i32 ; <i32> [#uses=1]
  113. %add41 = add i32 %conv38, %conv40 ; <i32> [#uses=1]
  114. %tmp42 = load i8** %packet.addr ; <i8*> [#uses=1]
  115. %arrayidx43 = getelementptr i8* %tmp42, i32 %add41 ; <i8*> [#uses=1]
  116. %tmp44 = load i8* %arrayidx43 ; <i8> [#uses=1]
  117. %conv45 = zext i8 %tmp44 to i32 ; <i32> [#uses=1]
  118. %call46 = call i32 (i8*, ...)* @printf(i8* getelementptr ([6 x i8]* @"\01LC2", i32 0, i32 0), i32 %conv45) ; <i32> [#uses=0]
  119. br label %for.inc47
  120. for.inc47: ; preds = %for.body36
  121. %tmp48 = load i16* %j ; <i16> [#uses=1]
  122. %inc49 = add i16 %tmp48, 1 ; <i16> [#uses=1]
  123. store i16 %inc49, i16* %j
  124. br label %for.cond31
  125. for.end50: ; preds = %for.cond31
  126. %call51 = call i32 (i8*, ...)* @printf(i8* getelementptr ([3 x i8]* @"\01LC3", i32 0, i32 0)) ; <i32> [#uses=0]
  127. store i16 0, i16* %j
  128. br label %for.cond52
  129. for.cond52: ; preds = %for.inc93, %for.end50
  130. %tmp53 = load i16* %j ; <i16> [#uses=1]
  131. %conv54 = zext i16 %tmp53 to i32 ; <i32> [#uses=1]
  132. %cmp55 = icmp slt i32 %conv54, 16 ; <i1> [#uses=1]
  133. br i1 %cmp55, label %for.body57, label %for.end96
  134. for.body57: ; preds = %for.cond52
  135. %tmp58 = load i16* %i ; <i16> [#uses=1]
  136. %conv59 = zext i16 %tmp58 to i32 ; <i32> [#uses=1]
  137. %tmp60 = load i16* %j ; <i16> [#uses=1]
  138. %conv61 = zext i16 %tmp60 to i32 ; <i32> [#uses=1]
  139. %add62 = add i32 %conv59, %conv61 ; <i32> [#uses=1]
  140. %tmp63 = load i8** %packet.addr ; <i8*> [#uses=1]
  141. %arrayidx64 = getelementptr i8* %tmp63, i32 %add62 ; <i8*> [#uses=1]
  142. %tmp65 = load i8* %arrayidx64 ; <i8> [#uses=1]
  143. %conv66 = zext i8 %tmp65 to i32 ; <i32> [#uses=1]
  144. %cmp67 = icmp sge i32 %conv66, 33 ; <i1> [#uses=1]
  145. br i1 %cmp67, label %land.lhs.true, label %if.else
  146. land.lhs.true: ; preds = %for.body57
  147. %tmp69 = load i16* %i ; <i16> [#uses=1]
  148. %conv70 = zext i16 %tmp69 to i32 ; <i32> [#uses=1]
  149. %tmp71 = load i16* %j ; <i16> [#uses=1]
  150. %conv72 = zext i16 %tmp71 to i32 ; <i32> [#uses=1]
  151. %add73 = add i32 %conv70, %conv72 ; <i32> [#uses=1]
  152. %tmp74 = load i8** %packet.addr ; <i8*> [#uses=1]
  153. %arrayidx75 = getelementptr i8* %tmp74, i32 %add73 ; <i8*> [#uses=1]
  154. %tmp76 = load i8* %arrayidx75 ; <i8> [#uses=1]
  155. %conv77 = zext i8 %tmp76 to i32 ; <i32> [#uses=1]
  156. %cmp78 = icmp sle i32 %conv77, 126 ; <i1> [#uses=1]
  157. br i1 %cmp78, label %if.then80, label %if.else
  158. if.then80: ; preds = %land.lhs.true
  159. %tmp81 = load i16* %i ; <i16> [#uses=1]
  160. %conv82 = zext i16 %tmp81 to i32 ; <i32> [#uses=1]
  161. %tmp83 = load i16* %j ; <i16> [#uses=1]
  162. %conv84 = zext i16 %tmp83 to i32 ; <i32> [#uses=1]
  163. %add85 = add i32 %conv82, %conv84 ; <i32> [#uses=1]
  164. %tmp86 = load i8** %packet.addr ; <i8*> [#uses=1]
  165. %arrayidx87 = getelementptr i8* %tmp86, i32 %add85 ; <i8*> [#uses=1]
  166. %tmp88 = load i8* %arrayidx87 ; <i8> [#uses=1]
  167. %conv89 = zext i8 %tmp88 to i32 ; <i32> [#uses=1]
  168. %call90 = call i32 (i8*, ...)* @printf(i8* getelementptr ([3 x i8]* @"\01LC4", i32 0, i32 0), i32 %conv89) ; <i32> [#uses=0]
  169. br label %if.end92
  170. if.else: ; preds = %land.lhs.true, %for.body57
  171. %call91 = call i32 (i8*, ...)* @printf(i8* getelementptr ([2 x i8]* @"\01LC5", i32 0, i32 0)) ; <i32> [#uses=0]
  172. br label %if.end92
  173. if.end92: ; preds = %if.else, %if.then80
  174. br label %for.inc93
  175. for.inc93: ; preds = %if.end92
  176. %tmp94 = load i16* %j ; <i16> [#uses=1]
  177. %inc95 = add i16 %tmp94, 1 ; <i16> [#uses=1]
  178. store i16 %inc95, i16* %j
  179. br label %for.cond52
  180. for.end96: ; preds = %for.cond52
  181. %call97 = call i32 (i8*, ...)* @printf(i8* getelementptr ([3 x i8]* @"\01LC6", i32 0, i32 0)) ; <i32> [#uses=0]
  182. br label %for.inc98
  183. for.inc98: ; preds = %for.end96, %if.then
  184. %tmp99 = load i16* %i ; <i16> [#uses=1]
  185. %conv100 = zext i16 %tmp99 to i32 ; <i32> [#uses=1]
  186. %add101 = add i32 %conv100, 16 ; <i32> [#uses=1]
  187. %conv102 = trunc i32 %add101 to i16 ; <i16> [#uses=1]
  188. store i16 %conv102, i16* %i
  189. br label %for.cond
  190. for.end103: ; preds = %for.cond
  191. ret void
  192. }
  193. declare i32 @printf(i8*, ...)
  194. define zeroext i16 @crc_xmodem_update(i16 zeroext %crc, i8 zeroext %data) nounwind {
  195. entry:
  196. %retval = alloca i16 ; <i16*> [#uses=2]
  197. %crc.addr = alloca i16 ; <i16*> [#uses=9]
  198. %data.addr = alloca i8 ; <i8*> [#uses=2]
  199. %i = alloca i32, align 4 ; <i32*> [#uses=4]
  200. store i16 %crc, i16* %crc.addr
  201. store i8 %data, i8* %data.addr
  202. %tmp = load i16* %crc.addr ; <i16> [#uses=1]
  203. %conv = zext i16 %tmp to i32 ; <i32> [#uses=1]
  204. %tmp1 = load i8* %data.addr ; <i8> [#uses=1]
  205. %conv2 = zext i8 %tmp1 to i32 ; <i32> [#uses=1]
  206. %conv3 = trunc i32 %conv2 to i16 ; <i16> [#uses=1]
  207. %conv4 = zext i16 %conv3 to i32 ; <i32> [#uses=1]
  208. %shl = shl i32 %conv4, 8 ; <i32> [#uses=1]
  209. %xor = xor i32 %conv, %shl ; <i32> [#uses=1]
  210. %conv5 = trunc i32 %xor to i16 ; <i16> [#uses=1]
  211. store i16 %conv5, i16* %crc.addr
  212. store i32 0, i32* %i
  213. br label %for.cond
  214. for.cond: ; preds = %for.inc, %entry
  215. %tmp6 = load i32* %i ; <i32> [#uses=1]
  216. %cmp = icmp slt i32 %tmp6, 8 ; <i1> [#uses=1]
  217. br i1 %cmp, label %for.body, label %for.end
  218. for.body: ; preds = %for.cond
  219. %tmp8 = load i16* %crc.addr ; <i16> [#uses=1]
  220. %conv9 = zext i16 %tmp8 to i32 ; <i32> [#uses=1]
  221. %and = and i32 %conv9, 32768 ; <i32> [#uses=1]
  222. %tobool = icmp ne i32 %and, 0 ; <i1> [#uses=1]
  223. br i1 %tobool, label %if.then, label %if.else
  224. if.then: ; preds = %for.body
  225. %tmp10 = load i16* %crc.addr ; <i16> [#uses=1]
  226. %conv11 = zext i16 %tmp10 to i32 ; <i32> [#uses=1]
  227. %shl12 = shl i32 %conv11, 1 ; <i32> [#uses=1]
  228. %xor13 = xor i32 %shl12, 4129 ; <i32> [#uses=1]
  229. %conv14 = trunc i32 %xor13 to i16 ; <i16> [#uses=1]
  230. store i16 %conv14, i16* %crc.addr
  231. br label %if.end
  232. if.else: ; preds = %for.body
  233. %tmp15 = load i16* %crc.addr ; <i16> [#uses=1]
  234. %conv16 = zext i16 %tmp15 to i32 ; <i32> [#uses=1]
  235. %shl17 = shl i32 %conv16, 1 ; <i32> [#uses=1]
  236. %conv18 = trunc i32 %shl17 to i16 ; <i16> [#uses=1]
  237. store i16 %conv18, i16* %crc.addr
  238. br label %if.end
  239. if.end: ; preds = %if.else, %if.then
  240. br label %for.inc
  241. for.inc: ; preds = %if.end
  242. %tmp19 = load i32* %i ; <i32> [#uses=1]
  243. %inc = add i32 %tmp19, 1 ; <i32> [#uses=1]
  244. store i32 %inc, i32* %i
  245. br label %for.cond
  246. for.end: ; preds = %for.cond
  247. %tmp20 = load i16* %crc.addr ; <i16> [#uses=1]
  248. store i16 %tmp20, i16* %retval
  249. %0 = load i16* %retval ; <i16> [#uses=1]
  250. ret i16 %0
  251. }
  252. define zeroext i16 @do_crc(i8* %data, i16 zeroext %size) nounwind {
  253. entry:
  254. %retval = alloca i16 ; <i16*> [#uses=2]
  255. %data.addr = alloca i8* ; <i8**> [#uses=2]
  256. %size.addr = alloca i16 ; <i16*> [#uses=2]
  257. %crc = alloca i16, align 2 ; <i16*> [#uses=4]
  258. %i = alloca i16, align 2 ; <i16*> [#uses=5]
  259. store i8* %data, i8** %data.addr
  260. store i16 %size, i16* %size.addr
  261. store i16 0, i16* %crc
  262. store i16 0, i16* %i
  263. br label %for.cond
  264. for.cond: ; preds = %for.inc, %entry
  265. %tmp = load i16* %i ; <i16> [#uses=1]
  266. %conv = zext i16 %tmp to i32 ; <i32> [#uses=1]
  267. %tmp1 = load i16* %size.addr ; <i16> [#uses=1]
  268. %conv2 = zext i16 %tmp1 to i32 ; <i32> [#uses=1]
  269. %cmp = icmp slt i32 %conv, %conv2 ; <i1> [#uses=1]
  270. br i1 %cmp, label %for.body, label %for.end
  271. for.body: ; preds = %for.cond
  272. %tmp4 = load i16* %crc ; <i16> [#uses=1]
  273. %tmp5 = load i16* %i ; <i16> [#uses=1]
  274. %tmp6 = load i8** %data.addr ; <i8*> [#uses=1]
  275. %idxprom = zext i16 %tmp5 to i32 ; <i32> [#uses=1]
  276. %arrayidx = getelementptr i8* %tmp6, i32 %idxprom ; <i8*> [#uses=1]
  277. %tmp7 = load i8* %arrayidx ; <i8> [#uses=1]
  278. %call = call zeroext i16 @crc_xmodem_update(i16 zeroext %tmp4, i8 zeroext %tmp7) ; <i16> [#uses=1]
  279. store i16 %call, i16* %crc
  280. br label %for.inc
  281. for.inc: ; preds = %for.body
  282. %tmp8 = load i16* %i ; <i16> [#uses=1]
  283. %inc = add i16 %tmp8, 1 ; <i16> [#uses=1]
  284. store i16 %inc, i16* %i
  285. br label %for.cond
  286. for.end: ; preds = %for.cond
  287. %tmp9 = load i16* %crc ; <i16> [#uses=1]
  288. store i16 %tmp9, i16* %retval
  289. %0 = load i16* %retval ; <i16> [#uses=1]
  290. ret i16 %0
  291. }
  292. define zeroext i16 @do_crc_update(i16 zeroext %crc, i8* %data, i16 zeroext %size) nounwind {
  293. entry:
  294. %retval = alloca i16 ; <i16*> [#uses=2]
  295. %crc.addr = alloca i16 ; <i16*> [#uses=4]
  296. %data.addr = alloca i8* ; <i8**> [#uses=2]
  297. %size.addr = alloca i16 ; <i16*> [#uses=2]
  298. %i = alloca i16, align 2 ; <i16*> [#uses=5]
  299. store i16 %crc, i16* %crc.addr
  300. store i8* %data, i8** %data.addr
  301. store i16 %size, i16* %size.addr
  302. store i16 0, i16* %i
  303. br label %for.cond
  304. for.cond: ; preds = %for.inc, %entry
  305. %tmp = load i16* %i ; <i16> [#uses=1]
  306. %conv = zext i16 %tmp to i32 ; <i32> [#uses=1]
  307. %tmp1 = load i16* %size.addr ; <i16> [#uses=1]
  308. %conv2 = zext i16 %tmp1 to i32 ; <i32> [#uses=1]
  309. %cmp = icmp slt i32 %conv, %conv2 ; <i1> [#uses=1]
  310. br i1 %cmp, label %for.body, label %for.end
  311. for.body: ; preds = %for.cond
  312. %tmp4 = load i16* %crc.addr ; <i16> [#uses=1]
  313. %tmp5 = load i16* %i ; <i16> [#uses=1]
  314. %tmp6 = load i8** %data.addr ; <i8*> [#uses=1]
  315. %idxprom = zext i16 %tmp5 to i32 ; <i32> [#uses=1]
  316. %arrayidx = getelementptr i8* %tmp6, i32 %idxprom ; <i8*> [#uses=1]
  317. %tmp7 = load i8* %arrayidx ; <i8> [#uses=1]
  318. %call = call zeroext i16 @crc_xmodem_update(i16 zeroext %tmp4, i8 zeroext %tmp7) ; <i16> [#uses=1]
  319. store i16 %call, i16* %crc.addr
  320. br label %for.inc
  321. for.inc: ; preds = %for.body
  322. %tmp8 = load i16* %i ; <i16> [#uses=1]
  323. %inc = add i16 %tmp8, 1 ; <i16> [#uses=1]
  324. store i16 %inc, i16* %i
  325. br label %for.cond
  326. for.end: ; preds = %for.cond
  327. %tmp9 = load i16* %crc.addr ; <i16> [#uses=1]
  328. store i16 %tmp9, i16* %retval
  329. %0 = load i16* %retval ; <i16> [#uses=1]
  330. ret i16 %0
  331. }
  332. define i32 @main(i32 %argc, i8** %argv) nounwind {
  333. entry:
  334. %retval = alloca i32 ; <i32*> [#uses=2]
  335. %argc.addr = alloca i32 ; <i32*> [#uses=3]
  336. %argv.addr = alloca i8** ; <i8***> [#uses=8]
  337. %handle = alloca %struct.usb_dev_handle*, align 4 ; <%struct.usb_dev_handle**> [#uses=7]
  338. %rawVid = alloca [2 x i8], align 1 ; <[2 x i8]*> [#uses=4]
  339. %rawPid = alloca [2 x i8], align 1 ; <[2 x i8]*> [#uses=4]
  340. %vendor = alloca [11 x i8], align 1 ; <[11 x i8]*> [#uses=12]
  341. %product = alloca [8 x i8], align 1 ; <[8 x i8]*> [#uses=11]
  342. %cnt = alloca i32, align 4 ; <i32*> [#uses=9]
  343. %vid = alloca i32, align 4 ; <i32*> [#uses=4]
  344. %pid = alloca i32, align 4 ; <i32*> [#uses=4]
  345. %cnt_crc = alloca i32, align 4 ; <i32*> [#uses=6]
  346. %read_buffer = alloca i8*, align 4 ; <i8**> [#uses=4]
  347. %crc_buffer = alloca i8*, align 4 ; <i8**> [#uses=5]
  348. %addr = alloca i32, align 4 ; <i32*> [#uses=11]
  349. %addr_lo = alloca i16, align 2 ; <i16*> [#uses=7]
  350. %addr_hi = alloca i16, align 2 ; <i16*> [#uses=7]
  351. %step = alloca i16, align 2 ; <i16*> [#uses=6]
  352. %crc = alloca i16, align 2 ; <i16*> [#uses=3]
  353. %bank = alloca i8, align 1 ; <i8*> [#uses=4]
  354. %fp = alloca %struct.__sFILE*, align 4 ; <%struct.__sFILE**> [#uses=3]
  355. store i32 %argc, i32* %argc.addr
  356. store i8** %argv, i8*** %argv.addr
  357. store %struct.usb_dev_handle* null, %struct.usb_dev_handle** %handle
  358. %.array = getelementptr [2 x i8]* %rawVid, i32 0, i32 0 ; <i8*> [#uses=1]
  359. store i8 -64, i8* %.array
  360. %.array1 = getelementptr [2 x i8]* %rawVid, i32 0, i32 1 ; <i8*> [#uses=1]
  361. store i8 22, i8* %.array1
  362. %.array2 = getelementptr [2 x i8]* %rawPid, i32 0, i32 0 ; <i8*> [#uses=1]
  363. store i8 -36, i8* %.array2
  364. %.array3 = getelementptr [2 x i8]* %rawPid, i32 0, i32 1 ; <i8*> [#uses=1]
  365. store i8 5, i8* %.array3
  366. %.array4 = getelementptr [11 x i8]* %vendor, i32 0, i32 0 ; <i8*> [#uses=1]
  367. store i8 111, i8* %.array4
  368. %.array5 = getelementptr [11 x i8]* %vendor, i32 0, i32 1 ; <i8*> [#uses=1]
  369. store i8 112, i8* %.array5
  370. %.array6 = getelementptr [11 x i8]* %vendor, i32 0, i32 2 ; <i8*> [#uses=1]
  371. store i8 116, i8* %.array6
  372. %.array7 = getelementptr [11 x i8]* %vendor, i32 0, i32 3 ; <i8*> [#uses=1]
  373. store i8 105, i8* %.array7
  374. %.array8 = getelementptr [11 x i8]* %vendor, i32 0, i32 4 ; <i8*> [#uses=1]
  375. store i8 120, i8* %.array8
  376. %.array9 = getelementptr [11 x i8]* %vendor, i32 0, i32 5 ; <i8*> [#uses=1]
  377. store i8 120, i8* %.array9
  378. %.array10 = getelementptr [11 x i8]* %vendor, i32 0, i32 6 ; <i8*> [#uses=1]
  379. store i8 46, i8* %.array10
  380. %.array11 = getelementptr [11 x i8]* %vendor, i32 0, i32 7 ; <i8*> [#uses=1]
  381. store i8 111, i8* %.array11
  382. %.array12 = getelementptr [11 x i8]* %vendor, i32 0, i32 8 ; <i8*> [#uses=1]
  383. store i8 114, i8* %.array12
  384. %.array13 = getelementptr [11 x i8]* %vendor, i32 0, i32 9 ; <i8*> [#uses=1]
  385. store i8 103, i8* %.array13
  386. %.array14 = getelementptr [11 x i8]* %vendor, i32 0, i32 10 ; <i8*> [#uses=1]
  387. store i8 0, i8* %.array14
  388. %.array15 = getelementptr [8 x i8]* %product, i32 0, i32 0 ; <i8*> [#uses=1]
  389. store i8 83, i8* %.array15
  390. %.array16 = getelementptr [8 x i8]* %product, i32 0, i32 1 ; <i8*> [#uses=1]
  391. store i8 78, i8* %.array16
  392. %.array17 = getelementptr [8 x i8]* %product, i32 0, i32 2 ; <i8*> [#uses=1]
  393. store i8 69, i8* %.array17
  394. %.array18 = getelementptr [8 x i8]* %product, i32 0, i32 3 ; <i8*> [#uses=1]
  395. store i8 83, i8* %.array18
  396. %.array19 = getelementptr [8 x i8]* %product, i32 0, i32 4 ; <i8*> [#uses=1]
  397. store i8 82, i8* %.array19
  398. %.array20 = getelementptr [8 x i8]* %product, i32 0, i32 5 ; <i8*> [#uses=1]
  399. store i8 65, i8* %.array20
  400. %.array21 = getelementptr [8 x i8]* %product, i32 0, i32 6 ; <i8*> [#uses=1]
  401. store i8 77, i8* %.array21
  402. %.array22 = getelementptr [8 x i8]* %product, i32 0, i32 7 ; <i8*> [#uses=1]
  403. store i8 0, i8* %.array22
  404. store i32 0, i32* %cnt_crc
  405. store i32 0, i32* %addr
  406. store i16 0, i16* %addr_lo
  407. store i16 0, i16* %addr_hi
  408. store i16 0, i16* %step
  409. store i16 0, i16* %crc
  410. store i8 0, i8* %bank
  411. call void @usb_init()
  412. %tmp = load i32* %argc.addr ; <i32> [#uses=1]
  413. %cmp = icmp slt i32 %tmp, 2 ; <i1> [#uses=1]
  414. br i1 %cmp, label %if.then, label %if.end
  415. if.then: ; preds = %entry
  416. %tmp23 = load i8*** %argv.addr ; <i8**> [#uses=1]
  417. %arrayidx = getelementptr i8** %tmp23, i32 0 ; <i8**> [#uses=1]
  418. %tmp24 = load i8** %arrayidx ; <i8*> [#uses=1]
  419. call void @usage(i8* %tmp24)
  420. call void @exit(i32 1) noreturn
  421. unreachable
  422. ; No predecessors!
  423. br label %if.end
  424. if.end: ; preds = %0, %entry
  425. %arraydecay = getelementptr [2 x i8]* %rawVid, i32 0, i32 0 ; <i8*> [#uses=1]
  426. %arrayidx25 = getelementptr i8* %arraydecay, i32 1 ; <i8*> [#uses=1]
  427. %tmp26 = load i8* %arrayidx25 ; <i8> [#uses=1]
  428. %conv = zext i8 %tmp26 to i32 ; <i32> [#uses=1]
  429. %mul = mul i32 %conv, 256 ; <i32> [#uses=1]
  430. %arraydecay27 = getelementptr [2 x i8]* %rawVid, i32 0, i32 0 ; <i8*> [#uses=1]
  431. %arrayidx28 = getelementptr i8* %arraydecay27, i32 0 ; <i8*> [#uses=1]
  432. %tmp29 = load i8* %arrayidx28 ; <i8> [#uses=1]
  433. %conv30 = zext i8 %tmp29 to i32 ; <i32> [#uses=1]
  434. %add = add i32 %mul, %conv30 ; <i32> [#uses=1]
  435. store i32 %add, i32* %vid
  436. %arraydecay31 = getelementptr [2 x i8]* %rawPid, i32 0, i32 0 ; <i8*> [#uses=1]
  437. %arrayidx32 = getelementptr i8* %arraydecay31, i32 1 ; <i8*> [#uses=1]
  438. %tmp33 = load i8* %arrayidx32 ; <i8> [#uses=1]
  439. %conv34 = zext i8 %tmp33 to i32 ; <i32> [#uses=1]
  440. %mul35 = mul i32 %conv34, 256 ; <i32> [#uses=1]
  441. %arraydecay36 = getelementptr [2 x i8]* %rawPid, i32 0, i32 0 ; <i8*> [#uses=1]
  442. %arrayidx37 = getelementptr i8* %arraydecay36, i32 0 ; <i8*> [#uses=1]
  443. %tmp38 = load i8* %arrayidx37 ; <i8> [#uses=1]
  444. %conv39 = zext i8 %tmp38 to i32 ; <i32> [#uses=1]
  445. %add40 = add i32 %mul35, %conv39 ; <i32> [#uses=1]
  446. store i32 %add40, i32* %pid
  447. %tmp41 = load i32* %vid ; <i32> [#uses=1]
  448. %arraydecay42 = getelementptr [11 x i8]* %vendor, i32 0, i32 0 ; <i8*> [#uses=1]
  449. %tmp43 = load i32* %pid ; <i32> [#uses=1]
  450. %arraydecay44 = getelementptr [8 x i8]* %product, i32 0, i32 0 ; <i8*> [#uses=1]
  451. %call = call i32 @usbOpenDevice(%struct.usb_dev_handle** %handle, i32 %tmp41, i8* %arraydecay42, i32 %tmp43, i8* %arraydecay44, i8* null, %struct.__sFILE* null, %struct.__sFILE* null) ; <i32> [#uses=1]
  452. %cmp45 = icmp ne i32 %call, 0 ; <i1> [#uses=1]
  453. br i1 %cmp45, label %if.then47, label %if.end53
  454. if.then47: ; preds = %if.end
  455. %tmp48 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
  456. %arraydecay49 = getelementptr [8 x i8]* %product, i32 0, i32 0 ; <i8*> [#uses=1]
  457. %tmp50 = load i32* %vid ; <i32> [#uses=1]
  458. %tmp51 = load i32* %pid ; <i32> [#uses=1]
  459. %call52 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp48, i8* getelementptr ([55 x i8]* @"\01LC7", i32 0, i32 0), i8* %arraydecay49, i32 %tmp50, i32 %tmp51) ; <i32> [#uses=0]
  460. call void @exit(i32 1) noreturn
  461. unreachable
  462. ; No predecessors!
  463. br label %if.end53
  464. if.end53: ; preds = %1, %if.end
  465. %arraydecay54 = getelementptr [8 x i8]* %product, i32 0, i32 0 ; <i8*> [#uses=1]
  466. %tmp55 = load i32* %vid ; <i32> [#uses=1]
  467. %tmp56 = load i32* %pid ; <i32> [#uses=1]
  468. %call57 = call i32 (i8*, ...)* @printf(i8* getelementptr ([45 x i8]* @"\01LC8", i32 0, i32 0), i8* %arraydecay54, i32 %tmp55, i32 %tmp56) ; <i32> [#uses=0]
  469. %tmp58 = load i8*** %argv.addr ; <i8**> [#uses=1]
  470. %arrayidx59 = getelementptr i8** %tmp58, i32 1 ; <i8**> [#uses=1]
  471. %tmp60 = load i8** %arrayidx59 ; <i8*> [#uses=1]
  472. %call61 = call i32 @strcasecmp(i8* %tmp60, i8* getelementptr ([7 x i8]* @"\01LC9", i32 0, i32 0)) ; <i32> [#uses=1]
  473. %cmp62 = icmp eq i32 %call61, 0 ; <i1> [#uses=1]
  474. br i1 %cmp62, label %if.then64, label %if.else171
  475. if.then64: ; preds = %if.end53
  476. %tmp65 = load i32* %argc.addr ; <i32> [#uses=1]
  477. %cmp66 = icmp slt i32 %tmp65, 3 ; <i1> [#uses=1]
  478. br i1 %cmp66, label %if.then68, label %if.end72
  479. if.then68: ; preds = %if.then64
  480. %tmp69 = load i8*** %argv.addr ; <i8**> [#uses=1]
  481. %arrayidx70 = getelementptr i8** %tmp69, i32 0 ; <i8**> [#uses=1]
  482. %tmp71 = load i8** %arrayidx70 ; <i8*> [#uses=1]
  483. call void @usage(i8* %tmp71)
  484. call void @exit(i32 1) noreturn
  485. unreachable
  486. ; No predecessors!
  487. br label %if.end72
  488. if.end72: ; preds = %2, %if.then64
  489. %tmp73 = load i8*** %argv.addr ; <i8**> [#uses=1]
  490. %arrayidx74 = getelementptr i8** %tmp73, i32 2 ; <i8**> [#uses=1]
  491. %tmp75 = load i8** %arrayidx74 ; <i8*> [#uses=1]
  492. %call76 = call %struct.__sFILE* @fopen(i8* %tmp75, i8* getelementptr ([2 x i8]* @"\01LC10", i32 0, i32 0)) ; <%struct.__sFILE*> [#uses=1]
  493. store %struct.__sFILE* %call76, %struct.__sFILE** %fp
  494. %tmp77 = load %struct.__sFILE** %fp ; <%struct.__sFILE*> [#uses=1]
  495. %cmp78 = icmp eq %struct.__sFILE* %tmp77, null ; <i1> [#uses=1]
  496. br i1 %cmp78, label %if.then80, label %if.end86
  497. if.then80: ; preds = %if.end72
  498. %tmp81 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
  499. %tmp82 = load i8*** %argv.addr ; <i8**> [#uses=1]
  500. %arrayidx83 = getelementptr i8** %tmp82, i32 2 ; <i8**> [#uses=1]
  501. %tmp84 = load i8** %arrayidx83 ; <i8*> [#uses=1]
  502. %call85 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp81, i8* getelementptr ([21 x i8]* @"\01LC11", i32 0, i32 0), i8* %tmp84) ; <i32> [#uses=0]
  503. call void @exit(i32 1) noreturn
  504. unreachable
  505. ; No predecessors!
  506. br label %if.end86
  507. if.end86: ; preds = %3, %if.end72
  508. %call87 = call i8* @malloc(i32 1024) ; <i8*> [#uses=1]
  509. store i8* %call87, i8** %read_buffer
  510. %call88 = call i8* @malloc(i32 32768) ; <i8*> [#uses=1]
  511. store i8* %call88, i8** %crc_buffer
  512. %tmp89 = load i8** %crc_buffer ; <i8*> [#uses=1]
  513. %call90 = call i8* @memset(i8* %tmp89, i32 0, i32 32768) ; <i8*> [#uses=0]
  514. store i32 0, i32* %addr
  515. %tmp91 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
  516. %call92 = call i32 @usb_control_msg(%struct.usb_dev_handle* %tmp91, i32 64, i32 0, i32 0, i32 0, i8* null, i32 0, i32 5000) ; <i32> [#uses=0]
  517. br label %while.cond
  518. while.cond: ; preds = %if.end148, %if.end86
  519. %tmp93 = load i8** %read_buffer ; <i8*> [#uses=1]
  520. %tmp94 = load %struct.__sFILE** %fp ; <%struct.__sFILE*> [#uses=1]
  521. %call95 = call i32 @fread(i8* %tmp93, i32 1024, i32 1, %struct.__sFILE* %tmp94) ; <i32> [#uses=2]
  522. store i32 %call95, i32* %cnt
  523. %cmp96 = icmp sgt i32 %call95, 0 ; <i1> [#uses=1]
  524. br i1 %cmp96, label %while.body, label %while.end
  525. while.body: ; preds = %while.cond
  526. store i16 0, i16* %step
  527. br label %for.cond
  528. for.cond: ; preds = %for.inc, %while.body
  529. %tmp98 = load i16* %step ; <i16> [#uses=1]
  530. %conv99 = zext i16 %tmp98 to i32 ; <i32> [#uses=1]
  531. %cmp100 = icmp slt i32 %conv99, 1024 ; <i1> [#uses=1]
  532. br i1 %cmp100, label %for.body, label %for.end
  533. for.body: ; preds = %for.cond
  534. %tmp102 = load i32* %addr ; <i32> [#uses=1]
  535. %and = and i32 %tmp102, 65535 ; <i32> [#uses=1]
  536. %conv103 = trunc i32 %and to i16 ; <i16> [#uses=1]
  537. store i16 %conv103, i16* %addr_lo
  538. %tmp104 = load i32* %addr ; <i32> [#uses=1]
  539. %shr = lshr i32 %tmp104, 16 ; <i32> [#uses=1]
  540. %and105 = and i32 %shr, 255 ; <i32> [#uses=1]
  541. %conv106 = trunc i32 %and105 to i16 ; <i16> [#uses=1]
  542. store i16 %conv106, i16* %addr_hi
  543. %tmp107 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
  544. %tmp108 = load i16* %addr_hi ; <i16> [#uses=1]
  545. %conv109 = zext i16 %tmp108 to i32 ; <i32> [#uses=1]
  546. %tmp110 = load i16* %addr_lo ; <i16> [#uses=1]
  547. %conv111 = zext i16 %tmp110 to i32 ; <i32> [#uses=1]
  548. %tmp112 = load i8** %read_buffer ; <i8*> [#uses=1]
  549. %tmp113 = load i16* %step ; <i16> [#uses=1]
  550. %conv114 = zext i16 %tmp113 to i32 ; <i32> [#uses=1]
  551. %add.ptr = getelementptr i8* %tmp112, i32 %conv114 ; <i8*> [#uses=1]
  552. %call115 = call i32 @usb_control_msg(%struct.usb_dev_handle* %tmp107, i32 64, i32 1, i32 %conv109, i32 %conv111, i8* %add.ptr, i32 128, i32 5000) ; <i32> [#uses=0]
  553. %tmp116 = load i32* %addr ; <i32> [#uses=1]
  554. %add117 = add i32 %tmp116, 128 ; <i32> [#uses=1]
  555. store i32 %add117, i32* %addr
  556. br label %for.inc
  557. for.inc: ; preds = %for.body
  558. %tmp118 = load i16* %step ; <i16> [#uses=1]
  559. %conv119 = zext i16 %tmp118 to i32 ; <i32> [#uses=1]
  560. %add120 = add i32 %conv119, 128 ; <i32> [#uses=1]
  561. %conv121 = trunc i32 %add120 to i16 ; <i16> [#uses=1]
  562. store i16 %conv121, i16* %step
  563. br label %for.cond
  564. for.end: ; preds = %for.cond
  565. %tmp122 = load i8** %crc_buffer ; <i8*> [#uses=1]
  566. %tmp123 = load i32* %cnt_crc ; <i32> [#uses=1]
  567. %add.ptr124 = getelementptr i8* %tmp122, i32 %tmp123 ; <i8*> [#uses=1]
  568. %tmp125 = load i8** %read_buffer ; <i8*> [#uses=1]
  569. %call126 = call i8* @memcpy(i8* %add.ptr124, i8* %tmp125, i32 1024) ; <i8*> [#uses=0]
  570. %tmp127 = load i32* %cnt_crc ; <i32> [#uses=1]
  571. %add128 = add i32 %tmp127, 1024 ; <i32> [#uses=1]
  572. store i32 %add128, i32* %cnt_crc
  573. %tmp129 = load i32* %cnt_crc ; <i32> [#uses=1]
  574. %cmp130 = icmp sge i32 %tmp129, 32768 ; <i1> [#uses=1]
  575. br i1 %cmp130, label %if.then132, label %if.end148
  576. if.then132: ; preds = %for.end
  577. %tmp133 = load i8** %crc_buffer ; <i8*> [#uses=1]
  578. %call134 = call zeroext i16 @do_crc(i8* %tmp133, i16 zeroext -32768) ; <i16> [#uses=1]
  579. store i16 %call134, i16* %crc
  580. %tmp135 = load i32* %addr ; <i32> [#uses=1]
  581. %tmp136 = load i8* %bank ; <i8> [#uses=1]
  582. %conv137 = zext i8 %tmp136 to i32 ; <i32> [#uses=1]
  583. %tmp138 = load i16* %addr_hi ; <i16> [#uses=1]
  584. %conv139 = zext i16 %tmp138 to i32 ; <i32> [#uses=1]
  585. %tmp140 = load i16* %addr_lo ; <i16> [#uses=1]
  586. %conv141 = zext i16 %tmp140 to i32 ; <i32> [#uses=1]
  587. %tmp142 = load i16* %crc ; <i16> [#uses=1]
  588. %conv143 = zext i16 %tmp142 to i32 ; <i32> [#uses=1]
  589. %call144 = call i32 (i8*, ...)* @printf(i8* getelementptr ([70 x i8]* @"\01LC12", i32 0, i32 0), i32 %tmp135, i32 %conv137, i32 %conv139, i32 %conv141, i32 %conv143) ; <i32> [#uses=0]
  590. %tmp145 = load i8** %crc_buffer ; <i8*> [#uses=1]
  591. %call146 = call i8* @memset(i8* %tmp145, i32 0, i32 32768) ; <i8*> [#uses=0]
  592. %tmp147 = load i8* %bank ; <i8> [#uses=1]
  593. %inc = add i8 %tmp147, 1 ; <i8> [#uses=1]
  594. store i8 %inc, i8* %bank
  595. store i32 0, i32* %cnt_crc
  596. br label %if.end148
  597. if.end148: ; preds = %if.then132, %for.end
  598. br label %while.cond
  599. while.end: ; preds = %while.cond
  600. %tmp149 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
  601. %tmp150 = load i16* %addr_hi ; <i16> [#uses=1]
  602. %conv151 = zext i16 %tmp150 to i32 ; <i32> [#uses=1]
  603. %tmp152 = load i16* %addr_lo ; <i16> [#uses=1]
  604. %conv153 = zext i16 %tmp152 to i32 ; <i32> [#uses=1]
  605. %call154 = call i32 @usb_control_msg(%struct.usb_dev_handle* %tmp149, i32 64, i32 4, i32 %conv151, i32 %conv153, i8* null, i32 0, i32 5000) ; <i32> [#uses=1]
  606. store i32 %call154, i32* %cnt
  607. %tmp155 = load i32* %cnt ; <i32> [#uses=1]
  608. %cmp156 = icmp slt i32 %tmp155, 1 ; <i1> [#uses=1]
  609. br i1 %cmp156, label %if.then158, label %if.end170
  610. if.then158: ; preds = %while.end
  611. %tmp159 = load i32* %cnt ; <i32> [#uses=1]
  612. %cmp160 = icmp slt i32 %tmp159, 0 ; <i1> [#uses=1]
  613. br i1 %cmp160, label %if.then162, label %if.else
  614. if.then162: ; preds = %if.then158
  615. %tmp163 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
  616. %call164 = call i8* @usb_strerror() ; <i8*> [#uses=1]
  617. %call165 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp163, i8* getelementptr ([15 x i8]* @"\01LC13", i32 0, i32 0), i8* %call164) ; <i32> [#uses=0]
  618. br label %if.end169
  619. if.else: ; preds = %if.then158
  620. %tmp166 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
  621. %tmp167 = load i32* %cnt ; <i32> [#uses=1]
  622. %call168 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp166, i8* getelementptr ([25 x i8]* @"\01LC14", i32 0, i32 0), i32 %tmp167) ; <i32> [#uses=0]
  623. br label %if.end169
  624. if.end169: ; preds = %if.else, %if.then162
  625. br label %if.end170
  626. if.end170: ; preds = %if.end169, %while.end
  627. br label %if.end216
  628. if.else171: ; preds = %if.end53
  629. %tmp172 = load i8*** %argv.addr ; <i8**> [#uses=1]
  630. %arrayidx173 = getelementptr i8** %tmp172, i32 1 ; <i8**> [#uses=1]
  631. %tmp174 = load i8** %arrayidx173 ; <i8*> [#uses=1]
  632. %call175 = call i32 @strcasecmp(i8* %tmp174, i8* getelementptr ([4 x i8]* @"\01LC15", i32 0, i32 0)) ; <i32> [#uses=1]
  633. %cmp176 = icmp eq i32 %call175, 0 ; <i1> [#uses=1]
  634. br i1 %cmp176, label %if.then178, label %if.else211
  635. if.then178: ; preds = %if.else171
  636. store i32 0, i32* %addr
  637. %tmp179 = load i32* %addr ; <i32> [#uses=1]
  638. %and180 = and i32 %tmp179, 65535 ; <i32> [#uses=1]
  639. %conv181 = trunc i32 %and180 to i16 ; <i16> [#uses=1]
  640. store i16 %conv181, i16* %addr_lo
  641. %tmp182 = load i32* %addr ; <i32> [#uses=1]
  642. %shr183 = lshr i32 %tmp182, 16 ; <i32> [#uses=1]
  643. %and184 = and i32 %shr183, 255 ; <i32> [#uses=1]
  644. %conv185 = trunc i32 %and184 to i16 ; <i16> [#uses=1]
  645. store i16 %conv185, i16* %addr_hi
  646. %tmp186 = load i32* %addr ; <i32> [#uses=1]
  647. %call187 = call i32 (i8*, ...)* @printf(i8* getelementptr ([30 x i8]* @"\01LC16", i32 0, i32 0), i32 %tmp186) ; <i32> [#uses=0]
  648. %tmp188 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
  649. %tmp189 = load i16* %addr_hi ; <i16> [#uses=1]
  650. %conv190 = zext i16 %tmp189 to i32 ; <i32> [#uses=1]
  651. %tmp191 = load i16* %addr_lo ; <i16> [#uses=1]
  652. %conv192 = zext i16 %tmp191 to i32 ; <i32> [#uses=1]
  653. %call193 = call i32 @usb_control_msg(%struct.usb_dev_handle* %tmp188, i32 64, i32 5, i32 %conv190, i32 %conv192, i8* null, i32 8192, i32 5000) ; <i32> [#uses=1]
  654. store i32 %call193, i32* %cnt
  655. %tmp194 = load i32* %cnt ; <i32> [#uses=1]
  656. %cmp195 = icmp slt i32 %tmp194, 1 ; <i1> [#uses=1]
  657. br i1 %cmp195, label %if.then197, label %if.end210
  658. if.then197: ; preds = %if.then178
  659. %tmp198 = load i32* %cnt ; <i32> [#uses=1]
  660. %cmp199 = icmp slt i32 %tmp198, 0 ; <i1> [#uses=1]
  661. br i1 %cmp199, label %if.then201, label %if.else205
  662. if.then201: ; preds = %if.then197
  663. %tmp202 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
  664. %call203 = call i8* @usb_strerror() ; <i8*> [#uses=1]
  665. %call204 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp202, i8* getelementptr ([15 x i8]* @"\01LC13", i32 0, i32 0), i8* %call203) ; <i32> [#uses=0]
  666. br label %if.end209
  667. if.else205: ; preds = %if.then197
  668. %tmp206 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
  669. %tmp207 = load i32* %cnt ; <i32> [#uses=1]
  670. %call208 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp206, i8* getelementptr ([25 x i8]* @"\01LC14", i32 0, i32 0), i32 %tmp207) ; <i32> [#uses=0]
  671. br label %if.end209
  672. if.end209: ; preds = %if.else205, %if.then201
  673. br label %if.end210
  674. if.end210: ; preds = %if.end209, %if.then178
  675. br label %if.end215
  676. if.else211: ; preds = %if.else171
  677. %tmp212 = load i8*** %argv.addr ; <i8**> [#uses=1]
  678. %arrayidx213 = getelementptr i8** %tmp212, i32 0 ; <i8**> [#uses=1]
  679. %tmp214 = load i8** %arrayidx213 ; <i8*> [#uses=1]
  680. call void @usage(i8* %tmp214)
  681. call void @exit(i32 1) noreturn
  682. unreachable
  683. ; No predecessors!
  684. br label %if.end215
  685. if.end215: ; preds = %4, %if.end210
  686. br label %if.end216
  687. if.end216: ; preds = %if.end215, %if.end170
  688. %tmp217 = load %struct.usb_dev_handle** %handle ; <%struct.usb_dev_handle*> [#uses=1]
  689. %call218 = call i32 @usb_close(%struct.usb_dev_handle* %tmp217) ; <i32> [#uses=0]
  690. store i32 0, i32* %retval
  691. %5 = load i32* %retval ; <i32> [#uses=1]
  692. ret i32 %5
  693. }
  694. declare void @usb_init()
  695. define internal void @usage(i8* %name) nounwind {
  696. entry:
  697. %name.addr = alloca i8* ; <i8**> [#uses=2]
  698. store i8* %name, i8** %name.addr
  699. %tmp = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
  700. %call = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp, i8* getelementptr ([8 x i8]* @"\01LC17", i32 0, i32 0)) ; <i32> [#uses=0]
  701. %tmp1 = load %struct.__sFILE** @__stderrp ; <%struct.__sFILE*> [#uses=1]
  702. %tmp2 = load i8** %name.addr ; <i8*> [#uses=1]
  703. %call3 = call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %tmp1, i8* getelementptr ([31 x i8]* @"\01LC18", i32 0, i32 0), i8* %tmp2) ; <i32> [#uses=0]
  704. ret void
  705. }
  706. declare void @exit(i32) noreturn
  707. declare i32 @usbOpenDevice(%struct.usb_dev_handle**, i32, i8*, i32, i8*, i8*, %struct.__sFILE*, %struct.__sFILE*)
  708. declare i32 @fprintf(%struct.__sFILE*, i8*, ...)
  709. declare i32 @strcasecmp(i8*, i8*)
  710. declare %struct.__sFILE* @fopen(i8*, i8*)
  711. declare i8* @malloc(i32)
  712. declare i8* @memset(i8*, i32, i32)
  713. declare i32 @usb_control_msg(%struct.usb_dev_handle*, i32, i32, i32, i32, i8*, i32, i32)
  714. declare i32 @fread(i8*, i32, i32, %struct.__sFILE*)
  715. declare i8* @memcpy(i8*, i8*, i32)
  716. declare i8* @usb_strerror()
  717. declare i32 @usb_close(%struct.usb_dev_handle*)