#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ hexstring_parse(char const *, int *, size_t *);
int /*<<< orphan*/ memcpy(int *, int *, int);
int ntohs(int);
int /*<<< orphan*/ stderr;
int read_record(uint8_t *buf, size_t buflen, const char *line, bool *eof) {
  size_t len;
  uint8_t sum = 0;
  uint8_t record_sum;
  uint8_t record_len;
  uint8_t type;
  uint16_t addr;
  uint8_t data[256];
  int i;
  *eof = false;
  if (line[0] != ':') {
    fprintf(stderr, "bad hexfile: no start\n");
    return 1;
  }
  line += 1;
  len = 1;
  if (0 != hexstring_parse(line, &record_len, &len)) {
    fprintf(stderr, "bad hexfile: no len '%s'\n", line);
    return 1;
  }
  line += len * 2;
  len = 2;
  if (0 != hexstring_parse(line, (uint8_t *)&addr, &len)) {
    fprintf(stderr, "bad hexfile: no addr\n");
    return 1;
  }
  addr = ntohs(addr);
  line += len * 2;
  len = 1;
  if (0 != hexstring_parse(line, &type, &len)) {
    fprintf(stderr, "bad hexfile: no type\n");
    return 1;
  }
  line += len * 2;
  len = record_len;
  if (0 != hexstring_parse(line, data, &len)) {
    fprintf(stderr, "bad hexfile: no data\n");
    return 1;
  }
  line += len * 2;
  len = 1;
  if (0 != hexstring_parse(line, &record_sum, &len)) {
    fprintf(stderr, "bad hexfile: no sum\n");
    return 1;
  }
  line += len * 2;
  if (type == 0) {
    sum += record_len;
    sum += addr >> 8;
    sum += addr & 0xFF;
    for (i = 0; i < record_len; i++)
      sum += data[i];
    sum = (sum ^ 0xFF) + 1;
    if (sum != record_sum) {
      fprintf(stderr, "bad hexfile, checksum mismatch\n");
      return 1;
    }
    if (addr + record_len > buflen) {
      fprintf(stderr, "bad hexfile, too big\n");
      return 1;
    }
    memcpy(buf + addr, data, record_len);
  } else if (type == 1) {
    *eof = true;
  } else {
    fprintf(stderr, "bad hexfile: unknown record type %02X\n", type);
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     119f <read_record+0x5f>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c1 <read_record+0x381>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <hexstring_parse@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11f9 <read_record+0xb9>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c1 <read_record+0x381>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x2,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x44(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <hexstring_parse@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1253 <read_record+0x113>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c1 <read_record+0x381>
mov    -0x44(%rbp),%edi
call   1050 <ntohs@plt>
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <hexstring_parse@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12b8 <read_record+0x178>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c1 <read_record+0x381>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movslq -0x3c(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x450(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <hexstring_parse@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1315 <read_record+0x1d5>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c1 <read_record+0x381>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <hexstring_parse@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     136f <read_record+0x22f>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c1 <read_record+0x381>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    1482 <read_record+0x342>
mov    -0x3c(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x44(%rbp),%eax
sar    $0x8,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x44(%rbp),%eax
and    $0xff,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x454(%rbp)
mov    -0x454(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    13ed <read_record+0x2ad>
movslq -0x454(%rbp),%rax
mov    -0x450(%rbp,%rax,4),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x454(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x454(%rbp)
jmp    13b6 <read_record+0x276>
mov    -0x34(%rbp),%eax
xor    $0xff,%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     142a <read_record+0x2ea>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
lea    0xc71(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c1 <read_record+0x381>
mov    -0x44(%rbp),%eax
add    -0x3c(%rbp),%eax
cltq
cmp    -0x18(%rbp),%rax
jbe    145f <read_record+0x31f>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
lea    0xc5c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c1 <read_record+0x381>
mov    -0x10(%rbp),%rdi
movslq -0x44(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x450(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1040 <memcpy@plt>
jmp    14ba <read_record+0x37a>
cmpl   $0x1,-0x40(%rbp)
jne    149b <read_record+0x35b>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    14b5 <read_record+0x375>
mov    0x2b3e(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%edx
lea    0xc10(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    14ba <read_record+0x37a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_record>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x428,%rsp
movl   $0x0,(%rcx)
cmpb   $0x3a,(%rdx)
jne    11a5 <read_record+0x65>
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
add    $0x1,%rbx
movq   $0x1,0x8(%rsp)
lea    0x14(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <hexstring_parse@plt>
test   %rax,%rax
je     11d2 <read_record+0x92>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11bc <read_record+0x7c>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x8(%rsp),%rax
lea    (%rbx,%rax,2),%rbx
movq   $0x2,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <hexstring_parse@plt>
test   %rax,%rax
je     120d <read_record+0xcd>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
jmp    11b5 <read_record+0x75>
mov    0x10(%rsp),%edi
call   1050 <ntohs@plt>
mov    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
lea    (%rbx,%rax,2),%rbx
movq   $0x1,0x8(%rsp)
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <hexstring_parse@plt>
test   %rax,%rax
je     1258 <read_record+0x118>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
jmp    11b5 <read_record+0x75>
mov    0x8(%rsp),%rax
lea    (%rbx,%rax,2),%rbx
movslq 0x14(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <hexstring_parse@plt>
test   %rax,%rax
je     1297 <read_record+0x157>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
jmp    11b5 <read_record+0x75>
mov    0x8(%rsp),%rax
lea    (%rbx,%rax,2),%rdi
movq   $0x1,0x8(%rsp)
lea    0x1c(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1060 <hexstring_parse@plt>
test   %rax,%rax
je     12d2 <read_record+0x192>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
jmp    11b5 <read_record+0x75>
mov    0x18(%rsp),%edx
cmp    $0x1,%edx
je     1308 <read_record+0x1c8>
test   %edx,%edx
jne    1317 <read_record+0x1d7>
mov    0x14(%rsp),%edx
movslq 0x10(%rsp),%rax
mov    %eax,%ecx
sar    $0x8,%ecx
add    %edx,%ecx
movzbl %al,%esi
add    %ecx,%esi
test   %edx,%edx
jle    13fd <read_record+0x2bd>
cmp    $0x8,%edx
jae    1335 <read_record+0x1f5>
xor    %ecx,%ecx
jmp    13f0 <read_record+0x2b0>
movl   $0x1,(%r12)
xor    %ebx,%ebx
jmp    11c1 <read_record+0x81>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11c1 <read_record+0x81>
mov    %edx,%ecx
and    $0xfffffff8,%ecx
movd   %esi,%xmm0
lea    -0x8(%rcx),%rdi
mov    %rdi,%rsi
shr    $0x3,%rsi
add    $0x1,%rsi
mov    %esi,%ebx
and    $0x3,%ebx
cmp    $0x18,%rdi
jae    1360 <read_record+0x220>
pxor   %xmm1,%xmm1
xor    %edi,%edi
jmp    13aa <read_record+0x26a>
and    $0xfffffffffffffffc,%rsi
pxor   %xmm1,%xmm1
xor    %edi,%edi
paddd  0x20(%rsp,%rdi,4),%xmm0
paddd  0x30(%rsp,%rdi,4),%xmm1
paddd  0x40(%rsp,%rdi,4),%xmm0
paddd  0x50(%rsp,%rdi,4),%xmm1
paddd  0x60(%rsp,%rdi,4),%xmm0
paddd  0x70(%rsp,%rdi,4),%xmm1
paddd  0x80(%rsp,%rdi,4),%xmm0
paddd  0x90(%rsp,%rdi,4),%xmm1
add    $0x20,%rdi
add    $0xfffffffffffffffc,%rsi
jne    136a <read_record+0x22a>
test   %rbx,%rbx
je     13d1 <read_record+0x291>
lea    (%rsp,%rdi,4),%rsi
add    $0x30,%rsi
shl    $0x5,%rbx
xor    %edi,%edi
paddd  -0x10(%rsi,%rdi,1),%xmm0
paddd  (%rsi,%rdi,1),%xmm1
add    $0x20,%rdi
cmp    %rdi,%rbx
jne    13bd <read_record+0x27d>
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%esi
cmp    %rdx,%rcx
je     13fd <read_record+0x2bd>
add    0x20(%rsp,%rcx,4),%esi
add    $0x1,%rcx
cmp    %rcx,%rdx
jne    13f0 <read_record+0x2b0>
xor    $0xff,%esi
add    $0x1,%esi
cmp    0x1c(%rsp),%esi
jne    142c <read_record+0x2ec>
lea    (%rax,%rdx,1),%ecx
movslq %ecx,%rcx
cmp    %r15,%rcx
jbe    1441 <read_record+0x301>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
lea    0xc81(%rip),%rsi
jmp    11b5 <read_record+0x75>
mov    0x2bad(%rip),%rax
mov    (%rax),%edi
lea    0xc4c(%rip),%rsi
jmp    11b5 <read_record+0x75>
lea    (%r14,%rax,4),%rdi
lea    0x20(%rsp),%rsi
call   1040 <memcpy@plt>
xor    %ebx,%ebx
jmp    11c1 <read_record+0x81>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"bad hexfile: no start\0A\00"
@.str.1 = [26 x i8] c"bad hexfile: no len '%s'\0A\00"
@.str.2 = [22 x i8] c"bad hexfile: no addr\0A\00"
@.str.3 = [22 x i8] c"bad hexfile: no type\0A\00"
@.str.4 = [22 x i8] c"bad hexfile: no data\0A\00"
@.str.5 = [21 x i8] c"bad hexfile: no sum\0A\00"
@.str.6 = [32 x i8] c"bad hexfile, checksum mismatch\0A\00"
@.str.7 = [22 x i8] c"bad hexfile, too big\0A\00"
@.str.8 = [39 x i8] c"bad hexfile: unknown record type %02X\0A\00"
define i32 @read_record(i32* %0, i64 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [256 x i32]
%17 = alloca i32
store i32* %0, i32** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i32 0, i32* %11
%18 = load i32*, i32** %9
store i32 0, i32* %18
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 58
br i1 %23, label %24, label %27
24: ; preds = %4
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %158
27: ; preds = %4
%28 = load i8*, i8** %8
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %29, i8** %8
store i64 1, i64* %10
%30 = load i8*, i8** %8
%31 = call i64 @hexstring_parse(i8* %30, i32* %13, i64* %10)
%32 = icmp ne i64 0, %31
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %8
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %35)
store i32 1, i32* %5
br label %158
37: ; preds = %27
%38 = load i64, i64* %10
%39 = mul i64 %38, 2
%40 = load i8*, i8** %8
%41 = getelementptr inbounds i8, i8* %40, i64 %39
store i8* %41, i8** %8
store i64 2, i64* %10
%42 = load i8*, i8** %8
%43 = call i64 @hexstring_parse(i8* %42, i32* %15, i64* %10)
%44 = icmp ne i64 0, %43
br i1 %44, label %45, label %48
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %5
br label %158
48: ; preds = %37
%49 = load i32, i32* %15
%50 = call i32 @ntohs(i32 %49)
store i32 %50, i32* %15
%51 = load i64, i64* %10
%52 = mul i64 %51, 2
%53 = load i8*, i8** %8
%54 = getelementptr inbounds i8, i8* %53, i64 %52
store i8* %54, i8** %8
store i64 1, i64* %10
%55 = load i8*, i8** %8
%56 = call i64 @hexstring_parse(i8* %55, i32* %14, i64* %10)
%57 = icmp ne i64 0, %56
br i1 %57, label %58, label %61
58: ; preds = %48
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %5
br label %158
61: ; preds = %48
%62 = load i64, i64* %10
%63 = mul i64 %62, 2
%64 = load i8*, i8** %8
%65 = getelementptr inbounds i8, i8* %64, i64 %63
store i8* %65, i8** %8
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
store i64 %67, i64* %10
%68 = load i8*, i8** %8
%69 = getelementptr inbounds [256 x i32], [256 x i32]* %16, i64 0, i64 0
%70 = call i64 @hexstring_parse(i8* %68, i32* %69, i64* %10)
%71 = icmp ne i64 0, %70
br i1 %71, label %72, label %75
72: ; preds = %61
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %5
br label %158
75: ; preds = %61
%76 = load i64, i64* %10
%77 = mul i64 %76, 2
%78 = load i8*, i8** %8
%79 = getelementptr inbounds i8, i8* %78, i64 %77
store i8* %79, i8** %8
store i64 1, i64* %10
%80 = load i8*, i8** %8
%81 = call i64 @hexstring_parse(i8* %80, i32* %12, i64* %10)
%82 = icmp ne i64 0, %81
br i1 %82, label %83, label %86
83: ; preds = %75
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %5
br label %158
86: ; preds = %75
%87 = load i64, i64* %10
%88 = mul i64 %87, 2
%89 = load i8*, i8** %8
%90 = getelementptr inbounds i8, i8* %89, i64 %88
store i8* %90, i8** %8
%91 = load i32, i32* %14
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %147
93: ; preds = %86
%94 = load i32, i32* %13
%95 = load i32, i32* %11
%96 = add nsw i32 %95, %94
store i32 %96, i32* %11
%97 = load i32, i32* %15
%98 = ashr i32 %97, 8
%99 = load i32, i32* %11
%100 = add nsw i32 %99, %98
store i32 %100, i32* %11
%101 = load i32, i32* %15
%102 = and i32 %101, 255
%103 = load i32, i32* %11
%104 = add nsw i32 %103, %102
store i32 %104, i32* %11
store i32 0, i32* %17
br label %105
105: ; preds = %116, %93
%106 = load i32, i32* %17
%107 = load i32, i32* %13
%108 = icmp slt i32 %106, %107
br i1 %108, label %109, label %119
109: ; preds = %105
%110 = load i32, i32* %17
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [256 x i32], [256 x i32]* %16, i64 0, i64 %111
%113 = load i32, i32* %112
%114 = load i32, i32* %11
%115 = add nsw i32 %114, %113
store i32 %115, i32* %11
br label %116
116: ; preds = %109
%117 = load i32, i32* %17
%118 = add nsw i32 %117, 1
store i32 %118, i32* %17
br label %105
119: ; preds = %105
%120 = load i32, i32* %11
%121 = xor i32 %120, 255
%122 = add nsw i32 %121, 1
store i32 %122, i32* %11
%123 = load i32, i32* %11
%124 = load i32, i32* %12
%125 = icmp ne i32 %123, %124
br i1 %125, label %126, label %129
126: ; preds = %119
%127 = load i32, i32* @stderr
%128 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %5
br label %158
129: ; preds = %119
%130 = load i32, i32* %15
%131 = load i32, i32* %13
%132 = add nsw i32 %130, %131
%133 = sext i32 %132 to i64
%134 = load i64, i64* %7
%135 = icmp ugt i64 %133, %134
br i1 %135, label %136, label %139
136: ; preds = %129
%137 = load i32, i32* @stderr
%138 = call i32 (i32, i8*, ...) @fprintf(i32 %137, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %5
br label %158
139: ; preds = %129
%140 = load i32*, i32** %6
%141 = load i32, i32* %15
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i32, i32* %140, i64 %142
%144 = getelementptr inbounds [256 x i32], [256 x i32]* %16, i64 0, i64 0
%145 = load i32, i32* %13
%146 = call i32 @memcpy(i32* %143, i32* %144, i32 %145)
br label %157
147: ; preds = %86
%148 = load i32, i32* %14
%149 = icmp eq i32 %148, 1
br i1 %149, label %150, label %152
150: ; preds = %147
%151 = load i32*, i32** %9
store i32 1, i32* %151
br label %156
152: ; preds = %147
%153 = load i32, i32* @stderr
%154 = load i32, i32* %14
%155 = call i32 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 %154)
br label %156
156: ; preds = %152, %150
br label %157
157: ; preds = %156, %139
store i32 0, i32* %5
br label %158
158: ; preds = %157, %136, %126, %83, %72, %58, %45, %33, %24
%159 = load i32, i32* %5
ret i32 %159
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"bad hexfile: no start\0A\00"
@.str.1 = [26 x i8] c"bad hexfile: no len '%s'\0A\00"
@.str.2 = [22 x i8] c"bad hexfile: no addr\0A\00"
@.str.3 = [22 x i8] c"bad hexfile: no type\0A\00"
@.str.4 = [22 x i8] c"bad hexfile: no data\0A\00"
@.str.5 = [21 x i8] c"bad hexfile: no sum\0A\00"
@.str.6 = [32 x i8] c"bad hexfile, checksum mismatch\0A\00"
@.str.7 = [22 x i8] c"bad hexfile, too big\0A\00"
@.str.8 = [39 x i8] c"bad hexfile: unknown record type %02X\0A\00"
define i32 @read_record(i32* %0, i64 %1, i8* %2, i32* nocapture writeonly %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [256 x i32]
%11 = bitcast i64* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = bitcast i32* %9 to i8*
%16 = bitcast [256 x i32]* %10 to i8*
store i32 0, i32* %3
%17 = load i8, i8* %2
%18 = icmp eq i8 %17, 58
br i1 %18, label %22, label %19
19: ; preds = %4
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %200
22: ; preds = %4
%23 = getelementptr inbounds i8, i8* %2, i64 1
store i64 1, i64* %5
%24 = call i64 @hexstring_parse(i8* %23, i32* %7, i64* %5)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %200
29: ; preds = %22
%30 = load i64, i64* %5
%31 = shl i64 %30, 1
%32 = getelementptr inbounds i8, i8* %23, i64 %31
store i64 2, i64* %5
%33 = call i64 @hexstring_parse(i8* %32, i32* %9, i64* %5)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %200
38: ; preds = %29
%39 = load i32, i32* %9
%40 = call i32 @ntohs(i32 %39)
store i32 %40, i32* %9
%41 = load i64, i64* %5
%42 = shl i64 %41, 1
%43 = getelementptr inbounds i8, i8* %32, i64 %42
store i64 1, i64* %5
%44 = call i64 @hexstring_parse(i8* %43, i32* %8, i64* %5)
%45 = icmp eq i64 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %200
49: ; preds = %38
%50 = load i64, i64* %5
%51 = shl i64 %50, 1
%52 = getelementptr inbounds i8, i8* %43, i64 %51
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
store i64 %54, i64* %5
%55 = getelementptr inbounds [256 x i32], [256 x i32]* %10, i64 0, i64 0
%56 = call i64 @hexstring_parse(i8* %52, i32* %55, i64* %5)
%57 = icmp eq i64 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %49
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %200
61: ; preds = %49
%62 = load i64, i64* %5
%63 = shl i64 %62, 1
%64 = getelementptr inbounds i8, i8* %52, i64 %63
store i64 1, i64* %5
%65 = call i64 @hexstring_parse(i8* %64, i32* %6, i64* %5)
%66 = icmp eq i64 %65, 0
br i1 %66, label %70, label %67
67: ; preds = %61
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %200
70: ; preds = %61
%71 = load i32, i32* %8
switch i32 %71, label %197 [
i32 0, label %72
i32 1, label %196
]
72: ; preds = %70
%73 = load i32, i32* %7
%74 = load i32, i32* %9
%75 = ashr i32 %74, 8
%76 = add nsw i32 %75, %73
%77 = and i32 %74, 255
%78 = add nsw i32 %76, %77
%79 = icmp sgt i32 %73, 0
br i1 %79, label %80, label %176
80: ; preds = %72
%81 = zext i32 %73 to i64
%82 = icmp ult i32 %73, 8
br i1 %82, label %165, label %83
83: ; preds = %80
%84 = and i64 %81, 4294967288
%85 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %78, i64 0
%86 = add nsw i64 %84, -8
%87 = lshr exact i64 %86, 3
%88 = add nuw nsw i64 %87, 1
%89 = and i64 %88, 3
%90 = icmp ult i64 %86, 24
br i1 %90, label %136, label %91
91: ; preds = %83
%92 = and i64 %88, 4611686018427387900
br label %93
93: ; preds = %93, %91
%94 = phi i64 [ 0, %91 ], [ %133, %93 ]
%95 = phi <4 x i32> [ %85, %91 ], [ %131, %93 ]
%96 = phi <4 x i32> [ zeroinitializer, %91 ], [ %132, %93 ]
%97 = phi i64 [ 0, %91 ], [ %134, %93 ]
%98 = getelementptr inbounds [256 x i32], [256 x i32]* %10, i64 0, i64 %94
%99 = bitcast i32* %98 to <4 x i32>*
%100 = load <4 x i32>, <4 x i32>* %99
%101 = getelementptr inbounds i32, i32* %98, i64 4
%102 = bitcast i32* %101 to <4 x i32>*
%103 = load <4 x i32>, <4 x i32>* %102
%104 = add <4 x i32> %100, %95
%105 = add <4 x i32> %103, %96
%106 = or i64 %94, 8
%107 = getelementptr inbounds [256 x i32], [256 x i32]* %10, i64 0, i64 %106
%108 = bitcast i32* %107 to <4 x i32>*
%109 = load <4 x i32>, <4 x i32>* %108
%110 = getelementptr inbounds i32, i32* %107, i64 4
%111 = bitcast i32* %110 to <4 x i32>*
%112 = load <4 x i32>, <4 x i32>* %111
%113 = add <4 x i32> %109, %104
%114 = add <4 x i32> %112, %105
%115 = or i64 %94, 16
%116 = getelementptr inbounds [256 x i32], [256 x i32]* %10, i64 0, i64 %115
%117 = bitcast i32* %116 to <4 x i32>*
%118 = load <4 x i32>, <4 x i32>* %117
%119 = getelementptr inbounds i32, i32* %116, i64 4
%120 = bitcast i32* %119 to <4 x i32>*
%121 = load <4 x i32>, <4 x i32>* %120
%122 = add <4 x i32> %118, %113
%123 = add <4 x i32> %121, %114
%124 = or i64 %94, 24
%125 = getelementptr inbounds [256 x i32], [256 x i32]* %10, i64 0, i64 %124
%126 = bitcast i32* %125 to <4 x i32>*
%127 = load <4 x i32>, <4 x i32>* %126
%128 = getelementptr inbounds i32, i32* %125, i64 4
%129 = bitcast i32* %128 to <4 x i32>*
%130 = load <4 x i32>, <4 x i32>* %129
%131 = add <4 x i32> %127, %122
%132 = add <4 x i32> %130, %123
%133 = add nuw i64 %94, 32
%134 = add i64 %97, 4
%135 = icmp eq i64 %134, %92
br i1 %135, label %136, label %93
136: ; preds = %93, %83
%137 = phi <4 x i32> [ undef, %83 ], [ %131, %93 ]
%138 = phi <4 x i32> [ undef, %83 ], [ %132, %93 ]
%139 = phi i64 [ 0, %83 ], [ %133, %93 ]
%140 = phi <4 x i32> [ %85, %83 ], [ %131, %93 ]
%141 = phi <4 x i32> [ zeroinitializer, %83 ], [ %132, %93 ]
%142 = icmp eq i64 %89, 0
br i1 %142, label %159, label %143
143: ; preds = %136, %143
%144 = phi i64 [ %156, %143 ], [ %139, %136 ]
%145 = phi <4 x i32> [ %154, %143 ], [ %140, %136 ]
%146 = phi <4 x i32> [ %155, %143 ], [ %141, %136 ]
%147 = phi i64 [ %157, %143 ], [ 0, %136 ]
%148 = getelementptr inbounds [256 x i32], [256 x i32]* %10, i64 0, i64 %144
%149 = bitcast i32* %148 to <4 x i32>*
%150 = load <4 x i32>, <4 x i32>* %149
%151 = getelementptr inbounds i32, i32* %148, i64 4
%152 = bitcast i32* %151 to <4 x i32>*
%153 = load <4 x i32>, <4 x i32>* %152
%154 = add <4 x i32> %150, %145
%155 = add <4 x i32> %153, %146
%156 = add nuw i64 %144, 8
%157 = add i64 %147, 1
%158 = icmp eq i64 %157, %89
br i1 %158, label %159, label %143
159: ; preds = %143, %136
%160 = phi <4 x i32> [ %137, %136 ], [ %154, %143 ]
%161 = phi <4 x i32> [ %138, %136 ], [ %155, %143 ]
%162 = add <4 x i32> %161, %160
%163 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %162)
%164 = icmp eq i64 %84, %81
br i1 %164, label %176, label %165
165: ; preds = %80, %159
%166 = phi i64 [ 0, %80 ], [ %84, %159 ]
%167 = phi i32 [ %78, %80 ], [ %163, %159 ]
br label %168
168: ; preds = %165, %168
%169 = phi i64 [ %174, %168 ], [ %166, %165 ]
%170 = phi i32 [ %173, %168 ], [ %167, %165 ]
%171 = getelementptr inbounds [256 x i32], [256 x i32]* %10, i64 0, i64 %169
%172 = load i32, i32* %171
%173 = add nsw i32 %172, %170
%174 = add nuw nsw i64 %169, 1
%175 = icmp eq i64 %174, %81
br i1 %175, label %176, label %168
176: ; preds = %168, %159, %72
%177 = phi i32 [ %78, %72 ], [ %163, %159 ], [ %173, %168 ]
%178 = xor i32 %177, 255
%179 = add nsw i32 %178, 1
%180 = load i32, i32* %6
%181 = icmp eq i32 %179, %180
br i1 %181, label %185, label %182
182: ; preds = %176
%183 = load i32, i32* @stderr
%184 = call i32 (i32, i8*, ...) @fprintf(i32 %183, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
br label %200
185: ; preds = %176
%186 = add nsw i32 %74, %73
%187 = sext i32 %186 to i64
%188 = icmp ugt i64 %187, %1
br i1 %188, label %189, label %192
189: ; preds = %185
%190 = load i32, i32* @stderr
%191 = call i32 (i32, i8*, ...) @fprintf(i32 %190, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
br label %200
192: ; preds = %185
%193 = sext i32 %74 to i64
%194 = getelementptr inbounds i32, i32* %0, i64 %193
%195 = call i32 @memcpy(i32* %194, i32* %55, i32 %73)
br label %200
196: ; preds = %70
store i32 1, i32* %3
br label %200
197: ; preds = %70
%198 = load i32, i32* @stderr
%199 = call i32 (i32, i8*, ...) @fprintf(i32 %198, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32 %71)
br label %200
200: ; preds = %192, %197, %196, %189, %182, %67, %58, %46, %35, %26, %19
%201 = phi i32 [ 1, %19 ], [ 1, %26 ], [ 1, %35 ], [ 1, %46 ], [ 1, %58 ], [ 1, %67 ], [ 1, %182 ], [ 1, %189 ], [ 0, %196 ], [ 0, %197 ], [ 0, %192 ]
ret i32 %201
}