#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ error(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
unsigned int strtoul(char *, char **, int);
int main(int argc, char *argv[]) {
  char *endptr;
  unsigned int loadAddr;
  FILE *infile;
  FILE *outfile;
  int numBytes, i;
  int c;
  unsigned char lineData[16];
  unsigned int chksum;
  if (argc != 4) {
    printf("Usage: %s <load addr, hex> <input file> <output file>\n", argv[0]);
    exit(1);
  }
  loadAddr = strtoul(argv[1], &endptr, 16);
  if (*endptr != '\0') {
    error("illegal load address %s", argv[1]);
  }
  infile = fopen(argv[2], "rb");
  if (infile == NULL) {
    error("cannot open input file %s", argv[2]);
  }
  outfile = fopen(argv[3], "wt");
  if (outfile == NULL) {
    error("cannot open output file %s", argv[3]);
  }
  fprintf(outfile, ":02000004");
  fprintf(outfile, "%04X", loadAddr >> 16);
  chksum = 0x02 + 0x04 + ((loadAddr >> 24) & 0xFF) + ((loadAddr >> 16) & 0xFF);
  fprintf(outfile, "%02X\n", (-chksum) & 0xFF);
  while (1) {
    chksum = 0;
    for (numBytes = 0; numBytes < 16; numBytes++) {
      c = fgetc(infile);
      if (c == EOF) {
        break;
      }
      lineData[numBytes] = c;
      chksum += c;
    }
    if (numBytes == 0) {
      break;
    }
    fprintf(outfile, ":%02X%04X00", numBytes, loadAddr & 0xFFFF);
    for (i = 0; i < numBytes; i++) {
      fprintf(outfile, "%02X", lineData[i]);
    }
    chksum += numBytes;
    chksum += ((loadAddr >> 8) & 0xFF) + ((loadAddr >> 0) & 0xFF);
    fprintf(outfile, "%02X\n", (-chksum) & 0xFF);
    loadAddr += numBytes;
    if (c == EOF) {
      break;
    }
  }
  fprintf(outfile, ":00000001FF\n");
  fclose(infile);
  fclose(outfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11bd <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1090 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fa <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe42(%rip),%rdi
call   1070 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe46(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1231 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe26(%rip),%rdi
call   1070 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1268 <main+0xe8>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xe0c(%rip),%rdi
call   1070 <error@plt>
mov    -0x30(%rbp),%rdi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
shr    $0x10,%edx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
add    $0x6,%eax
mov    -0x1c(%rbp),%ecx
shr    $0x10,%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rdi
xor    %edx,%edx
sub    -0x54(%rbp),%edx
and    $0xff,%edx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x10,-0x34(%rbp)
jge    132d <main+0x1ad>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2cec(%rip),%rcx
cmp    (%rcx),%eax
jne    1309 <main+0x189>
jmp    132d <main+0x1ad>
mov    -0x3c(%rbp),%eax
mov    %al,%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x3c(%rbp),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12dc <main+0x15c>
cmpl   $0x0,-0x34(%rbp)
jne    133c <main+0x1bc>
jmp    1400 <main+0x280>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x1c(%rbp),%ecx
and    $0xffff,%ecx
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1396 <main+0x216>
mov    -0x30(%rbp),%rdi
movslq -0x38(%rbp),%rax
movzbl -0x50(%rbp,%rax,1),%edx
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1361 <main+0x1e1>
mov    -0x34(%rbp),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    -0x1c(%rbp),%ecx
shr    $0x0,%ecx
and    $0xff,%ecx
add    %ecx,%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rdi
xor    %edx,%edx
sub    -0x54(%rbp),%edx
and    $0xff,%edx
lea    0xcc5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2bfa(%rip),%rcx
cmp    (%rcx),%eax
jne    13fb <main+0x27b>
jmp    1400 <main+0x280>
jmp    12ce <main+0x14e>
mov    -0x30(%rbp),%rdi
lea    0xca5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbp
cmp    $0x4,%edi
jne    1540 <main+0x3b0>
mov    0x8(%rbp),%rdi
lea    0x30(%rsp),%rsi
mov    $0x10,%edx
call   1090 <strtoul@plt>
mov    %eax,0x24(%rsp)
mov    0x30(%rsp),%rax
cmpb   $0x0,(%rax)
je     11db <main+0x4b>
mov    0x8(%rbp),%rsi
lea    0xe61(%rip),%rdi
call   1070 <error@plt>
mov    0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1203 <main+0x73>
mov    0x10(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1070 <error@plt>
mov    0x18(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    122b <main+0x9b>
mov    0x18(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1070 <error@plt>
lea    0xe58(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
mov    0x24(%rsp),%r14d
mov    %r14d,%ebp
shr    $0x10,%ebp
lea    0xe3e(%rip),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%eax
shr    $0x18,%eax
add    %ebp,%eax
mov    $0xfa,%ecx
sub    %eax,%ecx
movzbl %cl,%edx
lea    0xe1e(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d5c(%rip),%r14
lea    0xe18(%rip),%r13
mov    %rbx,0x28(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%eax
je     1506 <main+0x376>
mov    %eax,%r12d
mov    %r12b,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x1,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x11(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x2,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x12(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x3,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x13(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x4,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x14(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x5,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x15(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x6,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x16(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x7,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x17(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x8,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x18(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0x9,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x19(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0xa,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x1a(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0xb,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x1b(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0xc,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x1c(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0xd,%ebp
cmp    (%r14),%eax
je     1440 <main+0x2b0>
mov    %al,0x1d(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0xe,%ebp
cmp    (%r14),%eax
jne    14d4 <main+0x344>
nopl   0x0(%rax,%rax,1)
mov    %eax,0xc(%rsp)
mov    0x24(%rsp),%eax
mov    %eax,%r14d
movzwl %ax,%ecx
mov    %r15,%rdi
lea    0xc47(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x10(%rsp,%rbx,1),%edx
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1470 <main+0x2e0>
add    %ebp,%r12d
mov    %r14d,%eax
shr    $0x8,%eax
add    %r14d,%eax
add    %r12d,%eax
neg    %eax
movzbl %al,%edx
mov    %r15,%rdi
lea    0xbf0(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    %r14d,%ebp
mov    %ebp,%eax
mov    %ebp,0x24(%rsp)
mov    0x2b28(%rip),%r14
mov    0xc(%rsp),%eax
cmp    (%r14),%eax
mov    0x28(%rsp),%rbx
jne    12a0 <main+0x110>
jmp    1506 <main+0x376>
mov    %al,0x1e(%rsp)
add    %eax,%r12d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    $0xf,%ebp
cmp    (%r14),%eax
mov    %eax,0xc(%rsp)
je     1444 <main+0x2b4>
mov    %al,0x1f(%rsp)
add    %eax,%r12d
mov    $0x10,%ebp
jmp    1444 <main+0x2b4>
lea    0xba3(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%rsi
lea    0xab5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [55 x i8] c"Usage: %s <load addr, hex> <input file> <output file>\0A\00"
@.str.1 = [24 x i8] c"illegal load address %s\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [26 x i8] c"cannot open input file %s\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [27 x i8] c"cannot open output file %s\00"
@.str.6 = [10 x i8] c":02000004\00"
@.str.7 = [5 x i8] c"%04X\00"
@.str.8 = [6 x i8] c"%02X\0A\00"
@EOF = global i32 0
@.str.9 = [12 x i8] c":%02X%04X00\00"
@.str.10 = [5 x i8] c"%02X\00"
@.str.11 = [13 x i8] c":00000001FF\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [16 x i8]
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 4
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strtoul(i8* %26, i8** %6, i32 16)
store i32 %27, i32* %7
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %23
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %32, %23
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %41, i32** %8
%42 = load i32*, i32** %8
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %49
44: ; preds = %37
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %44, %37
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
%53 = call i32* @fopen(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %53, i32** %9
%54 = load i32*, i32** %9
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %61
56: ; preds = %49
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %56, %49
%62 = load i32*, i32** %9
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%64 = load i32*, i32** %9
%65 = load i32, i32* %7
%66 = lshr i32 %65, 16
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %7
%69 = lshr i32 %68, 24
%70 = and i32 %69, 255
%71 = add i32 6, %70
%72 = load i32, i32* %7
%73 = lshr i32 %72, 16
%74 = and i32 %73, 255
%75 = add i32 %71, %74
store i32 %75, i32* %14
%76 = load i32*, i32** %9
%77 = load i32, i32* %14
%78 = sub i32 0, %77
%79 = and i32 %78, 255
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %79)
br label %81
81: ; preds = %61, %154
store i32 0, i32* %14
store i32 0, i32* %10
br label %82
82: ; preds = %101, %81
%83 = load i32, i32* %10
%84 = icmp slt i32 %83, 16
br i1 %84, label %85, label %104
85: ; preds = %82
%86 = load i32*, i32** %8
%87 = call i32 @fgetc(i32* %86)
store i32 %87, i32* %12
%88 = load i32, i32* %12
%89 = load i32, i32* @EOF
%90 = icmp eq i32 %88, %89
br i1 %90, label %91, label %92
91: ; preds = %85
br label %104
92: ; preds = %85
%93 = load i32, i32* %12
%94 = trunc i32 %93 to i8
%95 = load i32, i32* %10
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 %96
store i8 %94, i8* %97
%98 = load i32, i32* %12
%99 = load i32, i32* %14
%100 = add i32 %99, %98
store i32 %100, i32* %14
br label %101
101: ; preds = %92
%102 = load i32, i32* %10
%103 = add nsw i32 %102, 1
store i32 %103, i32* %10
br label %82
104: ; preds = %91, %82
%105 = load i32, i32* %10
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %104
br label %155
108: ; preds = %104
%109 = load i32*, i32** %9
%110 = load i32, i32* %10
%111 = load i32, i32* %7
%112 = and i32 %111, 65535
%113 = call i32 (i32*, i8*, ...) @fprintf(i32* %109, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %110, i32 %112)
store i32 0, i32* %11
br label %114
114: ; preds = %126, %108
%115 = load i32, i32* %11
%116 = load i32, i32* %10
%117 = icmp slt i32 %115, %116
br i1 %117, label %118, label %129
118: ; preds = %114
%119 = load i32*, i32** %9
%120 = load i32, i32* %11
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 %121
%123 = load i8, i8* %122
%124 = zext i8 %123 to i32
%125 = call i32 (i32*, i8*, ...) @fprintf(i32* %119, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 %124)
br label %126
126: ; preds = %118
%127 = load i32, i32* %11
%128 = add nsw i32 %127, 1
store i32 %128, i32* %11
br label %114
129: ; preds = %114
%130 = load i32, i32* %10
%131 = load i32, i32* %14
%132 = add i32 %131, %130
store i32 %132, i32* %14
%133 = load i32, i32* %7
%134 = lshr i32 %133, 8
%135 = and i32 %134, 255
%136 = load i32, i32* %7
%137 = lshr i32 %136, 0
%138 = and i32 %137, 255
%139 = add i32 %135, %138
%140 = load i32, i32* %14
%141 = add i32 %140, %139
store i32 %141, i32* %14
%142 = load i32*, i32** %9
%143 = load i32, i32* %14
%144 = sub i32 0, %143
%145 = and i32 %144, 255
%146 = call i32 (i32*, i8*, ...) @fprintf(i32* %142, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %145)
%147 = load i32, i32* %10
%148 = load i32, i32* %7
%149 = add i32 %148, %147
store i32 %149, i32* %7
%150 = load i32, i32* %12
%151 = load i32, i32* @EOF
%152 = icmp eq i32 %150, %151
br i1 %152, label %153, label %154
153: ; preds = %129
br label %155
154: ; preds = %129
br label %81
155: ; preds = %153, %107
%156 = load i32*, i32** %9
%157 = call i32 (i32*, i8*, ...) @fprintf(i32* %156, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
%158 = load i32*, i32** %8
%159 = call i32 @fclose(i32* %158)
%160 = load i32*, i32** %9
%161 = call i32 @fclose(i32* %160)
ret i32 0
}

LLVM IR (-O2):
@.str = [55 x i8] c"Usage: %s <load addr, hex> <input file> <output file>\0A\00"
@.str.1 = [24 x i8] c"illegal load address %s\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [26 x i8] c"cannot open input file %s\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [27 x i8] c"cannot open output file %s\00"
@.str.6 = [10 x i8] c":02000004\00"
@.str.7 = [5 x i8] c"%04X\00"
@.str.8 = [6 x i8] c"%02X\0A\00"
@EOF = global i32 0
@.str.9 = [12 x i8] c":%02X%04X00\00"
@.str.10 = [5 x i8] c"%02X\00"
@.str.11 = [13 x i8] c":00000001FF\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca [16 x i8]
%5 = bitcast i8** %3 to i8*
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 4
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strtoul(i8* %14, i8** %3, i32 16)
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = load i8*, i8** %13
%21 = tail call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %12
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %23
%29 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %22
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = tail call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %31
%37 = tail call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %30
%39 = tail call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i64 9, i64 1, i32* %33)
%40 = lshr i32 %15, 16
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %40)
%42 = lshr i32 %15, 24
%43 = add nuw nsw i32 %40, %42
%44 = sub nsw i32 250, %43
%45 = and i32 %44, 255
%46 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 1
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 2
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 3
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 4
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 5
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 6
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 7
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 8
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 9
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 10
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 11
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 12
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 13
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 14
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 15
br label %62
62: ; preds = %174, %38
%63 = phi i32 [ %15, %38 ], [ %182, %174 ]
%64 = tail call i32 @fgetc(i32* %25)
%65 = load i32, i32* @EOF
%66 = icmp eq i32 %64, %65
br i1 %66, label %185, label %67
67: ; preds = %62
%68 = trunc i32 %64 to i8
store i8 %68, i8* %6
%69 = tail call i32 @fgetc(i32* %25)
%70 = load i32, i32* @EOF
%71 = icmp eq i32 %69, %70
br i1 %71, label %159, label %72
72: ; preds = %67
%73 = trunc i32 %69 to i8
store i8 %73, i8* %47
%74 = add i32 %69, %64
%75 = tail call i32 @fgetc(i32* %25)
%76 = load i32, i32* @EOF
%77 = icmp eq i32 %75, %76
br i1 %77, label %159, label %78
78: ; preds = %72
%79 = trunc i32 %75 to i8
store i8 %79, i8* %48
%80 = add i32 %75, %74
%81 = tail call i32 @fgetc(i32* %25)
%82 = load i32, i32* @EOF
%83 = icmp eq i32 %81, %82
br i1 %83, label %159, label %84
84: ; preds = %78
%85 = trunc i32 %81 to i8
store i8 %85, i8* %49
%86 = add i32 %81, %80
%87 = tail call i32 @fgetc(i32* %25)
%88 = load i32, i32* @EOF
%89 = icmp eq i32 %87, %88
br i1 %89, label %159, label %90
90: ; preds = %84
%91 = trunc i32 %87 to i8
store i8 %91, i8* %50
%92 = add i32 %87, %86
%93 = tail call i32 @fgetc(i32* %25)
%94 = load i32, i32* @EOF
%95 = icmp eq i32 %93, %94
br i1 %95, label %159, label %96
96: ; preds = %90
%97 = trunc i32 %93 to i8
store i8 %97, i8* %51
%98 = add i32 %93, %92
%99 = tail call i32 @fgetc(i32* %25)
%100 = load i32, i32* @EOF
%101 = icmp eq i32 %99, %100
br i1 %101, label %159, label %102
102: ; preds = %96
%103 = trunc i32 %99 to i8
store i8 %103, i8* %52
%104 = add i32 %99, %98
%105 = tail call i32 @fgetc(i32* %25)
%106 = load i32, i32* @EOF
%107 = icmp eq i32 %105, %106
br i1 %107, label %159, label %108
108: ; preds = %102
%109 = trunc i32 %105 to i8
store i8 %109, i8* %53
%110 = add i32 %105, %104
%111 = tail call i32 @fgetc(i32* %25)
%112 = load i32, i32* @EOF
%113 = icmp eq i32 %111, %112
br i1 %113, label %159, label %114
114: ; preds = %108
%115 = trunc i32 %111 to i8
store i8 %115, i8* %54
%116 = add i32 %111, %110
%117 = tail call i32 @fgetc(i32* %25)
%118 = load i32, i32* @EOF
%119 = icmp eq i32 %117, %118
br i1 %119, label %159, label %120
120: ; preds = %114
%121 = trunc i32 %117 to i8
store i8 %121, i8* %55
%122 = add i32 %117, %116
%123 = tail call i32 @fgetc(i32* %25)
%124 = load i32, i32* @EOF
%125 = icmp eq i32 %123, %124
br i1 %125, label %159, label %126
126: ; preds = %120
%127 = trunc i32 %123 to i8
store i8 %127, i8* %56
%128 = add i32 %123, %122
%129 = tail call i32 @fgetc(i32* %25)
%130 = load i32, i32* @EOF
%131 = icmp eq i32 %129, %130
br i1 %131, label %159, label %132
132: ; preds = %126
%133 = trunc i32 %129 to i8
store i8 %133, i8* %57
%134 = add i32 %129, %128
%135 = tail call i32 @fgetc(i32* %25)
%136 = load i32, i32* @EOF
%137 = icmp eq i32 %135, %136
br i1 %137, label %159, label %138
138: ; preds = %132
%139 = trunc i32 %135 to i8
store i8 %139, i8* %58
%140 = add i32 %135, %134
%141 = tail call i32 @fgetc(i32* %25)
%142 = load i32, i32* @EOF
%143 = icmp eq i32 %141, %142
br i1 %143, label %159, label %144
144: ; preds = %138
%145 = trunc i32 %141 to i8
store i8 %145, i8* %59
%146 = add i32 %141, %140
%147 = tail call i32 @fgetc(i32* %25)
%148 = load i32, i32* @EOF
%149 = icmp eq i32 %147, %148
br i1 %149, label %159, label %150
150: ; preds = %144
%151 = trunc i32 %147 to i8
store i8 %151, i8* %60
%152 = add i32 %147, %146
%153 = tail call i32 @fgetc(i32* %25)
%154 = load i32, i32* @EOF
%155 = icmp eq i32 %153, %154
br i1 %155, label %159, label %156
156: ; preds = %150
%157 = trunc i32 %153 to i8
store i8 %157, i8* %61
%158 = add i32 %153, %152
br label %159
159: ; preds = %150, %144, %138, %132, %126, %120, %114, %108, %102, %96, %90, %84, %78, %72, %67, %156
%160 = phi i32 [ %153, %156 ], [ %153, %150 ], [ %147, %144 ], [ %141, %138 ], [ %135, %132 ], [ %129, %126 ], [ %123, %120 ], [ %117, %114 ], [ %111, %108 ], [ %105, %102 ], [ %99, %96 ], [ %93, %90 ], [ %87, %84 ], [ %81, %78 ], [ %75, %72 ], [ %69, %67 ]
%161 = phi i32 [ 16, %156 ], [ 15, %150 ], [ 14, %144 ], [ 13, %138 ], [ 12, %132 ], [ 11, %126 ], [ 10, %120 ], [ 9, %114 ], [ 8, %108 ], [ 7, %102 ], [ 6, %96 ], [ 5, %90 ], [ 4, %84 ], [ 3, %78 ], [ 2, %72 ], [ 1, %67 ]
%162 = phi i32 [ %158, %156 ], [ %152, %150 ], [ %146, %144 ], [ %140, %138 ], [ %134, %132 ], [ %128, %126 ], [ %122, %120 ], [ %116, %114 ], [ %110, %108 ], [ %104, %102 ], [ %98, %96 ], [ %92, %90 ], [ %86, %84 ], [ %80, %78 ], [ %74, %72 ], [ %64, %67 ]
%163 = and i32 %63, 65535
%164 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), i32 %161, i32 %163)
%165 = zext i32 %161 to i64
br label %166
166: ; preds = %159, %166
%167 = phi i64 [ 0, %159 ], [ %172, %166 ]
%168 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %167
%169 = load i8, i8* %168
%170 = zext i8 %169 to i32
%171 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 %170)
%172 = add nuw nsw i64 %167, 1
%173 = icmp eq i64 %172, %165
br i1 %173, label %174, label %166
174: ; preds = %166
%175 = add i32 %161, %162
%176 = lshr i32 %63, 8
%177 = add i32 %63, %176
%178 = add i32 %177, %175
%179 = sub i32 0, %178
%180 = and i32 %179, 255
%181 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %180)
%182 = add i32 %161, %63
%183 = load i32, i32* @EOF
%184 = icmp eq i32 %160, %183
br i1 %184, label %185, label %62
185: ; preds = %62, %174
%186 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i64 12, i64 1, i32* %33)
%187 = tail call i32 @fclose(i32* %25)
%188 = tail call i32 @fclose(i32* %33)
ret i32 0
}