#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 uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ parse_hex_line(char *, int *, int *, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void ihex_load_file(char *filename, uint8_t *memory, uint32_t *start,
                    uint32_t *end) {
  char line[1000];
  FILE *fin;
  uint32_t addr;
  int status, bytes[256];
  uint32_t n;
  uint32_t i, total = 0, lineno = 1;
  uint32_t minaddr = 0x1FFFF, maxaddr = 0;
  uint32_t offset = 0;
  if (strlen(filename) == 0) {
    printf("   Can't load a file without the filename.");
    printf("  '?' for help\n");
    return;
  }
  fin = fopen(filename, "r");
  if (fin == NULL) {
    printf("   Can't open file '%s' for reading.\n", filename);
    return;
  }
  while (!feof(fin) && !ferror(fin)) {
    line[0] = '\0';
    fgets(line, 1000, fin);
    if (line[strlen(line) - 1] == '\n')
      line[strlen(line) - 1] = '\0';
    if (line[strlen(line) - 1] == '\r')
      line[strlen(line) - 1] = '\0';
    if (parse_hex_line(line, bytes, &addr, &n, &status)) {
      if (status == 0) {
        for (i = 0; i <= (n - 1); i++) {
          memory[addr + offset] = bytes[i] & 255;
          total++;
          if ((addr + offset) < minaddr)
            minaddr = addr + offset;
          if ((addr + offset) > maxaddr)
            maxaddr = addr + offset;
          addr++;
        }
      }
      if (status == 1) {
        fclose(fin);
        printf("   Loaded %d bytes between:", total);
        printf(" %06X to %06X\n", minaddr, maxaddr);
        *start = minaddr;
        *end = maxaddr;
        return;
      }
      if (status == 2) {
        uint32_t segment;
        segment = (bytes[0] << 8) | bytes[1];
        offset = segment << 4;
        printf("Segment = 0x%04x, addr = 0x%08x\n", segment, offset);
      }
      if (status == 4) {
        offset = ((bytes[0] << 8) | bytes[1]) * 256 * 256;
        printf("Linear Address = 0x%04x\n", offset);
      }
    } else {
      printf("   Error: '%s', line: %d\n", filename, lineno);
    }
    lineno++;
  }
}


