#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
unsigned long fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  FILE *file;
  unsigned char *buf;
  unsigned long size, mem_size = 1024 * 4, i, j, k, sum;
  char filename[80];
  if (argc < 2) {
    printf("usage: bintohex infile\n");
    return -1;
  }
  file = fopen(argv[1], "rb");
  if (file == NULL) {
    printf("Can't open %s\n", argv[1]);
    return -1;
  }
  buf = (unsigned char *)malloc((1024 * 1024));
  memset(buf, 0, (1024 * 1024));
  size = fread(buf, 1, (1024 * 1024), file);
  mem_size = size;
  if (size > mem_size) {
    printf("FILE TOO LARGE!!!!!!!!!!!\n");
    return -1;
  }
  fclose(file);
  strcpy(filename, "codeX.hex");
  for (i = 0; i < 4; ++i) {
    filename[4] = '0' + i;
    file = fopen(filename, "wb");
    for (j = 0; i + j * 4 * 16 < mem_size; ++j) {
      k = j * 16;
      fprintf(file, ":10%4.4x00", (int)k);
      sum = 0x10 + (k >> 8) + (k & 0xff);
      for (k = 0; k < 16; ++k) {
        fprintf(file, "%2.2x", buf[i + j * 4 * 16 + k * 4]);
        sum += buf[i + j * 4 * 16 + k * 4];
      }
      sum &= 0xff;
      sum = 0x100 - sum;
      sum &= 0xff;
      fprintf(file, "%2.2x\n", (int)sum);
    }
    fprintf(file, ":00000001ff\n");
    fclose(file);
  }
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1000,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d5 <main+0x45>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1456 <main+0x2c6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe34(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121a <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1456 <main+0x2c6>
mov    $0x100000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x100000,%edx
call   1080 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100000,%edx
call   1050 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    1283 <main+0xf3>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1456 <main+0x2c6>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0xa0(%rbp),%rdi
lea    0xdab(%rip),%rsi
call   1040 <strcpy@plt>
movq   $0x0,-0x38(%rbp)
cmpq   $0x4,-0x38(%rbp)
jae    1446 <main+0x2b6>
mov    -0x38(%rbp),%rax
add    $0x30,%rax
mov    %al,-0x9c(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xd81(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
shl    $0x2,%rcx
shl    $0x4,%rcx
add    %rcx,%rax
cmp    -0x30(%rbp),%rax
jae    141a <main+0x28a>
mov    -0x40(%rbp),%rax
shl    $0x4,%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%edx
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x48(%rbp),%rax
shr    $0x8,%rax
add    $0x10,%rax
mov    -0x48(%rbp),%rcx
and    $0xff,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
cmpq   $0x10,-0x48(%rbp)
jae    13c8 <main+0x238>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rdx
shl    $0x2,%rdx
shl    $0x4,%rdx
add    %rdx,%rcx
mov    -0x48(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xcdb(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rdx
shl    $0x2,%rdx
shl    $0x4,%rdx
add    %rdx,%rcx
mov    -0x48(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rcx
movzbl (%rax,%rcx,1),%eax
add    -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1346 <main+0x1b6>
mov    -0x50(%rbp),%rax
and    $0xff,%rax
mov    %rax,-0x50(%rbp)
mov    $0x100,%eax
sub    -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
and    $0xff,%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%edx
lea    0xc61(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12df <main+0x14f>
mov    -0x18(%rbp),%rdi
lea    0xc45(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12a7 <main+0x117>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
cmp    $0x1,%edi
jg     11d4 <main+0x24>
lea    0xe7a(%rip),%rdi
call   1050 <puts@plt>
jmp    1508 <main+0x358>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe1e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     14f6 <main+0x346>
mov    %rax,%rbp
mov    $0x100000,%edi
call   10b0 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x100000,%edx
call   1090 <memset@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %rbp,%rcx
call   1060 <fread@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1070 <fclose@plt>
lea    0xddc(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1040 <strcpy@plt>
mov    %r13,0x8(%rsp)
add    $0x3c,%r13
lea    0xdcf(%rip),%rbp
xor    %r14d,%r14d
mov    %rbx,0x10(%rsp)
jmp    1297 <main+0xe7>
nopw   0x0(%rax,%rax,1)
mov    $0xc,%esi
mov    $0x1,%edx
lea    0xdc6(%rip),%rdi
mov    %r15,%rcx
call   10d0 <fwrite@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    (%rsp),%r14
add    $0x1,%r14
add    $0x1,%r13
cmp    $0x4,%r14
je     14e8 <main+0x338>
lea    0x30(%r14),%eax
mov    %al,0x24(%rsp)
lea    0x20(%rsp),%rdi
lea    0xd71(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    %r14,(%rsp)
cmp    %rbx,%r14
lea    0xd69(%rip),%r14
jae    1260 <main+0xb0>
mov    (%rsp),%rax
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %rax,0x18(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r12,%rbx
shr    $0x8,%rbx
mov    %r12d,%eax
and    $0xf0,%eax
add    %eax,%ebx
movzbl -0x3c(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x3c(%r13,%r12,4),%ebp
add    %ebx,%ebp
movzbl -0x38(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x38(%r13,%r12,4),%ebx
add    %ebp,%ebx
movzbl -0x34(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x34(%r13,%r12,4),%ebp
add    %ebx,%ebp
movzbl -0x30(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x30(%r13,%r12,4),%ebx
add    %ebp,%ebx
movzbl -0x2c(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x2c(%r13,%r12,4),%ebp
add    %ebx,%ebp
movzbl -0x28(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x28(%r13,%r12,4),%ebx
add    %ebp,%ebx
movzbl -0x24(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x24(%r13,%r12,4),%ebp
add    %ebx,%ebp
movzbl -0x20(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x20(%r13,%r12,4),%ebx
add    %ebp,%ebx
movzbl -0x1c(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x1c(%r13,%r12,4),%ebp
add    %ebx,%ebp
movzbl -0x18(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x18(%r13,%r12,4),%ebx
add    %ebp,%ebx
movzbl -0x14(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x14(%r13,%r12,4),%ebp
add    %ebx,%ebp
movzbl -0x10(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x10(%r13,%r12,4),%ebx
add    %ebp,%ebx
movzbl -0xc(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0xc(%r13,%r12,4),%ebp
add    %ebx,%ebp
movzbl -0x8(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x8(%r13,%r12,4),%ebx
add    %ebp,%ebx
movzbl -0x4(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl -0x4(%r13,%r12,4),%ebp
add    %ebx,%ebp
mov    0x10(%rsp),%rbx
movzbl 0x0(%r13,%r12,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
movzbl 0x0(%r13,%r12,4),%eax
add    %ebp,%eax
lea    0xb6d(%rip),%rbp
mov    $0xf0,%ecx
sub    %eax,%ecx
movzbl %cl,%edx
mov    %r15,%rdi
lea    0xb6a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    0x18(%rsp),%rax
add    $0x10,%r12
add    $0x40,%rax
cmp    %rbx,%rax
jb     12d0 <main+0x120>
jmp    1260 <main+0xb0>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    150d <main+0x35d>
mov    0x8(%rbx),%rsi
lea    0xb02(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xffffffff,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"usage: bintohex infile\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@.str.3 = [27 x i8] c"FILE TOO LARGE!!!!!!!!!!!\0A\00"
@.str.4 = [10 x i8] c"codeX.hex\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [11 x i8] c":10%4.4x00\00"
@.str.7 = [6 x i8] c"%2.2x\00"
@.str.8 = [7 x i8] c"%2.2x\0A\00"
@.str.9 = [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 i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 4096, i64* %9
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %141
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 -1, i32* %3
br label %141
31: ; preds = %19
%32 = call i64 @malloc(i32 1048576)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = call i32 @memset(i8* %34, i32 0, i32 1048576)
%36 = load i8*, i8** %7
%37 = load i32*, i32** %6
%38 = call i64 @fread(i8* %36, i32 1, i32 1048576, i32* %37)
store i64 %38, i64* %8
%39 = load i64, i64* %8
store i64 %39, i64* %9
%40 = load i64, i64* %8
%41 = load i64, i64* %9
%42 = icmp ugt i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %31
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %141
45: ; preds = %31
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%49 = call i32 @strcpy(i8* %48, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i64 0, i64* %10
br label %50
50: ; preds = %135, %45
%51 = load i64, i64* %10
%52 = icmp ult i64 %51, 4
br i1 %52, label %53, label %138
53: ; preds = %50
%54 = load i64, i64* %10
%55 = add i64 48, %54
%56 = trunc i64 %55 to i8
%57 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 4
store i8 %56, i8* %57
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %59, i32** %6
store i64 0, i64* %11
br label %60
60: ; preds = %127, %53
%61 = load i64, i64* %10
%62 = load i64, i64* %11
%63 = mul i64 %62, 4
%64 = mul i64 %63, 16
%65 = add i64 %61, %64
%66 = load i64, i64* %9
%67 = icmp ult i64 %65, %66
br i1 %67, label %68, label %130
68: ; preds = %60
%69 = load i64, i64* %11
%70 = mul i64 %69, 16
store i64 %70, i64* %12
%71 = load i32*, i32** %6
%72 = load i64, i64* %12
%73 = trunc i64 %72 to i32
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %73)
%75 = load i64, i64* %12
%76 = lshr i64 %75, 8
%77 = add i64 16, %76
%78 = load i64, i64* %12
%79 = and i64 %78, 255
%80 = add i64 %77, %79
store i64 %80, i64* %13
store i64 0, i64* %12
br label %81
81: ; preds = %113, %68
%82 = load i64, i64* %12
%83 = icmp ult i64 %82, 16
br i1 %83, label %84, label %116
84: ; preds = %81
%85 = load i32*, i32** %6
%86 = load i8*, i8** %7
%87 = load i64, i64* %10
%88 = load i64, i64* %11
%89 = mul i64 %88, 4
%90 = mul i64 %89, 16
%91 = add i64 %87, %90
%92 = load i64, i64* %12
%93 = mul i64 %92, 4
%94 = add i64 %91, %93
%95 = getelementptr inbounds i8, i8* %86, i64 %94
%96 = load i8, i8* %95
%97 = zext i8 %96 to i32
%98 = call i32 (i32*, i8*, ...) @fprintf(i32* %85, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %97)
%99 = load i8*, i8** %7
%100 = load i64, i64* %10
%101 = load i64, i64* %11
%102 = mul i64 %101, 4
%103 = mul i64 %102, 16
%104 = add i64 %100, %103
%105 = load i64, i64* %12
%106 = mul i64 %105, 4
%107 = add i64 %104, %106
%108 = getelementptr inbounds i8, i8* %99, i64 %107
%109 = load i8, i8* %108
%110 = zext i8 %109 to i64
%111 = load i64, i64* %13
%112 = add i64 %111, %110
store i64 %112, i64* %13
br label %113
113: ; preds = %84
%114 = load i64, i64* %12
%115 = add i64 %114, 1
store i64 %115, i64* %12
br label %81
116: ; preds = %81
%117 = load i64, i64* %13
%118 = and i64 %117, 255
store i64 %118, i64* %13
%119 = load i64, i64* %13
%120 = sub i64 256, %119
store i64 %120, i64* %13
%121 = load i64, i64* %13
%122 = and i64 %121, 255
store i64 %122, i64* %13
%123 = load i32*, i32** %6
%124 = load i64, i64* %13
%125 = trunc i64 %124 to i32
%126 = call i32 (i32*, i8*, ...) @fprintf(i32* %123, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %125)
br label %127
127: ; preds = %116
%128 = load i64, i64* %11
%129 = add i64 %128, 1
store i64 %129, i64* %11
br label %60
130: ; preds = %60
%131 = load i32*, i32** %6
%132 = call i32 (i32*, i8*, ...) @fprintf(i32* %131, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%133 = load i32*, i32** %6
%134 = call i32 @fclose(i32* %133)
br label %135
135: ; preds = %130
%136 = load i64, i64* %10
%137 = add i64 %136, 1
store i64 %137, i64* %10
br label %50
138: ; preds = %50
%139 = load i8*, i8** %7
%140 = call i32 @free(i8* %139)
store i32 0, i32* %3
br label %141
141: ; preds = %138, %43, %26, %17
%142 = load i32, i32* %3
ret i32 %142
}

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