#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int hex2hex(char *source, char *target, char *varline) {
  FILE *inf, *outf;
  int i, l, c;
  unsigned char buf[(256 * 1024)];
  if ((inf = fopen(source, "r")) == NULL) {
    perror(source);
    return 0;
  }
  if ((outf = fopen(target, "w")) == NULL) {
    perror(target);
    fclose(inf);
    return 0;
  }
  l = 0;
  while ((c = getc(inf)) != EOF) {
    if (c == ':') {
      int n, check;
      unsigned char sum;
      int addr;
      int linetype;
      if (fscanf(inf, "%02x", &n) != 1) {
        fprintf(stderr,
                "%s: "
                "File format error"
                "\n",
                source);
        fclose(inf);
        fclose(outf);
        return 0;
      };
      sum = n;
      if (fscanf(inf, "%04x", &addr) != 1) {
        fprintf(stderr,
                "%s: "
                "File format error"
                "\n",
                source);
        fclose(inf);
        fclose(outf);
        return 0;
      };
      sum += addr / 256;
      sum += addr % 256;
      if (fscanf(inf, "%02x", &linetype) != 1) {
        fprintf(stderr,
                "%s: "
                "File format error"
                "\n",
                source);
        fclose(inf);
        fclose(outf);
        return 0;
      };
      sum += linetype;
      if (linetype != 0)
        continue;
      for (i = 0; i < n; i++) {
        if (fscanf(inf, "%02x", &c) != 1) {
          fprintf(stderr,
                  "%s: "
                  "File format error"
                  "\n",
                  source);
          fclose(inf);
          fclose(outf);
          return 0;
        };
        if (addr >= (256 * 1024)) {
          fprintf(stderr,
                  "%s: "
                  "File too large"
                  "\n",
                  source);
          fclose(inf);
          fclose(outf);
          return 0;
        };
        buf[addr++] = c;
        if (addr > l)
          l = addr;
        sum += c;
      }
      if (fscanf(inf, "%02x", &check) != 1) {
        fprintf(stderr,
                "%s: "
                "File format error"
                "\n",
                source);
        fclose(inf);
        fclose(outf);
        return 0;
      };
      sum = ~sum + 1;
      if (check != sum) {
        fprintf(stderr,
                "%s: "
                "Line checksum error"
                "\n",
                source);
        fclose(inf);
        fclose(outf);
        return 0;
      };
    }
  }
  fprintf(outf, "/*\n *\t Computer generated file. Do not edit.\n */\n");
  fprintf(outf, "static unsigned char %s[] = {\n", varline);
  for (i = 0; i < l; i++) {
    if (i)
      fprintf(outf, ",");
    if (i && !(i % 16))
      fprintf(outf, "\n");
    fprintf(outf, "0x%02x", buf[i]);
  }
  fprintf(outf, "\n};\n\n");
  fclose(inf);
  fclose(outf);
  return 1;
}


