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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read_hexuint8_t(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int read_hex_file(FILE *fp, uint8_t *buffer, uint32_t offset, uint32_t size) {
  uint16_t bytes_read;
  char buf[8];
  uint8_t chk;
  uint16_t d, last_erased = 0xFFFF;
  uint8_t data[64], i, b, r;
  uint32_t addr;
  uint32_t high = 0;
  uint8_t *paddr;
  paddr = (uint8_t *)&addr;
  while (1) {
    do {
      bytes_read = fread(buf, 1, 1, fp);
    } while (bytes_read && (buf[0] != ':'));
    if (!bytes_read) {
      printf("No record.\n");
      return 0;
    }
    i = 0;
    chk = 0;
    do {
      d = read_hexuint8_t(fp);
      chk += d;
      data[i++] = d;
    } while (i < (data[0] + 5));
    if (chk) {
      printf("Checksum error. Got %02X, expected 00.", chk);
      printf("... File position: %ld.\n", ftell(fp));
    }
    switch (data[3]) {
    case 0x01:
      return high;
    case 0x02:
      fprintf(stderr, "Unsupported segmented address.\n");
      return 0;
    case 0x04:
      if (data[0] == 2) {
        paddr[3] = data[4];
        paddr[2] = data[5];
      } else {
        fprintf(stderr, "Extended address with wrong length.\n");
        return 0;
      }
      break;
    case 0x00:
      paddr[0] = data[2];
      paddr[1] = data[1];
      if (addr < offset) {
        fprintf(stderr, "Address too small (0x%X is below offset..)\n", addr);
        return 0;
      }
      if (addr - offset >= size) {
        fprintf(stderr, "Address too big (0x%X is > (size+offset)..)\n", addr);
        return 0;
      }
      for (i = 0; i < data[0]; i++) {
        b = data[4 + i];
        buffer[addr - offset] = b;
        if ((addr - offset) > high)
          high = addr - offset;
        addr++;
      }
      break;
    default:
      fprintf(stderr, "Unsupported record type %2x.\n", data[3]);
      return 0;
    }
  }
  return high;
}


x86 assembly (clang, -O0):
<read_hex_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0xffff,-0x38(%rbp)
movl   $0x0,-0x154(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x160(%rbp)
jmp    118d <read_hex_file+0x3d>
lea    -0x2c(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x161(%rbp)
je     11c6 <read_hex_file+0x76>
movsbl -0x2c(%rbp),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x161(%rbp)
mov    -0x161(%rbp),%al
test   $0x1,%al
jne    118d <read_hex_file+0x3d>
cmpl   $0x0,-0x24(%rbp)
jne    11f8 <read_hex_file+0xa8>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1498 <read_hex_file+0x348>
movl   $0x0,-0x144(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <read_hexuint8_t@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x144(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x144(%rbp)
cltq
mov    %ecx,-0x140(%rbp,%rax,4)
mov    -0x144(%rbp),%eax
mov    -0x140(%rbp),%ecx
add    $0x5,%ecx
cmp    %ecx,%eax
jl     1209 <read_hex_file+0xb9>
cmpl   $0x0,-0x30(%rbp)
je     1286 <read_hex_file+0x136>
mov    -0x30(%rbp),%esi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x134(%rbp),%eax
mov    %rax,-0x170(%rbp)
sub    $0x4,%rax
ja     146a <read_hex_file+0x31a>
mov    -0x170(%rbp),%rax
lea    0xd55(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x154(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1498 <read_hex_file+0x348>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1498 <read_hex_file+0x348>
cmpl   $0x2,-0x140(%rbp)
jne    1317 <read_hex_file+0x1c7>
mov    -0x130(%rbp),%ecx
mov    -0x160(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x12c(%rbp),%ecx
mov    -0x160(%rbp),%rax
mov    %ecx,0x8(%rax)
jmp    133a <read_hex_file+0x1ea>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1498 <read_hex_file+0x348>
jmp    1493 <read_hex_file+0x343>
mov    -0x138(%rbp),%ecx
mov    -0x160(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x13c(%rbp),%ecx
mov    -0x160(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x150(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1396 <read_hex_file+0x246>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
mov    -0x150(%rbp),%edx
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1498 <read_hex_file+0x348>
mov    -0x150(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     13d1 <read_hex_file+0x281>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
mov    -0x150(%rbp),%edx
lea    0xd13(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1498 <read_hex_file+0x348>
movl   $0x0,-0x144(%rbp)
mov    -0x144(%rbp),%eax
cmp    -0x140(%rbp),%eax
jge    1465 <read_hex_file+0x315>
mov    -0x144(%rbp),%eax
add    $0x4,%eax
cltq
mov    -0x140(%rbp,%rax,4),%eax
mov    %eax,-0x148(%rbp)
mov    -0x148(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0x150(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x150(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    -0x154(%rbp),%eax
jle    1442 <read_hex_file+0x2f2>
mov    -0x150(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x154(%rbp)
mov    -0x150(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x150(%rbp)
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    13db <read_hex_file+0x28b>
jmp    1493 <read_hex_file+0x343>
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
mov    -0x134(%rbp),%edx
lea    0xc7e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1498 <read_hex_file+0x348>
jmp    1188 <read_hex_file+0x38>
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hex_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %ecx,0x8(%rsp)
mov    %rdi,%r12
mov    %edx,0xc(%rsp)
movslq %edx,%rcx
mov    %rcx,%rax
neg    %rax
mov    %rax,0x10(%rsp)
lea    0x0(,%rcx,4),%rax
sub    %rax,%rsi
mov    %rsi,0x20(%rsp)
neg    %ecx
mov    %rcx,0x18(%rsp)
lea    0x28(%rsp),%r13
xor    %r14d,%r14d
jmp    11d0 <read_hex_file+0x60>
cmp    $0x2,%ebx
jne    139a <read_hex_file+0x22a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     11f0 <read_hex_file+0x80>
cmpb   $0x3a,0x28(%rsp)
jne    11d0 <read_hex_file+0x60>
test   %eax,%eax
je     1389 <read_hex_file+0x219>
xor    %ebx,%ebx
mov    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1080 <read_hexuint8_t@plt>
add    %eax,%ebx
mov    %eax,0x34(%rsp,%rbp,4)
movslq 0x30(%rsp),%r15
lea    0x4(%r15),%rax
add    $0x1,%rbp
cmp    %rax,%rbp
jl     1210 <read_hex_file+0xa0>
test   %ebx,%ebx
je     125c <read_hex_file+0xec>
lea    0xdd9(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1070 <ftell@plt>
lea    0xde8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x3c(%rsp),%edx
cmp    $0x4,%rdx
ja     13c8 <read_hex_file+0x258>
mov    %r15d,%ebx
lea    0xd8c(%rip),%rcx
movslq (%rcx,%rdx,4),%rax
add    %rcx,%rax
jmp    *%rax
movslq 0x38(%rsp),%r15
mov    0xc(%rsp),%ecx
cmp    %ecx,%r15d
jl     13dd <read_hex_file+0x26d>
mov    %r15d,%eax
sub    %ecx,%eax
cmp    0x8(%rsp),%eax
jge    13ef <read_hex_file+0x27f>
test   %ebx,%ebx
jle    11d0 <read_hex_file+0x60>
mov    0x20(%rsp),%rax
lea    (%rax,%r15,4),%rdi
lea    0x0(,%rbx,4),%rdx
lea    0x40(%rsp),%rsi
call   1090 <memcpy@plt>
lea    -0x1(%rbx),%rcx
mov    %ebx,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jb     1356 <read_hex_file+0x1e6>
and    $0xfffffffc,%ebx
mov    0x18(%rsp),%rcx
add    %r15d,%ecx
mov    0x10(%rsp),%rdx
add    %r15,%rdx
xor    %esi,%esi
jmp    12f9 <read_hex_file+0x189>
nopl   0x0(%rax,%rax,1)
add    $0x4,%rsi
cmp    %rsi,%rbx
je     1353 <read_hex_file+0x1e3>
lea    (%rdx,%rsi,1),%rdi
movslq %r14d,%rbp
cmp    %rbp,%rdi
jle    1309 <read_hex_file+0x199>
lea    (%rcx,%rsi,1),%r14d
lea    (%rdx,%rsi,1),%rdi
add    $0x1,%rdi
movslq %r14d,%rbp
cmp    %rbp,%rdi
jle    1321 <read_hex_file+0x1b1>
lea    (%rcx,%rsi,1),%r14d
add    $0x1,%r14d
lea    (%rdx,%rsi,1),%rdi
add    $0x2,%rdi
movslq %r14d,%rbp
cmp    %rbp,%rdi
jle    1339 <read_hex_file+0x1c9>
lea    (%rcx,%rsi,1),%r14d
add    $0x2,%r14d
lea    (%rdx,%rsi,1),%rdi
add    $0x3,%rdi
movslq %r14d,%rbp
cmp    %rbp,%rdi
jle    12f0 <read_hex_file+0x180>
lea    (%rcx,%rsi,1),%r14d
add    $0x3,%r14d
jmp    12f0 <read_hex_file+0x180>
add    %rsi,%r15
test   %rax,%rax
je     11d0 <read_hex_file+0x60>
add    0x10(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %r14d,%r14
cmp    %r14,%r15
cmovg  %r15d,%r14d
add    $0x1,%r15
add    $0xffffffffffffffff,%rax
jne    1370 <read_hex_file+0x200>
jmp    11d0 <read_hex_file+0x60>
lea    0xd80(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
jmp    140c <read_hex_file+0x29c>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
jmp    13bc <read_hex_file+0x24c>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xc98(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    140c <read_hex_file+0x29c>
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
lea    0xd1a(%rip),%rsi
xor    %r14d,%r14d
jmp    1405 <read_hex_file+0x295>
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
lea    0xcac(%rip),%rsi
jmp    13ff <read_hex_file+0x28f>
mov    0x2bea(%rip),%rax
mov    (%rax),%edi
lea    0xcc6(%rip),%rsi
xor    %r14d,%r14d
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"No record.\0A\00"
@.str.1 = [39 x i8] c"Checksum error. Got %02X, expected 00.\00"
@.str.2 = [25 x i8] c"... File position: %ld.\0A\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"Unsupported segmented address.\0A\00"
@.str.4 = [37 x i8] c"Extended address with wrong length.\0A\00"
@.str.5 = [44 x i8] c"Address too small (0x%X is below offset..)\0A\00"
@.str.6 = [45 x i8] c"Address too big (0x%X is > (size+offset)..)\0A\00"
@.str.7 = [30 x i8] c"Unsupported record type %2x.\0A\00"
define i32 @read_hex_file(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [8 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [64 x i32]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 65535, i32* %14
store i32 0, i32* %20
store i32* %19, i32** %21
br label %22
22: ; preds = %4, %160
br label %23
23: ; preds = %35, %22
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i32 @fread(i8* %24, i32 1, i32 1, i32* %25)
store i32 %26, i32* %10
br label %27
27: ; preds = %23
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 58
br label %35
35: ; preds = %30, %27
%36 = phi i1 [ false, %27 ], [ %34, %30 ]
br i1 %36, label %23, label %37
37: ; preds = %35
%38 = load i32, i32* %10
%39 = icmp ne i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %161
42: ; preds = %37
store i32 0, i32* %16
store i32 0, i32* %12
br label %43
43: ; preds = %54, %42
%44 = load i32*, i32** %6
%45 = call i32 @read_hexuint8_t(i32* %44)
store i32 %45, i32* %13
%46 = load i32, i32* %13
%47 = load i32, i32* %12
%48 = add nsw i32 %47, %46
store i32 %48, i32* %12
%49 = load i32, i32* %13
%50 = load i32, i32* %16
%51 = add nsw i32 %50, 1
store i32 %51, i32* %16
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 %52
store i32 %49, i32* %53
br label %54
54: ; preds = %43
%55 = load i32, i32* %16
%56 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 0
%57 = load i32, i32* %56
%58 = add nsw i32 %57, 5
%59 = icmp slt i32 %55, %58
br i1 %59, label %43, label %60
60: ; preds = %54
%61 = load i32, i32* %12
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %60
%64 = load i32, i32* %12
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %64)
%66 = load i32*, i32** %6
%67 = call i32 @ftell(i32* %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %63, %60
%70 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 3
%71 = load i32, i32* %70
switch i32 %71, label %155 [
i32 1, label %72
i32 2, label %74
i32 4, label %77
i32 0, label %94
]
72: ; preds = %69
%73 = load i32, i32* %20
store i32 %73, i32* %5
br label %161
74: ; preds = %69
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %161
77: ; preds = %69
%78 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 0
%79 = load i32, i32* %78
%80 = icmp eq i32 %79, 2
br i1 %80, label %81, label %90
81: ; preds = %77
%82 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 4
%83 = load i32, i32* %82
%84 = load i32*, i32** %21
%85 = getelementptr inbounds i32, i32* %84, i64 3
store i32 %83, i32* %85
%86 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 5
%87 = load i32, i32* %86
%88 = load i32*, i32** %21
%89 = getelementptr inbounds i32, i32* %88, i64 2
store i32 %87, i32* %89
br label %93
90: ; preds = %77
%91 = load i32, i32* @stderr
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %5
br label %161
93: ; preds = %81
br label %160
94: ; preds = %69
%95 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 2
%96 = load i32, i32* %95
%97 = load i32*, i32** %21
%98 = getelementptr inbounds i32, i32* %97, i64 0
store i32 %96, i32* %98
%99 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 1
%100 = load i32, i32* %99
%101 = load i32*, i32** %21
%102 = getelementptr inbounds i32, i32* %101, i64 1
store i32 %100, i32* %102
%103 = load i32, i32* %19
%104 = load i32, i32* %8
%105 = icmp slt i32 %103, %104
br i1 %105, label %106, label %110
106: ; preds = %94
%107 = load i32, i32* @stderr
%108 = load i32, i32* %19
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %108)
store i32 0, i32* %5
br label %161
110: ; preds = %94
%111 = load i32, i32* %19
%112 = load i32, i32* %8
%113 = sub nsw i32 %111, %112
%114 = load i32, i32* %9
%115 = icmp sge i32 %113, %114
br i1 %115, label %116, label %120
116: ; preds = %110
%117 = load i32, i32* @stderr
%118 = load i32, i32* %19
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 %118)
store i32 0, i32* %5
br label %161
120: ; preds = %110
store i32 0, i32* %16
br label %121
121: ; preds = %151, %120
%122 = load i32, i32* %16
%123 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 0
%124 = load i32, i32* %123
%125 = icmp slt i32 %122, %124
br i1 %125, label %126, label %154
126: ; preds = %121
%127 = load i32, i32* %16
%128 = add nsw i32 4, %127
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 %129
%131 = load i32, i32* %130
store i32 %131, i32* %17
%132 = load i32, i32* %17
%133 = load i32*, i32** %7
%134 = load i32, i32* %19
%135 = load i32, i32* %8
%136 = sub nsw i32 %134, %135
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds i32, i32* %133, i64 %137
store i32 %132, i32* %138
%139 = load i32, i32* %19
%140 = load i32, i32* %8
%141 = sub nsw i32 %139, %140
%142 = load i32, i32* %20
%143 = icmp sgt i32 %141, %142
br i1 %143, label %144, label %148
144: ; preds = %126
%145 = load i32, i32* %19
%146 = load i32, i32* %8
%147 = sub nsw i32 %145, %146
store i32 %147, i32* %20
br label %148
148: ; preds = %144, %126
%149 = load i32, i32* %19
%150 = add nsw i32 %149, 1
store i32 %150, i32* %19
br label %151
151: ; preds = %148
%152 = load i32, i32* %16
%153 = add nsw i32 %152, 1
store i32 %153, i32* %16
br label %121
154: ; preds = %121
br label %160
155: ; preds = %69
%156 = load i32, i32* @stderr
%157 = getelementptr inbounds [64 x i32], [64 x i32]* %15, i64 0, i64 3
%158 = load i32, i32* %157
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %158)
store i32 0, i32* %5
br label %161
160: ; preds = %154, %93
br label %22
161: ; preds = %155, %116, %106, %90, %74, %72, %40
%162 = load i32, i32* %5
ret i32 %162
}

LLVM IR (-O2):
@.str.1 = [39 x i8] c"Checksum error. Got %02X, expected 00.\00"
@.str.2 = [25 x i8] c"... File position: %ld.\0A\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"Unsupported segmented address.\0A\00"
@.str.4 = [37 x i8] c"Extended address with wrong length.\0A\00"
@.str.5 = [44 x i8] c"Address too small (0x%X is below offset..)\0A\00"
@.str.6 = [45 x i8] c"Address too big (0x%X is > (size+offset)..)\0A\00"
@.str.7 = [30 x i8] c"Unsupported record type %2x.\0A\00"
@str = [11 x i8] c"No record.\00"
define i32 @read_hex_file(i32* %0, i32* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = alloca [8 x i8]
%6 = alloca [64 x i32]
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = bitcast [64 x i32]* %6 to i8*
%9 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 0
%10 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 3
%11 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 2
%12 = sext i32 %2 to i64
%13 = sub nsw i64 0, %12
%14 = getelementptr i32, i32* %1, i64 %13
%15 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 4
%16 = bitcast i32* %15 to i8*
br label %36
17: ; preds = %101, %87
%18 = phi i32 [ undef, %87 ], [ %127, %101 ]
%19 = phi i64 [ %88, %87 ], [ %128, %101 ]
%20 = phi i32 [ %37, %87 ], [ %127, %101 ]
%21 = icmp eq i64 %94, 0
br i1 %21, label %34, label %22
22: ; preds = %17, %22
%23 = phi i64 [ %31, %22 ], [ %19, %17 ]
%24 = phi i32 [ %30, %22 ], [ %20, %17 ]
%25 = phi i64 [ %32, %22 ], [ 0, %17 ]
%26 = sub nsw i64 %23, %12
%27 = sext i32 %24 to i64
%28 = icmp sgt i64 %26, %27
%29 = trunc i64 %26 to i32
%30 = select i1 %28, i32 %29, i32 %24
%31 = add nsw i64 %23, 1
%32 = add i64 %25, 1
%33 = icmp eq i64 %32, %94
br i1 %33, label %34, label %22
34: ; preds = %22, %17
%35 = phi i32 [ %18, %17 ], [ %30, %22 ]
br label %36
36: ; preds = %34, %4
%37 = phi i32 [ %35, %34 ], [ 0, %4 ]
br label %38
38: ; preds = %86, %36
br label %39
39: ; preds = %39, %38
%40 = call i32 @fread(i8* %7, i32 1, i32 1, i32* %0)
%41 = icmp ne i32 %40, 0
%42 = load i8, i8* %7
%43 = icmp ne i8 %42, 58
%44 = select i1 %41, i1 %43, i1 false
br i1 %44, label %39, label %45
45: ; preds = %39
br i1 %41, label %48, label %46
46: ; preds = %45
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %134
48: ; preds = %45, %48
%49 = phi i64 [ %53, %48 ], [ 0, %45 ]
%50 = phi i32 [ %52, %48 ], [ 0, %45 ]
%51 = tail call i32 @read_hexuint8_t(i32* %0)
%52 = add nsw i32 %51, %50
%53 = add nuw nsw i64 %49, 1
%54 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 %49
store i32 %51, i32* %54
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 4
%57 = sext i32 %56 to i64
%58 = icmp slt i64 %49, %57
br i1 %58, label %48, label %59
59: ; preds = %48
%60 = icmp eq i32 %52, 0
br i1 %60, label %65, label %61
61: ; preds = %59
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%63 = tail call i32 @ftell(i32* %0)
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %61, %59
%66 = load i32, i32* %10
switch i32 %66, label %131 [
i32 1, label %134
i32 2, label %67
i32 4, label %70
i32 0, label %75
]
67: ; preds = %65
%68 = load i32, i32* @stderr
%69 = tail call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %134
70: ; preds = %65
%71 = icmp eq i32 %55, 2
br i1 %71, label %86, label %72
72: ; preds = %70
%73 = load i32, i32* @stderr
%74 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %134
75: ; preds = %65
%76 = load i32, i32* %11
%77 = icmp slt i32 %76, %2
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = tail call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %76)
br label %134
81: ; preds = %75
%82 = sub nsw i32 %76, %2
%83 = icmp slt i32 %82, %3
br i1 %83, label %84, label %98
84: ; preds = %81
%85 = icmp sgt i32 %55, 0
br i1 %85, label %87, label %86
86: ; preds = %84, %70
br label %38
87: ; preds = %84
%88 = sext i32 %76 to i64
%89 = getelementptr i32, i32* %14, i64 %88
%90 = bitcast i32* %89 to i8*
%91 = zext i32 %55 to i64
%92 = shl nuw nsw i64 %91, 2
%93 = add nsw i64 %91, -1
%94 = and i64 %91, 3
%95 = icmp ult i64 %93, 3
br i1 %95, label %17, label %96
96: ; preds = %87
%97 = and i64 %91, 4294967292
br label %101
98: ; preds = %81
%99 = load i32, i32* @stderr
%100 = tail call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 %76)
br label %134
101: ; preds = %101, %96
%102 = phi i64 [ %88, %96 ], [ %128, %101 ]
%103 = phi i32 [ %37, %96 ], [ %127, %101 ]
%104 = phi i64 [ 0, %96 ], [ %129, %101 ]
%105 = sub nsw i64 %102, %12
%106 = sext i32 %103 to i64
%107 = icmp sgt i64 %105, %106
%108 = trunc i64 %105 to i32
%109 = select i1 %107, i32 %108, i32 %103
%110 = add nsw i64 %102, 1
%111 = sub nsw i64 %110, %12
%112 = sext i32 %109 to i64
%113 = icmp sgt i64 %111, %112
%114 = trunc i64 %111 to i32
%115 = select i1 %113, i32 %114, i32 %109
%116 = add nsw i64 %102, 2
%117 = sub nsw i64 %116, %12
%118 = sext i32 %115 to i64
%119 = icmp sgt i64 %117, %118
%120 = trunc i64 %117 to i32
%121 = select i1 %119, i32 %120, i32 %115
%122 = add nsw i64 %102, 3
%123 = sub nsw i64 %122, %12
%124 = sext i32 %121 to i64
%125 = icmp sgt i64 %123, %124
%126 = trunc i64 %123 to i32
%127 = select i1 %125, i32 %126, i32 %121
%128 = add nsw i64 %102, 4
%129 = add i64 %104, 4
%130 = icmp eq i64 %129, %97
br i1 %130, label %17, label %101
131: ; preds = %65
%132 = load i32, i32* @stderr
%133 = tail call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %66)
br label %134
134: ; preds = %65, %131, %98, %78, %72, %67, %46
%135 = phi i32 [ 0, %131 ], [ 0, %78 ], [ 0, %98 ], [ 0, %72 ], [ 0, %67 ], [ 0, %46 ], [ %37, %65 ]
ret i32 %135
}