x86 assembly (clang, -O0):
<ihex_load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x82c(%rbp)
movl   $0x1,-0x830(%rbp)
movl   $0x1ffff,-0x834(%rbp)
movl   $0x0,-0x838(%rbp)
movl   $0x0,-0x83c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
jne    1200 <ihex_load_file+0x80>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1553 <ihex_load_file+0x3d3>
mov    -0x8(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    123c <ihex_load_file+0xbc>
mov    -0x8(%rbp),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1553 <ihex_load_file+0x3d3>
jmp    1241 <ihex_load_file+0xc1>
mov    -0x418(%rbp),%rdi
call   1090 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x841(%rbp)
jne    127a <ihex_load_file+0xfa>
mov    -0x418(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x841(%rbp)
mov    -0x841(%rbp),%al
test   $0x1,%al
jne    128d <ihex_load_file+0x10d>
jmp    1553 <ihex_load_file+0x3d3>
movb   $0x0,-0x410(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x3e8,%esi
call   1080 <fgets@plt>
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12e7 <ihex_load_file+0x167>
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
jne    1322 <ihex_load_file+0x1a2>
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
lea    -0x820(%rbp),%rsi
lea    -0x41c(%rbp),%rdx
lea    -0x824(%rbp),%rcx
lea    -0x420(%rbp),%r8
call   1040 <parse_hex_line@plt>
cmp    $0x0,%rax
je     1527 <ihex_load_file+0x3a7>
cmpl   $0x0,-0x420(%rbp)
jne    1437 <ihex_load_file+0x2b7>
movl   $0x0,-0x828(%rbp)
mov    -0x828(%rbp),%eax
mov    -0x824(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1432 <ihex_load_file+0x2b2>
movslq -0x828(%rbp),%rax
mov    -0x820(%rbp,%rax,4),%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    -0x41c(%rbp),%ecx
add    -0x83c(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x82c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x82c(%rbp)
mov    -0x41c(%rbp),%eax
add    -0x83c(%rbp),%eax
cmp    -0x834(%rbp),%eax
jge    13e5 <ihex_load_file+0x265>
mov    -0x41c(%rbp),%eax
add    -0x83c(%rbp),%eax
mov    %eax,-0x834(%rbp)
mov    -0x41c(%rbp),%eax
add    -0x83c(%rbp),%eax
cmp    -0x838(%rbp),%eax
jle    140f <ihex_load_file+0x28f>
mov    -0x41c(%rbp),%eax
add    -0x83c(%rbp),%eax
mov    %eax,-0x838(%rbp)
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
mov    -0x828(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x828(%rbp)
jmp    136b <ihex_load_file+0x1eb>
jmp    1437 <ihex_load_file+0x2b7>
cmpl   $0x1,-0x420(%rbp)
jne    149b <ihex_load_file+0x31b>
mov    -0x418(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x82c(%rbp),%esi
lea    0xc06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x834(%rbp),%esi
mov    -0x838(%rbp),%edx
lea    0xc08(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x834(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x838(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1553 <ihex_load_file+0x3d3>
cmpl   $0x2,-0x420(%rbp)
jne    14e6 <ihex_load_file+0x366>
mov    -0x820(%rbp),%eax
shl    $0x8,%eax
or     -0x81c(%rbp),%eax
mov    %eax,-0x840(%rbp)
mov    -0x840(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x83c(%rbp)
mov    -0x840(%rbp),%esi
mov    -0x83c(%rbp),%edx
lea    0xbaf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x4,-0x420(%rbp)
jne    1522 <ihex_load_file+0x3a2>
mov    -0x820(%rbp),%eax
shl    $0x8,%eax
or     -0x81c(%rbp),%eax
shl    $0x8,%eax
shl    $0x8,%eax
mov    %eax,-0x83c(%rbp)
mov    -0x83c(%rbp),%esi
lea    0xb94(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    153f <ihex_load_file+0x3bf>
mov    -0x8(%rbp),%rsi
mov    -0x830(%rbp),%edx
lea    0xb90(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x830(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x830(%rbp)
jmp    1241 <ihex_load_file+0xc1>
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ihex_load_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x848,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r15
call   1070 <strlen@plt>
test   %eax,%eax
je     11fa <ihex_load_file+0x6a>
lea    0xe6e(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1225 <ihex_load_file+0x95>
mov    %rax,%rbp
mov    %r12,0x50(%rsp)
mov    %r14,0x58(%rsp)
mov    %rbx,0x20(%rsp)
mov    %rax,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     1247 <ihex_load_file+0xb7>
add    $0x848,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xec3(%rip),%rdi
add    $0x848,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
lea    0xe01(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
add    $0x848,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <printf@plt>
mov    0x20(%rsp),%rax
add    $0x4,%rax
mov    %rax,0x28(%rsp)
mov    $0x1,%r14d
mov    $0x1ffff,%r13d
lea    0x460(%rsp),%rbx
movl   $0x0,0xc(%rsp)
xor    %r12d,%r12d
movl   $0x0,0x10(%rsp)
mov    %r15,0x38(%rsp)
mov    %rbp,0x30(%rsp)
jmp    12b8 <ihex_load_file+0x128>
nopl   0x0(%rax,%rax,1)
lea    0xe21(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%r14d
mov    %rbp,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    11e8 <ihex_load_file+0x58>
mov    %rbp,%rdi
call   1040 <ferror@plt>
test   %eax,%eax
jne    11e8 <ihex_load_file+0x58>
movb   $0x0,0x460(%rsp)
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1300 <ihex_load_file+0x170>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0xd,-0x1(%rax,%rbx,1)
jne    1320 <ihex_load_file+0x190>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
lea    0x60(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x14(%rsp),%r8
call   1050 <parse_hex_line@plt>
test   %rax,%rax
je     1290 <ihex_load_file+0x100>
mov    0x14(%rsp),%r11d
test   %r11d,%r11d
je     1380 <ihex_load_file+0x1f0>
cmp    $0x2,%r11d
je     149c <ihex_load_file+0x30c>
cmp    $0x1,%r11d
je     14f4 <ihex_load_file+0x364>
cmp    $0x4,%r11d
jne    12a4 <ihex_load_file+0x114>
jmp    14cd <ihex_load_file+0x33d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x1c(%rsp),%r9d
test   %r9d,%r9d
jle    12a4 <ihex_load_file+0x114>
movslq 0x18(%rsp),%rdx
movslq 0xc(%rsp),%rax
cmp    $0x1,%r9d
jne    13af <ihex_load_file+0x21f>
xor    %edi,%edi
test   $0x1,%r9b
jne    1461 <ihex_load_file+0x2d1>
jmp    1489 <ihex_load_file+0x2f9>
mov    %r9d,%r10d
and    $0xfffffffe,%r10d
lea    (%rax,%rdx,1),%rsi
mov    %rdx,0x48(%rsp)
mov    %rax,0x40(%rsp)
add    %eax,%edx
mov    0x28(%rsp),%rax
lea    (%rax,%rsi,4),%rbx
xor    %edi,%edi
jmp    13e9 <ihex_load_file+0x259>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x2,%rdi
cmp    %rdi,%r10
je     143c <ihex_load_file+0x2ac>
movzbl 0x60(%rsp,%rdi,4),%eax
lea    (%rsi,%rdi,1),%rbp
mov    %eax,-0x4(%rbx,%rdi,4)
movslq %r13d,%rax
lea    (%rdx,%rdi,1),%ecx
cmp    %rax,%rbp
cmovl  %ecx,%eax
movslq %r12d,%r15
cmp    %r15,%rbp
cmovg  %ecx,%r15d
movzbl 0x64(%rsp,%rdi,4),%ecx
lea    0x1(%rsi,%rdi,1),%r8
mov    %ecx,(%rbx,%rdi,4)
movslq %eax,%rcx
lea    (%rdx,%rdi,1),%r12d
add    $0x1,%r12d
mov    %r12d,%r13d
cmp    %rcx,%r8
jl     142f <ihex_load_file+0x29f>
mov    %eax,%r13d
movslq %r15d,%rax
cmp    %rax,%r8
jg     13e0 <ihex_load_file+0x250>
mov    %r15d,%r12d
jmp    13e0 <ihex_load_file+0x250>
mov    0x48(%rsp),%rdx
add    %rdi,%rdx
mov    0x38(%rsp),%r15
mov    0x30(%rsp),%rbp
lea    0x460(%rsp),%rbx
mov    0x40(%rsp),%rax
test   $0x1,%r9b
je     1489 <ihex_load_file+0x2f9>
movzbl 0x60(%rsp,%rdi,4),%esi
add    %rdx,%rax
mov    0x20(%rsp),%rcx
mov    %esi,(%rcx,%rax,4)
movslq %r13d,%r13
cmp    %r13,%rax
cmovl  %eax,%r13d
movslq %r12d,%r12
cmp    %r12,%rax
cmovg  %eax,%r12d
add    $0x1,%rdx
add    %r9d,0x10(%rsp)
mov    %edx,0x18(%rsp)
cmp    $0x2,%r11d
jne    1359 <ihex_load_file+0x1c9>
mov    0x60(%rsp),%esi
shl    $0x8,%esi
or     0x64(%rsp),%esi
mov    %esi,%edx
shl    $0x4,%edx
lea    0xbcb(%rip),%rdi
mov    %edx,0xc(%rsp)
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x14(%rsp),%r11d
cmp    $0x4,%r11d
jne    12a4 <ihex_load_file+0x114>
mov    0x60(%rsp),%eax
mov    0x64(%rsp),%esi
shl    $0x18,%eax
shl    $0x10,%esi
or     %eax,%esi
lea    0xbbb(%rip),%rdi
mov    %esi,0xc(%rsp)
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12a4 <ihex_load_file+0x114>
mov    %rbp,%rdi
call   1060 <fclose@plt>
lea    0xb50(%rip),%rdi
mov    0x10(%rsp),%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xb5a(%rip),%rdi
mov    %r13d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x50(%rsp),%rax
mov    %r13d,(%rax)
mov    0x58(%rsp),%rax
mov    %r12d,(%rax)
jmp    11e8 <ihex_load_file+0x58>

LLVM IR (-O0):
@.str = [43 x i8] c" Can't load a file without the filename.\00"
@.str.1 = [16 x i8] c" '?' for help\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [38 x i8] c" Can't open file '%s' for reading.\0A\00"
@.str.4 = [28 x i8] c" Loaded %d bytes between:\00"
@.str.5 = [15 x i8] c" %06X to %06X\0A\00"
@.str.6 = [33 x i8] c"Segment = 0x%04x, addr = 0x%08x\0A\00"
@.str.7 = [25 x i8] c"Linear Address = 0x%04x\0A\00"
@.str.8 = [26 x i8] c" Error: '%s', line: %d\0A\00"
define void @ihex_load_file(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [1000 x i8]
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca [256 x i32]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %16
store i32 1, i32* %17
store i32 131071, i32* %18
store i32 0, i32* %19
store i32 0, i32* %20
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %188
28: ; preds = %4
%29 = load i8*, i8** %5
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %10
%31 = load i32*, i32** %10
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %188
36: ; preds = %28
br label %37
37: ; preds = %185, %36
%38 = load i32*, i32** %10
%39 = call i32 @feof(i32* %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %46, label %41
41: ; preds = %37
%42 = load i32*, i32** %10
%43 = call i32 @ferror(i32* %42)
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
br label %46
46: ; preds = %41, %37
%47 = phi i1 [ false, %37 ], [ %45, %41 ]
br i1 %47, label %48, label %188
48: ; preds = %46
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
store i8 0, i8* %49
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%51 = load i32*, i32** %10
%52 = call i32 @fgets(i8* %50, i32 1000, i32* %51)
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%54 = call i32 @strlen(i8* %53)
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 10
br i1 %60, label %61, label %67
61: ; preds = %48
%62 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %61, %48
%68 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = sub nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 13
br i1 %75, label %76, label %82
76: ; preds = %67
%77 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%78 = call i32 @strlen(i8* %77)
%79 = sub nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 %80
store i8 0, i8* %81
br label %82
82: ; preds = %76, %67
%83 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%84 = getelementptr inbounds [256 x i32], [256 x i32]* %13, i64 0, i64 0
%85 = call i64 @parse_hex_line(i8* %83, i32* %84, i32* %11, i32* %14, i32* %12)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %181
87: ; preds = %82
%88 = load i32, i32* %12
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %136
90: ; preds = %87
store i32 0, i32* %15
br label %91
91: ; preds = %132, %90
%92 = load i32, i32* %15
%93 = load i32, i32* %14
%94 = sub nsw i32 %93, 1
%95 = icmp sle i32 %92, %94
br i1 %95, label %96, label %135
96: ; preds = %91
%97 = load i32, i32* %15
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [256 x i32], [256 x i32]* %13, i64 0, i64 %98
%100 = load i32, i32* %99
%101 = and i32 %100, 255
%102 = load i32*, i32** %6
%103 = load i32, i32* %11
%104 = load i32, i32* %20
%105 = add nsw i32 %103, %104
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i32, i32* %102, i64 %106
store i32 %101, i32* %107
%108 = load i32, i32* %16
%109 = add nsw i32 %108, 1
store i32 %109, i32* %16
%110 = load i32, i32* %11
%111 = load i32, i32* %20
%112 = add nsw i32 %110, %111
%113 = load i32, i32* %18
%114 = icmp slt i32 %112, %113
br i1 %114, label %115, label %119
115: ; preds = %96
%116 = load i32, i32* %11
%117 = load i32, i32* %20
%118 = add nsw i32 %116, %117
store i32 %118, i32* %18
br label %119
119: ; preds = %115, %96
%120 = load i32, i32* %11
%121 = load i32, i32* %20
%122 = add nsw i32 %120, %121
%123 = load i32, i32* %19
%124 = icmp sgt i32 %122, %123
br i1 %124, label %125, label %129
125: ; preds = %119
%126 = load i32, i32* %11
%127 = load i32, i32* %20
%128 = add nsw i32 %126, %127
store i32 %128, i32* %19
br label %129
129: ; preds = %125, %119
%130 = load i32, i32* %11
%131 = add nsw i32 %130, 1
store i32 %131, i32* %11
br label %132
132: ; preds = %129
%133 = load i32, i32* %15
%134 = add nsw i32 %133, 1
store i32 %134, i32* %15
br label %91
135: ; preds = %91
br label %136
136: ; preds = %135, %87
%137 = load i32, i32* %12
%138 = icmp eq i32 %137, 1
br i1 %138, label %139, label %151
139: ; preds = %136
%140 = load i32*, i32** %10
%141 = call i32 @fclose(i32* %140)
%142 = load i32, i32* %16
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %142)
%144 = load i32, i32* %18
%145 = load i32, i32* %19
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %144, i32 %145)
%147 = load i32, i32* %18
%148 = load i32*, i32** %7
store i32 %147, i32* %148
%149 = load i32, i32* %19
%150 = load i32*, i32** %8
store i32 %149, i32* %150
br label %188
151: ; preds = %136
%152 = load i32, i32* %12
%153 = icmp eq i32 %152, 2
br i1 %153, label %154, label %166
154: ; preds = %151
%155 = getelementptr inbounds [256 x i32], [256 x i32]* %13, i64 0, i64 0
%156 = load i32, i32* %155
%157 = shl i32 %156, 8
%158 = getelementptr inbounds [256 x i32], [256 x i32]* %13, i64 0, i64 1
%159 = load i32, i32* %158
%160 = or i32 %157, %159
store i32 %160, i32* %21
%161 = load i32, i32* %21
%162 = shl i32 %161, 4
store i32 %162, i32* %20
%163 = load i32, i32* %21
%164 = load i32, i32* %20
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %163, i32 %164)
br label %166
166: ; preds = %154, %151
%167 = load i32, i32* %12
%168 = icmp eq i32 %167, 4
br i1 %168, label %169, label %180
169: ; preds = %166
%170 = getelementptr inbounds [256 x i32], [256 x i32]* %13, i64 0, i64 0
%171 = load i32, i32* %170
%172 = shl i32 %171, 8
%173 = getelementptr inbounds [256 x i32], [256 x i32]* %13, i64 0, i64 1
%174 = load i32, i32* %173
%175 = or i32 %172, %174
%176 = mul nsw i32 %175, 256
%177 = mul nsw i32 %176, 256
store i32 %177, i32* %20
%178 = load i32, i32* %20
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %178)
br label %180
180: ; preds = %169, %166
br label %185
181: ; preds = %82
%182 = load i8*, i8** %5
%183 = load i32, i32* %17
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %182, i32 %183)
br label %185
185: ; preds = %181, %180
%186 = load i32, i32* %17
%187 = add nsw i32 %186, 1
store i32 %187, i32* %17
br label %37
188: ; preds = %25, %33, %139, %46
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c" Can't load a file without the filename.\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [38 x i8] c" Can't open file '%s' for reading.\0A\00"
@.str.4 = [28 x i8] c" Loaded %d bytes between:\00"
@.str.5 = [15 x i8] c" %06X to %06X\0A\00"
@.str.6 = [33 x i8] c"Segment = 0x%04x, addr = 0x%08x\0A\00"
@.str.7 = [25 x i8] c"Linear Address = 0x%04x\0A\00"
@.str.8 = [26 x i8] c" Error: '%s', line: %d\0A\00"
@str = [15 x i8] c" '?' for help\00"
define void @ihex_load_file(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [1000 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca [256 x i32]
%9 = alloca i32
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = bitcast [256 x i32]* %8 to i8*
%14 = bitcast i32* %9 to i8*
%15 = tail call i32 @strlen(i8* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %184
20: ; preds = %4
%21 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = call i32 @feof(i32* %21)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %184
26: ; preds = %23
%27 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 0
%28 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 1
br label %31
29: ; preds = %20
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %184
31: ; preds = %26, %176
%32 = phi i32 [ 0, %26 ], [ %180, %176 ]
%33 = phi i32 [ 0, %26 ], [ %179, %176 ]
%34 = phi i32 [ 131071, %26 ], [ %178, %176 ]
%35 = phi i32 [ 1, %26 ], [ %181, %176 ]
%36 = phi i32 [ 0, %26 ], [ %177, %176 ]
%37 = call i32 @ferror(i32* %21)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %184
39: ; preds = %31
store i8 0, i8* %10
%40 = call i32 @fgets(i8* %10, i32 1000, i32* %21)
%41 = call i32 @strlen(i8* %10)
%42 = add nsw i32 %41, -1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 10
br i1 %46, label %47, label %52
47: ; preds = %39
%48 = call i32 @strlen(i8* %10)
%49 = add nsw i32 %48, -1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %47, %39
%53 = call i32 @strlen(i8* %10)
%54 = add nsw i32 %53, -1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 13
br i1 %58, label %59, label %64
59: ; preds = %52
%60 = call i32 @strlen(i8* %10)
%61 = add nsw i32 %60, -1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %62
store i8 0, i8* %63
br label %64
64: ; preds = %59, %52
%65 = call i64 @parse_hex_line(i8* %10, i32* %27, i32* %6, i32* %9, i32* %7)
%66 = icmp eq i64 %65, 0
br i1 %66, label %174, label %67
67: ; preds = %64
%68 = load i32, i32* %7
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %147
70: ; preds = %67
%71 = load i32, i32* %9
%72 = icmp sgt i32 %71, 0
br i1 %72, label %73, label %176
73: ; preds = %70
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = sext i32 %32 to i64
%77 = zext i32 %71 to i64
%78 = and i64 %77, 1
%79 = icmp eq i32 %71, 1
br i1 %79, label %118, label %80
80: ; preds = %73
%81 = and i64 %77, 4294967294
br label %82
82: ; preds = %82, %80
%83 = phi i64 [ %75, %80 ], [ %114, %82 ]
%84 = phi i64 [ 0, %80 ], [ %115, %82 ]
%85 = phi i32 [ %33, %80 ], [ %113, %82 ]
%86 = phi i32 [ %34, %80 ], [ %110, %82 ]
%87 = phi i64 [ 0, %80 ], [ %116, %82 ]
%88 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 %84
%89 = load i32, i32* %88
%90 = and i32 %89, 255
%91 = add nsw i64 %83, %76
%92 = getelementptr inbounds i32, i32* %1, i64 %91
store i32 %90, i32* %92
%93 = sext i32 %86 to i64
%94 = icmp slt i64 %91, %93
%95 = trunc i64 %91 to i32
%96 = select i1 %94, i32 %95, i32 %86
%97 = sext i32 %85 to i64
%98 = icmp sgt i64 %91, %97
%99 = select i1 %98, i32 %95, i32 %85
%100 = add nsw i64 %83, 1
%101 = or i64 %84, 1
%102 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 %101
%103 = load i32, i32* %102
%104 = and i32 %103, 255
%105 = add nsw i64 %100, %76
%106 = getelementptr inbounds i32, i32* %1, i64 %105
store i32 %104, i32* %106
%107 = sext i32 %96 to i64
%108 = icmp slt i64 %105, %107
%109 = trunc i64 %105 to i32
%110 = select i1 %108, i32 %109, i32 %96
%111 = sext i32 %99 to i64
%112 = icmp sgt i64 %105, %111
%113 = select i1 %112, i32 %109, i32 %99
%114 = add nsw i64 %83, 2
%115 = add nuw nsw i64 %84, 2
%116 = add i64 %87, 2
%117 = icmp eq i64 %116, %81
br i1 %117, label %118, label %82
118: ; preds = %82, %73
%119 = phi i32 [ undef, %73 ], [ %110, %82 ]
%120 = phi i32 [ undef, %73 ], [ %113, %82 ]
%121 = phi i64 [ undef, %73 ], [ %114, %82 ]
%122 = phi i64 [ %75, %73 ], [ %114, %82 ]
%123 = phi i64 [ 0, %73 ], [ %115, %82 ]
%124 = phi i32 [ %33, %73 ], [ %113, %82 ]
%125 = phi i32 [ %34, %73 ], [ %110, %82 ]
%126 = icmp eq i64 %78, 0
br i1 %126, label %141, label %127
127: ; preds = %118
%128 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 %123
%129 = load i32, i32* %128
%130 = and i32 %129, 255
%131 = add nsw i64 %122, %76
%132 = getelementptr inbounds i32, i32* %1, i64 %131
store i32 %130, i32* %132
%133 = sext i32 %125 to i64
%134 = icmp slt i64 %131, %133
%135 = trunc i64 %131 to i32
%136 = select i1 %134, i32 %135, i32 %125
%137 = sext i32 %124 to i64
%138 = icmp sgt i64 %131, %137
%139 = select i1 %138, i32 %135, i32 %124
%140 = add nsw i64 %122, 1
br label %141
141: ; preds = %118, %127
%142 = phi i32 [ %119, %118 ], [ %136, %127 ]
%143 = phi i32 [ %120, %118 ], [ %139, %127 ]
%144 = phi i64 [ %121, %118 ], [ %140, %127 ]
%145 = add i32 %36, %71
%146 = trunc i64 %144 to i32
store i32 %146, i32* %6
br label %147
147: ; preds = %141, %67
%148 = phi i32 [ %36, %67 ], [ %145, %141 ]
%149 = phi i32 [ %34, %67 ], [ %142, %141 ]
%150 = phi i32 [ %33, %67 ], [ %143, %141 ]
switch i32 %68, label %163 [
i32 1, label %151
i32 2, label %155
]
151: ; preds = %147
%152 = call i32 @fclose(i32* %21)
%153 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %148)
%154 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %149, i32 %150)
store i32 %149, i32* %2
store i32 %150, i32* %3
br label %184
155: ; preds = %147
%156 = load i32, i32* %27
%157 = shl i32 %156, 8
%158 = load i32, i32* %28
%159 = or i32 %157, %158
%160 = shl i32 %159, 4
%161 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %159, i32 %160)
%162 = load i32, i32* %7
br label %163
163: ; preds = %147, %155
%164 = phi i32 [ %162, %155 ], [ %68, %147 ]
%165 = phi i32 [ %160, %155 ], [ %32, %147 ]
%166 = icmp eq i32 %164, 4
br i1 %166, label %167, label %176
167: ; preds = %163
%168 = load i32, i32* %27
%169 = load i32, i32* %28
%170 = shl i32 %168, 24
%171 = shl i32 %169, 16
%172 = or i32 %171, %170
%173 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %172)
br label %176
174: ; preds = %64
%175 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %0, i32 %35)
br label %176
176: ; preds = %70, %163, %167, %174
%177 = phi i32 [ %148, %167 ], [ %148, %163 ], [ %36, %174 ], [ %36, %70 ]
%178 = phi i32 [ %149, %167 ], [ %149, %163 ], [ %34, %174 ], [ %34, %70 ]
%179 = phi i32 [ %150, %167 ], [ %150, %163 ], [ %33, %174 ], [ %33, %70 ]
%180 = phi i32 [ %172, %167 ], [ %165, %163 ], [ %32, %174 ], [ %32, %70 ]
%181 = add nuw nsw i32 %35, 1
%182 = call i32 @feof(i32* %21)
%183 = icmp eq i32 %182, 0
br i1 %183, label %31, label %184
184: ; preds = %176, %31, %23, %151, %29, %17
ret void
}