x86 assembly (clang, -O0):
<hex2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11aa <hex2hex+0x4a>
mov    -0x10(%rbp),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
mov    -0x18(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11e6 <hex2hex+0x86>
mov    -0x18(%rbp),%rdi
call   1070 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
movl   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%eax
je     1563 <hex2hex+0x403>
cmpl   $0x3a,-0x3c(%rbp)
jne    155e <hex2hex+0x3fe>
mov    -0x28(%rbp),%rdi
lea    0xe85(%rip),%rsi
lea    -0x40044(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     126c <hex2hex+0x10c>
mov    0x2d9f(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
mov    -0x40044(%rbp),%eax
mov    %al,-0x40049(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd98(%rip),%rsi
lea    -0x40050(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     12d2 <hex2hex+0x172>
mov    0x2d39(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
mov    -0x40050(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
movzbl -0x40049(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x40049(%rbp)
mov    -0x40050(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
movzbl -0x40049(%rbp),%eax
add    %edx,%eax
mov    %al,-0x40049(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xd89(%rip),%rsi
lea    -0x40054(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     1368 <hex2hex+0x208>
mov    0x2ca3(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xcc1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
mov    -0x40054(%rbp),%ecx
movzbl -0x40049(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x40049(%rbp)
cmpl   $0x0,-0x40054(%rbp)
je     138f <hex2hex+0x22f>
jmp    11ed <hex2hex+0x8d>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x40044(%rbp),%eax
jge    149d <hex2hex+0x33d>
mov    -0x28(%rbp),%rdi
lea    0xcf2(%rip),%rsi
lea    -0x3c(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     13fc <hex2hex+0x29c>
mov    0x2c0f(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xc2d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
cmpl   $0x40000,-0x40050(%rbp)
jl     1446 <hex2hex+0x2e6>
mov    0x2bc5(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xbff(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
mov    -0x3c(%rbp),%eax
mov    %al,%cl
mov    -0x40050(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x40050(%rbp)
cltq
mov    %cl,-0x40040(%rbp,%rax,1)
mov    -0x40050(%rbp),%eax
cmp    -0x38(%rbp),%eax
jle    147d <hex2hex+0x31d>
mov    -0x40050(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x3c(%rbp),%ecx
movzbl -0x40049(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x40049(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1396 <hex2hex+0x236>
mov    -0x28(%rbp),%rdi
lea    0xbfa(%rip),%rsi
lea    -0x40048(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     14f7 <hex2hex+0x397>
mov    0x2b14(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xb32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
movzbl -0x40049(%rbp),%eax
xor    $0xffffffff,%eax
add    $0x1,%eax
mov    %al,-0x40049(%rbp)
mov    -0x40048(%rbp),%eax
movzbl -0x40049(%rbp),%ecx
cmp    %ecx,%eax
je     1559 <hex2hex+0x3f9>
mov    0x2ab2(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xb00(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1641 <hex2hex+0x4e1>
jmp    155e <hex2hex+0x3fe>
jmp    11ed <hex2hex+0x8d>
mov    -0x30(%rbp),%rdi
lea    0xadf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xafb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1616 <hex2hex+0x4b6>
cmpl   $0x0,-0x34(%rbp)
je     15ba <hex2hex+0x45a>
mov    -0x30(%rbp),%rdi
lea    0xaeb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x34(%rbp)
je     15ea <hex2hex+0x48a>
mov    -0x34(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    15ea <hex2hex+0x48a>
mov    -0x30(%rbp),%rdi
lea    0xac8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
movzbl -0x40040(%rbp,%rax,1),%edx
ff
lea    0xa9f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1592 <hex2hex+0x432>
mov    -0x30(%rbp),%rdi
lea    0xa86(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40028,%rsp
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0xe5f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1410 <hex2hex+0x290>
mov    %rax,%r14
lea    0xe49(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     141c <hex2hex+0x29c>
mov    %rax,%r12
mov    %rbx,0x18(%rsp)
mov    %r14,%rdi
call   10a0 <getc@plt>
mov    %eax,0x4(%rsp)
mov    0x2e03(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%eax
jne    1274 <hex2hex+0xf4>
lea    0xe57(%rip),%rdi
mov    $0x31,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1090 <fwrite@plt>
lea    0xe70(%rip),%rsi
mov    %r12,%rdi
mov    0x18(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %ebx,%ebx
jle    1241 <hex2hex+0xc1>
movzbl 0x20(%rsp),%edx
lea    0xe70(%rip),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
cmp    $0x1,%ebx
jne    13bf <hex2hex+0x23f>
lea    0xe5d(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1090 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebp
jmp    1460 <hex2hex+0x2e0>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
cmp    $0x3a,%eax
jne    12ec <hex2hex+0x16c>
mov    %r14,%rdi
lea    0xe11(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1433 <hex2hex+0x2b3>
mov    0xc(%rsp),%r13d
mov    %r14,%rdi
lea    0xd6a(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1433 <hex2hex+0x2b3>
mov    0x8(%rsp),%ebp
mov    %r14,%rdi
lea    0xdce(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1433 <hex2hex+0x2b3>
cmpl   $0x0,0x10(%rsp)
je     130c <hex2hex+0x18c>
mov    %r14,%rdi
call   10a0 <getc@plt>
mov    %eax,0x4(%rsp)
mov    0x2ce9(%rip),%rcx
cmp    (%rcx),%eax
jne    1280 <hex2hex+0x100>
jmp    11ef <hex2hex+0x6f>
lea    0xff(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
sar    $0x8,%eax
add    %ebp,%r13d
add    %eax,%r13d
cmpl   $0x0,0xc(%rsp)
jle    1386 <hex2hex+0x206>
mov    %r15,%rbp
xor    %r15d,%r15d
nopl   (%rax)
mov    %r14,%rdi
lea    0xd66(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1430 <hex2hex+0x2b0>
movslq 0x8(%rsp),%rax
cmp    $0x3ffff,%rax
jg     1474 <hex2hex+0x2f4>
mov    0x4(%rsp),%ecx
lea    0x1(%rax),%edx
mov    %edx,0x8(%rsp)
mov    %cl,0x20(%rsp,%rax,1)
cmp    %ebx,%eax
cmovge %edx,%ebx
movzbl %r13b,%r13d
add    %ecx,%r13d
add    $0x1,%r15d
cmp    0xc(%rsp),%r15d
jl     1330 <hex2hex+0x1b0>
jmp    1389 <hex2hex+0x209>
mov    %r15,%rbp
mov    %r14,%rdi
lea    0xd0d(%rip),%rsi
lea    0x14(%rsp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1430 <hex2hex+0x2b0>
neg    %r13d
movzbl %r13b,%eax
cmp    %eax,0x14(%rsp)
jne    1480 <hex2hex+0x300>
mov    %rbp,%r15
jmp    12ec <hex2hex+0x16c>
mov    %ebx,%ebp
mov    $0x1,%ebx
lea    0xcd1(%rip),%r15
jmp    13ef <hex2hex+0x26f>
nop
movzbl 0x20(%rsp,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1241 <hex2hex+0xc1>
mov    $0x2c,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
test   $0xf,%bl
jne    13d0 <hex2hex+0x250>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
jmp    13d0 <hex2hex+0x250>
mov    %r15,%rdi
call   1080 <perror@plt>
xor    %ebp,%ebp
jmp    1460 <hex2hex+0x2e0>
mov    %rbp,%rdi
call   1080 <perror@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
jmp    1460 <hex2hex+0x2e0>
mov    %rbp,%r15
lea    0xbca(%rip),%rsi
mov    0x2b97(%rip),%rax
movslq (%rax),%rdi
xor    %ebp,%ebp
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x40028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xba5(%rip),%rsi
mov    %rbp,%r15
jmp    143a <hex2hex+0x2ba>
lea    0xbad(%rip),%rsi
jmp    147b <hex2hex+0x2fb>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.2 = [5 x i8] c"%02x\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"%s: File format error\0A\00"
@.str.4 = [5 x i8] c"%04x\00"
@.str.5 = [20 x i8] c"%s: File too large\0A\00"
@.str.6 = [25 x i8] c"%s: Line checksum error\0A\00"
@.str.7 = [50 x i8] c"/*\0A *\09 Computer generated file. Do not edit.\0A */\0A\00"
@.str.8 = [31 x i8] c"static unsigned char %s[] = {\0A\00"
@.str.9 = [2 x i8] c",\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [7 x i8] c"0x%02x\00"
@.str.12 = [6 x i8] c"\0A};\0A\0A\00"
define i32 @hex2hex(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [262144 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = load i8*, i8** %5
%24 = call i32 @perror(i8* %23)
store i32 0, i32* %4
br label %241
25: ; preds = %3
%26 = load i8*, i8** %6
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %9
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = call i32 @perror(i8* %30)
%32 = load i32*, i32** %8
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %4
br label %241
34: ; preds = %25
store i32 0, i32* %11
br label %35
35: ; preds = %196, %107, %34
%36 = load i32*, i32** %8
%37 = call i32 @getc(i32* %36)
store i32 %37, i32* %12
%38 = load i32, i32* @EOF
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %197
40: ; preds = %35
%41 = load i32, i32* %12
%42 = icmp eq i32 %41, 58
br i1 %42, label %43, label %196
43: ; preds = %40
%44 = load i32*, i32** %8
%45 = call i32 @fscanf(i32* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %14)
%46 = icmp ne i32 %45, 1
br i1 %46, label %47, label %57
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i32*
%51 = load i8*, i8** %5
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %8
%54 = call i32 @fclose(i32* %53)
%55 = load i32*, i32** %9
%56 = call i32 @fclose(i32* %55)
store i32 0, i32* %4
br label %241
57: ; preds = %43
%58 = load i32, i32* %14
%59 = trunc i32 %58 to i8
store i8 %59, i8* %16
%60 = load i32*, i32** %8
%61 = call i32 @fscanf(i32* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %17)
%62 = icmp ne i32 %61, 1
br i1 %62, label %63, label %73
63: ; preds = %57
%64 = load i32, i32* @stderr
%65 = sext i32 %64 to i64
%66 = inttoptr i64 %65 to i32*
%67 = load i8*, i8** %5
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %67)
%69 = load i32*, i32** %8
%70 = call i32 @fclose(i32* %69)
%71 = load i32*, i32** %9
%72 = call i32 @fclose(i32* %71)
store i32 0, i32* %4
br label %241
73: ; preds = %57
%74 = load i32, i32* %17
%75 = sdiv i32 %74, 256
%76 = load i8, i8* %16
%77 = zext i8 %76 to i32
%78 = add nsw i32 %77, %75
%79 = trunc i32 %78 to i8
store i8 %79, i8* %16
%80 = load i32, i32* %17
%81 = srem i32 %80, 256
%82 = load i8, i8* %16
%83 = zext i8 %82 to i32
%84 = add nsw i32 %83, %81
%85 = trunc i32 %84 to i8
store i8 %85, i8* %16
%86 = load i32*, i32** %8
%87 = call i32 @fscanf(i32* %86, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %18)
%88 = icmp ne i32 %87, 1
br i1 %88, label %89, label %99
89: ; preds = %73
%90 = load i32, i32* @stderr
%91 = sext i32 %90 to i64
%92 = inttoptr i64 %91 to i32*
%93 = load i8*, i8** %5
%94 = call i32 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %93)
%95 = load i32*, i32** %8
%96 = call i32 @fclose(i32* %95)
%97 = load i32*, i32** %9
%98 = call i32 @fclose(i32* %97)
store i32 0, i32* %4
br label %241
99: ; preds = %73
%100 = load i32, i32* %18
%101 = load i8, i8* %16
%102 = zext i8 %101 to i32
%103 = add nsw i32 %102, %100
%104 = trunc i32 %103 to i8
store i8 %104, i8* %16
%105 = load i32, i32* %18
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %99
br label %35
108: ; preds = %99
store i32 0, i32* %10
br label %109
109: ; preds = %158, %108
%110 = load i32, i32* %10
%111 = load i32, i32* %14
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %161
113: ; preds = %109
%114 = load i32*, i32** %8
%115 = call i32 @fscanf(i32* %114, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%116 = icmp ne i32 %115, 1
br i1 %116, label %117, label %127
117: ; preds = %113
%118 = load i32, i32* @stderr
%119 = sext i32 %118 to i64
%120 = inttoptr i64 %119 to i32*
%121 = load i8*, i8** %5
%122 = call i32 (i32*, i8*, ...) @fprintf(i32* %120, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %121)
%123 = load i32*, i32** %8
%124 = call i32 @fclose(i32* %123)
%125 = load i32*, i32** %9
%126 = call i32 @fclose(i32* %125)
store i32 0, i32* %4
br label %241
127: ; preds = %113
%128 = load i32, i32* %17
%129 = icmp sge i32 %128, 262144
br i1 %129, label %130, label %140
130: ; preds = %127
%131 = load i32, i32* @stderr
%132 = sext i32 %131 to i64
%133 = inttoptr i64 %132 to i32*
%134 = load i8*, i8** %5
%135 = call i32 (i32*, i8*, ...) @fprintf(i32* %133, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %134)
%136 = load i32*, i32** %8
%137 = call i32 @fclose(i32* %136)
%138 = load i32*, i32** %9
%139 = call i32 @fclose(i32* %138)
store i32 0, i32* %4
br label %241
140: ; preds = %127
%141 = load i32, i32* %12
%142 = trunc i32 %141 to i8
%143 = load i32, i32* %17
%144 = add nsw i32 %143, 1
store i32 %144, i32* %17
%145 = sext i32 %143 to i64
%146 = getelementptr inbounds [262144 x i8], [262144 x i8]* %13, i64 0, i64 %145
store i8 %142, i8* %146
%147 = load i32, i32* %17
%148 = load i32, i32* %11
%149 = icmp sgt i32 %147, %148
br i1 %149, label %150, label %152
150: ; preds = %140
%151 = load i32, i32* %17
store i32 %151, i32* %11
br label %152
152: ; preds = %150, %140
%153 = load i32, i32* %12
%154 = load i8, i8* %16
%155 = zext i8 %154 to i32
%156 = add nsw i32 %155, %153
%157 = trunc i32 %156 to i8
store i8 %157, i8* %16
br label %158
158: ; preds = %152
%159 = load i32, i32* %10
%160 = add nsw i32 %159, 1
store i32 %160, i32* %10
br label %109
161: ; preds = %109
%162 = load i32*, i32** %8
%163 = call i32 @fscanf(i32* %162, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%164 = icmp ne i32 %163, 1
br i1 %164, label %165, label %175
165: ; preds = %161
%166 = load i32, i32* @stderr
%167 = sext i32 %166 to i64
%168 = inttoptr i64 %167 to i32*
%169 = load i8*, i8** %5
%170 = call i32 (i32*, i8*, ...) @fprintf(i32* %168, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %169)
%171 = load i32*, i32** %8
%172 = call i32 @fclose(i32* %171)
%173 = load i32*, i32** %9
%174 = call i32 @fclose(i32* %173)
store i32 0, i32* %4
br label %241
175: ; preds = %161
%176 = load i8, i8* %16
%177 = zext i8 %176 to i32
%178 = xor i32 %177, -1
%179 = add nsw i32 %178, 1
%180 = trunc i32 %179 to i8
store i8 %180, i8* %16
%181 = load i32, i32* %15
%182 = load i8, i8* %16
%183 = zext i8 %182 to i32
%184 = icmp ne i32 %181, %183
br i1 %184, label %185, label %195
185: ; preds = %175
%186 = load i32, i32* @stderr
%187 = sext i32 %186 to i64
%188 = inttoptr i64 %187 to i32*
%189 = load i8*, i8** %5
%190 = call i32 (i32*, i8*, ...) @fprintf(i32* %188, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %189)
%191 = load i32*, i32** %8
%192 = call i32 @fclose(i32* %191)
%193 = load i32*, i32** %9
%194 = call i32 @fclose(i32* %193)
store i32 0, i32* %4
br label %241
195: ; preds = %175
br label %196
196: ; preds = %195, %40
br label %35
197: ; preds = %35
%198 = load i32*, i32** %9
%199 = call i32 (i32*, i8*, ...) @fprintf(i32* %198, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0))
%200 = load i32*, i32** %9
%201 = load i8*, i8** %7
%202 = call i32 (i32*, i8*, ...) @fprintf(i32* %200, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %201)
store i32 0, i32* %10
br label %203
203: ; preds = %231, %197
%204 = load i32, i32* %10
%205 = load i32, i32* %11
%206 = icmp slt i32 %204, %205
br i1 %206, label %207, label %234
207: ; preds = %203
%208 = load i32, i32* %10
%209 = icmp ne i32 %208, 0
br i1 %209, label %210, label %213
210: ; preds = %207
%211 = load i32*, i32** %9
%212 = call i32 (i32*, i8*, ...) @fprintf(i32* %211, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %213
213: ; preds = %210, %207
%214 = load i32, i32* %10
%215 = icmp ne i32 %214, 0
br i1 %215, label %216, label %223
216: ; preds = %213
%217 = load i32, i32* %10
%218 = srem i32 %217, 16
%219 = icmp ne i32 %218, 0
br i1 %219, label %223, label %220
220: ; preds = %216
%221 = load i32*, i32** %9
%222 = call i32 (i32*, i8*, ...) @fprintf(i32* %221, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %223
223: ; preds = %220, %216, %213
%224 = load i32*, i32** %9
%225 = load i32, i32* %10
%226 = sext i32 %225 to i64
%227 = getelementptr inbounds [262144 x i8], [262144 x i8]* %13, i64 0, i64 %226
%228 = load i8, i8* %227
%229 = zext i8 %228 to i32
%230 = call i32 (i32*, i8*, ...) @fprintf(i32* %224, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %229)
br label %231
231: ; preds = %223
%232 = load i32, i32* %10
%233 = add nsw i32 %232, 1
store i32 %233, i32* %10
br label %203
234: ; preds = %203
%235 = load i32*, i32** %9
%236 = call i32 (i32*, i8*, ...) @fprintf(i32* %235, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
%237 = load i32*, i32** %8
%238 = call i32 @fclose(i32* %237)
%239 = load i32*, i32** %9
%240 = call i32 @fclose(i32* %239)
store i32 1, i32* %4
br label %241
241: ; preds = %234, %185, %165, %130, %117, %89, %63, %47, %29, %22
%242 = load i32, i32* %4
ret i32 %242
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.2 = [5 x i8] c"%02x\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"%s: File format error\0A\00"
@.str.4 = [5 x i8] c"%04x\00"
@.str.5 = [20 x i8] c"%s: File too large\0A\00"
@.str.6 = [25 x i8] c"%s: Line checksum error\0A\00"
@.str.7 = [50 x i8] c"/*\0A *\09 Computer generated file. Do not edit.\0A */\0A\00"
@.str.8 = [31 x i8] c"static unsigned char %s[] = {\0A\00"
@.str.11 = [7 x i8] c"0x%02x\00"
@.str.12 = [6 x i8] c"\0A};\0A\0A\00"
define i32 @hex2hex(i8* %0, i8* nocapture %1, i8* %2) {
%4 = alloca i32
%5 = alloca [262144 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = bitcast i32* %4 to i8*
%11 = getelementptr inbounds [262144 x i8], [262144 x i8]* %5, i64 0, i64 0
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = tail call i32 @perror(i8* %0)
br label %136
16: ; preds = %3
%17 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = call i32 @getc(i32* %12)
store i32 %20, i32* %4
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %107, label %23
23: ; preds = %19
%24 = bitcast i32* %6 to i8*
%25 = bitcast i32* %7 to i8*
%26 = bitcast i32* %8 to i8*
%27 = bitcast i32* %9 to i8*
br label %104
28: ; preds = %16
%29 = tail call i32 @perror(i8* %1)
%30 = tail call i32 @fclose(i32* %12)
br label %136
31: ; preds = %104, %95
%32 = phi i32 [ %105, %104 ], [ %96, %95 ]
%33 = icmp eq i32 %32, 58
br i1 %33, label %34, label %99
34: ; preds = %31
%35 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %87
37: ; preds = %34
%38 = load i32, i32* %6
%39 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %8)
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %87
41: ; preds = %37
%42 = load i32, i32* %8
%43 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %87
45: ; preds = %41
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %95
48: ; preds = %45
%49 = sdiv i32 %42, 256
%50 = add i32 %42, %38
%51 = add i32 %50, %49
%52 = load i32, i32* %6
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %76
54: ; preds = %48, %63
%55 = phi i32 [ %72, %63 ], [ %51, %48 ]
%56 = phi i32 [ %70, %63 ], [ %106, %48 ]
%57 = phi i32 [ %73, %63 ], [ 0, %48 ]
%58 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %87
60: ; preds = %54
%61 = load i32, i32* %8
%62 = icmp sgt i32 %61, 262143
br i1 %62, label %87, label %63
63: ; preds = %60
%64 = load i32, i32* %4
%65 = trunc i32 %64 to i8
%66 = add nsw i32 %61, 1
store i32 %66, i32* %8
%67 = sext i32 %61 to i64
%68 = getelementptr inbounds [262144 x i8], [262144 x i8]* %5, i64 0, i64 %67
store i8 %65, i8* %68
%69 = icmp slt i32 %61, %56
%70 = select i1 %69, i32 %56, i32 %66
%71 = and i32 %55, 255
%72 = add nsw i32 %64, %71
%73 = add nuw nsw i32 %57, 1
%74 = load i32, i32* %6
%75 = icmp slt i32 %73, %74
br i1 %75, label %54, label %76
76: ; preds = %63, %48
%77 = phi i32 [ %106, %48 ], [ %70, %63 ]
%78 = phi i32 [ %51, %48 ], [ %72, %63 ]
%79 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%80 = icmp eq i32 %79, 1
br i1 %80, label %81, label %87
81: ; preds = %76
%82 = sub i32 0, %78
%83 = load i32, i32* %7
%84 = and i32 %82, 255
%85 = icmp eq i32 %83, %84
br i1 %85, label %86, label %87
86: ; preds = %81
br label %99
87: ; preds = %81, %76, %41, %37, %34, %60, %54
%88 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %54 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), %60 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %34 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %37 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %41 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %76 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), %81 ]
%89 = load i32, i32* @stderr
%90 = sext i32 %89 to i64
%91 = inttoptr i64 %90 to i32*
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %91, i8* %88, i8* %0)
%93 = call i32 @fclose(i32* %12)
%94 = call i32 @fclose(i32* %17)
br label %136
95: ; preds = %45
%96 = call i32 @getc(i32* %12)
store i32 %96, i32* %4
%97 = load i32, i32* @EOF
%98 = icmp eq i32 %96, %97
br i1 %98, label %107, label %31
99: ; preds = %31, %86
%100 = phi i32 [ %77, %86 ], [ %106, %31 ]
%101 = call i32 @getc(i32* %12)
store i32 %101, i32* %4
%102 = load i32, i32* @EOF
%103 = icmp eq i32 %101, %102
br i1 %103, label %107, label %104
104: ; preds = %23, %99
%105 = phi i32 [ %20, %23 ], [ %101, %99 ]
%106 = phi i32 [ 0, %23 ], [ %100, %99 ]
br label %31
107: ; preds = %99, %95, %19
%108 = phi i32 [ 0, %19 ], [ %106, %95 ], [ %100, %99 ]
%109 = call i64 @fwrite(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i64 49, i64 1, i32* %17)
%110 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %2)
%111 = icmp sgt i32 %108, 0
br i1 %111, label %112, label %132
112: ; preds = %107
%113 = zext i32 %108 to i64
%114 = load i8, i8* %11
%115 = zext i8 %114 to i32
%116 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %115)
%117 = icmp eq i32 %108, 1
br i1 %117, label %132, label %118
118: ; preds = %112, %125
%119 = phi i64 [ %130, %125 ], [ 1, %112 ]
%120 = call i32 @fputc(i32 44, i32* %17)
%121 = and i64 %119, 15
%122 = icmp eq i64 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %118
%124 = call i32 @fputc(i32 10, i32* %17)
br label %125
125: ; preds = %123, %118
%126 = getelementptr inbounds [262144 x i8], [262144 x i8]* %5, i64 0, i64 %119
%127 = load i8, i8* %126
%128 = zext i8 %127 to i32
%129 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %128)
%130 = add nuw nsw i64 %119, 1
%131 = icmp eq i64 %130, %113
br i1 %131, label %132, label %118
132: ; preds = %125, %112, %107
%133 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i64 5, i64 1, i32* %17)
%134 = call i32 @fclose(i32* %12)
%135 = call i32 @fclose(i32* %17)
br label %136
136: ; preds = %87, %132, %28, %14
%137 = phi i32 [ 0, %14 ], [ 0, %28 ], [ 1, %132 ], [ 0, %87 ]
ret i32 %137
}