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

/* Variables and functions */
int /*<<< orphan*/ bzero(unsigned char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned char *);
scalar_t__ memcmp(unsigned char *, char *, int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, ...);
int hexfile_build_tables(char *ihexfile, unsigned char *page_buffer,
                         unsigned char *page_table) {
  unsigned char buffer[256];
  int length;
  int i;
  int pages;
  unsigned long ext_addr = 0;
  unsigned short int addr = 0;
  FILE *ihex_fp;
  if ((ihex_fp = (FILE *)fopen(ihexfile, "r")) == NULL) {
    printf("Failed to open .ihex file %s\n", ihexfile);
    return (-1);
  } else {
    printf(".ihex file ok.\n");
  }
  bzero(buffer, sizeof(buffer));
  memset(page_table, 0, 64);
  memset(page_buffer, 0xFF, sizeof(page_buffer));
  pages = 0;
  while ((fscanf(ihex_fp, "%s", buffer) == 1)) {
    unsigned char data_len = 0;
    if (memcmp(&buffer[7], "00", 2) == 0) {
      i = 0;
      sscanf((char *)&buffer[1], "%2hhx", &data_len);
      sscanf((char *)&(buffer[3]), "%4hx", &addr);
      while (i < data_len) {
        uint32_t absolute_address = ext_addr + addr + i;
        if (page_table[absolute_address / 2048] == 0) {
          page_table[absolute_address / 2048] = 1;
          printf("Writing %d pages.\r", ++pages);
        }
        sscanf((char *)&buffer[2 * i + 9], "%2hhx",
               &page_buffer[absolute_address]);
        i++;
      }
    } else if (memcmp(&buffer[7], "01", 2) == 0) {
      printf("\nFile read complete.\n");
      break;
    } else if (memcmp(&buffer[7], "04", 2) == 0) {
      sscanf((char *)&(buffer[3]), "%4hx", &addr);
      sscanf((char *)&(buffer[9]), "%4lx", &ext_addr);
      printf("\nExtended page address: 0x%8.8lX\n", ext_addr * 0x8000);
      if (ext_addr)
        ext_addr--;
      ext_addr *= 0x8000;
    }
  }
  fclose(ihex_fp);
  return (pages);
}


x86 assembly (clang, -O0):
<hexfile_build_tables>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x138(%rbp)
movw   $0x0,-0x13a(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x148(%rbp)
cmp    $0x0,%rax
jne    11ea <hexfile_build_tables+0x6a>
mov    -0x10(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d9 <hexfile_build_tables+0x359>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10a0 <bzero@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    $0xff,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
movl   $0x0,-0x12c(%rbp)
mov    -0x148(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xde5(%rip),%rsi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    14c4 <hexfile_build_tables+0x344>
movb   $0x0,-0x149(%rbp)
lea    -0x120(%rbp),%rdi
add    $0x7,%rdi
lea    0xdc1(%rip),%rsi
mov    $0x2,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
jne    13cb <hexfile_build_tables+0x24b>
movl   $0x0,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
add    $0x1,%rdi
lea    0xd94(%rip),%rsi
lea    -0x149(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
lea    -0x120(%rbp),%rdi
add    $0x3,%rdi
lea    0xd7a(%rip),%rsi
lea    -0x13a(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    -0x128(%rbp),%eax
movzbl -0x149(%rbp),%ecx
cmp    %ecx,%eax
jge    13c6 <hexfile_build_tables+0x246>
mov    -0x138(%rbp),%rax
movzwl -0x13a(%rbp),%ecx
add    %rcx,%rax
movslq -0x128(%rbp),%rcx
add    %rcx,%rax
mov    %eax,-0x150(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x150(%rbp),%eax
mov    $0x800,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x158(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    137e <hexfile_build_tables+0x1fe>
mov    -0x20(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x150(%rbp),%eax
mov    $0x800,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x160(%rbp),%rax
movslq %ecx,%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x12c(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x12c(%rbp)
lea    0xcca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%eax
shl    $0x1,%eax
add    $0x9,%eax
cltq
lea    -0x120(%rbp),%rdi
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
movslq -0x150(%rbp),%rax
add    %rax,%rdx
lea    0xc8b(%rip),%rsi
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    12d0 <hexfile_build_tables+0x150>
jmp    14bf <hexfile_build_tables+0x33f>
lea    -0x120(%rbp),%rdi
add    $0x7,%rdi
lea    0xc77(%rip),%rsi
mov    $0x2,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
jne    1404 <hexfile_build_tables+0x284>
lea    0xc5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14c4 <hexfile_build_tables+0x344>
lea    -0x120(%rbp),%rdi
add    $0x7,%rdi
lea    0xc57(%rip),%rsi
mov    $0x2,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
jne    14b5 <hexfile_build_tables+0x335>
lea    -0x120(%rbp),%rdi
add    $0x3,%rdi
lea    0xc00(%rip),%rsi
lea    -0x13a(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
lea    -0x120(%rbp),%rdi
add    $0x9,%rdi
lea    0xc14(%rip),%rsi
lea    -0x138(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    -0x138(%rbp),%rsi
shl    $0xf,%rsi
lea    0xbf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x138(%rbp)
je     14a3 <hexfile_build_tables+0x323>
mov    -0x138(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
shl    $0xf,%rax
mov    %rax,-0x138(%rbp)
jmp    14ba <hexfile_build_tables+0x33a>
jmp    14bf <hexfile_build_tables+0x33f>
jmp    1236 <hexfile_build_tables+0xb6>
mov    -0x148(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x12c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexfile_build_tables>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,%rbp
movq   $0x0,0x8(%rsp)
movw   $0x0,0x6(%rsp)
lea    0xe3f(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13ff <hexfile_build_tables+0x26f>
mov    %rax,%r12
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
mov    %r13,0x10(%rsp)
mov    %r13,%rdi
mov    $0xff,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    0xe00(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    1424 <hexfile_build_tables+0x294>
lea    0x27(%rsp),%rbp
xor    %r15d,%r15d
mov    %r12,0x18(%rsp)
jmp    1277 <hexfile_build_tables+0xe7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x18(%rsp),%r12
mov    %r12,%rdi
lea    0xdc1(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1070 <fscanf@plt>
cmp    $0x1,%eax
lea    0x27(%rsp),%rbp
jne    1424 <hexfile_build_tables+0x294>
movb   $0x0,0x5(%rsp)
mov    %rbp,%rdi
lea    0xd9d(%rip),%rsi
mov    $0x2,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     1340 <hexfile_build_tables+0x1b0>
mov    %rbp,%rdi
lea    0xda1(%rip),%rsi
mov    $0x2,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     1418 <hexfile_build_tables+0x288>
mov    %rbp,%rdi
lea    0xd87(%rip),%rsi
mov    $0x2,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
jne    1250 <hexfile_build_tables+0xc0>
lea    0x23(%rsp),%rdi
lea    0xd51(%rip),%rsi
lea    0x6(%rsp),%rdx
xor    %eax,%eax
call   1090 <sscanf@plt>
lea    0x29(%rsp),%rdi
lea    0xd57(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1090 <sscanf@plt>
mov    0x8(%rsp),%rsi
shl    $0xf,%rsi
lea    0xd40(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    %rax,%rcx
shl    $0xf,%rcx
add    $0xffffffffffff8000,%rcx
test   %rax,%rax
cmove  %rax,%rcx
mov    %rcx,0x8(%rsp)
jmp    1250 <hexfile_build_tables+0xc0>
nopw   0x0(%rax,%rax,1)
lea    0x21(%rsp),%rdi
lea    0xcda(%rip),%rsi
lea    0x5(%rsp),%rdx
xor    %eax,%eax
call   1090 <sscanf@plt>
lea    0x23(%rsp),%rdi
lea    0xcc8(%rip),%rsi
lea    0x6(%rsp),%rdx
xor    %eax,%eax
call   1090 <sscanf@plt>
cmpb   $0x0,0x5(%rsp)
je     1250 <hexfile_build_tables+0xc0>
lea    0x29(%rsp),%r14
xor    %r12d,%r12d
mov    0x10(%rsp),%rbp
jmp    13bd <hexfile_build_tables+0x22d>
nopw   0x0(%rax,%rax,1)
movslq %r13d,%rdx
add    %rbp,%rdx
mov    %r14,%rdi
lea    0xc86(%rip),%rsi
xor    %eax,%eax
call   1090 <sscanf@plt>
add    $0x1,%r12
movzbl 0x5(%rsp),%eax
add    $0x2,%r14
cmp    %rax,%r12
jae    1250 <hexfile_build_tables+0xc0>
movzwl 0x6(%rsp),%r13d
add    0x8(%rsp),%r13d
add    %r12,%r13
lea    0x7ff(%r13),%eax
test   %r13d,%r13d
cmovns %r13d,%eax
sar    $0xb,%eax
cltq
cmpb   $0x0,(%rbx,%rax,1)
jne    1390 <hexfile_build_tables+0x200>
movb   $0x1,(%rbx,%rax,1)
add    $0x1,%r15d
lea    0xc3e(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1390 <hexfile_build_tables+0x200>
lea    0xbfc(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r15d
jmp    142c <hexfile_build_tables+0x29c>
lea    0xc61(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r15d,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [30 x i8] c"Failed to open .ihex file %s\0A\00"
@.str.2 = [16 x i8] c".ihex file ok.\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [3 x i8] c"00\00"
@.str.5 = [6 x i8] c"%2hhx\00"
@.str.6 = [5 x i8] c"%4hx\00"
@.str.7 = [19 x i8] c"Writing %d pages.\0D\00"
@.str.8 = [3 x i8] c"01\00"
@.str.9 = [22 x i8] c"\0AFile read complete.\0A\00"
@.str.10 = [3 x i8] c"04\00"
@.str.11 = [5 x i8] c"%4lx\00"
@.str.12 = [34 x i8] c"\0AExtended page address: 0x%8.8lX\0A\00"
define i32 @hexfile_build_tables(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i16
%14 = alloca i32*
%15 = alloca i8
%16 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 0, i64* %12
store i16 0, i16* %13
%17 = load i8*, i8** %5
%18 = call i64 @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %14
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 -1, i32* %4
br label %125
24: ; preds = %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = call i32 @bzero(i8* %27, i32 256)
%29 = load i8*, i8** %7
%30 = call i32 @memset(i8* %29, i32 0, i32 64)
%31 = load i8*, i8** %6
%32 = call i32 @memset(i8* %31, i32 255, i32 8)
store i32 0, i32* %11
br label %33
33: ; preds = %120, %26
%34 = load i32*, i32** %14
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%36 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %121
38: ; preds = %33
store i8 0, i8* %15
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 7
%40 = call i64 @memcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %92
42: ; preds = %38
store i32 0, i32* %10
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 1
%44 = call i32 (i8*, i8*, ...) @sscanf(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 3
%46 = call i32 (i8*, i8*, ...) @sscanf(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i16* %13)
br label %47
47: ; preds = %78, %42
%48 = load i32, i32* %10
%49 = load i8, i8* %15
%50 = zext i8 %49 to i32
%51 = icmp slt i32 %48, %50
br i1 %51, label %52, label %91
52: ; preds = %47
%53 = load i64, i64* %12
%54 = load i16, i16* %13
%55 = zext i16 %54 to i64
%56 = add i64 %53, %55
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = add i64 %56, %58
%60 = trunc i64 %59 to i32
store i32 %60, i32* %16
%61 = load i8*, i8** %7
%62 = load i32, i32* %16
%63 = sdiv i32 %62, 2048
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %78
69: ; preds = %52
%70 = load i8*, i8** %7
%71 = load i32, i32* %16
%72 = sdiv i32 %71, 2048
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %70, i64 %73
store i8 1, i8* %74
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %69, %52
%79 = load i32, i32* %10
%80 = mul nsw i32 2, %79
%81 = add nsw i32 %80, 9
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %82
%84 = load i8*, i8** %6
%85 = load i32, i32* %16
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = call i32 (i8*, i8*, ...) @sscanf(i8* %83, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %87)
%89 = load i32, i32* %10
%90 = add nsw i32 %89, 1
store i32 %90, i32* %10
br label %47
91: ; preds = %47
br label %120
92: ; preds = %38
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 7
%94 = call i64 @memcmp(i8* %93, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 2)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %92
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %121
98: ; preds = %92
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 7
%100 = call i64 @memcmp(i8* %99, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 2)
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %118
102: ; preds = %98
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 3
%104 = call i32 (i8*, i8*, ...) @sscanf(i8* %103, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i16* %13)
%105 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 9
%106 = call i32 (i8*, i8*, ...) @sscanf(i8* %105, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i64* %12)
%107 = load i64, i64* %12
%108 = mul i64 %107, 32768
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0), i64 %108)
%110 = load i64, i64* %12
%111 = icmp ne i64 %110, 0
br i1 %111, label %112, label %115
112: ; preds = %102
%113 = load i64, i64* %12
%114 = add i64 %113, -1
store i64 %114, i64* %12
br label %115
115: ; preds = %112, %102
%116 = load i64, i64* %12
%117 = mul i64 %116, 32768
store i64 %117, i64* %12
br label %118
118: ; preds = %115, %98
br label %119
119: ; preds = %118
br label %120
120: ; preds = %119, %91
br label %33
121: ; preds = %96, %33
%122 = load i32*, i32** %14
%123 = call i32 @fclose(i32* %122)
%124 = load i32, i32* %11
store i32 %124, i32* %4
br label %125
125: ; preds = %121, %21
%126 = load i32, i32* %4
ret i32 %126
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [30 x i8] c"Failed to open .ihex file %s\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [3 x i8] c"00\00"
@.str.5 = [6 x i8] c"%2hhx\00"
@.str.6 = [5 x i8] c"%4hx\00"
@.str.7 = [19 x i8] c"Writing %d pages.\0D\00"
@.str.8 = [3 x i8] c"01\00"
@.str.10 = [3 x i8] c"04\00"
@.str.11 = [5 x i8] c"%4lx\00"
@.str.12 = [34 x i8] c"\0AExtended page address: 0x%8.8lX\0A\00"
@str = [15 x i8] c".ihex file ok.\00"
@str.13 = [21 x i8] c"\0AFile read complete.\00"
define i32 @hexfile_build_tables(i8* %0, i8* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca i64
%6 = alloca i16
%7 = alloca i8
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%10 = bitcast i16* %6 to i8*
store i16 0, i16* %6
%11 = tail call i64 @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = inttoptr i64 %11 to i32*
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %93
16: ; preds = %3
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%18 = call i32 @bzero(i8* %8, i32 256)
%19 = tail call i32 @memset(i8* %2, i32 0, i32 64)
%20 = tail call i32 @memset(i8* %1, i32 255, i32 8)
%21 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %90
23: ; preds = %16
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 7
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 3
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 9
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 1
br label %28
28: ; preds = %23, %86
%29 = phi i32 [ 0, %23 ], [ %87, %86 ]
store i8 0, i8* %7
%30 = call i64 @memcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %67
32: ; preds = %28
%33 = call i32 (i8*, i8*, ...) @sscanf(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%34 = call i32 (i8*, i8*, ...) @sscanf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i16* %6)
%35 = load i8, i8* %7
%36 = icmp eq i8 %35, 0
br i1 %36, label %86, label %37
37: ; preds = %32, %55
%38 = phi i64 [ %63, %55 ], [ 0, %32 ]
%39 = phi i32 [ %56, %55 ], [ %29, %32 ]
%40 = load i64, i64* %5
%41 = load i16, i16* %6
%42 = zext i16 %41 to i64
%43 = add i64 %40, %42
%44 = trunc i64 %43 to i32
%45 = trunc i64 %38 to i32
%46 = add i32 %45, %44
%47 = sdiv i32 %46, 2048
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %2, i64 %48
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %37
store i8 1, i8* %49
%53 = add nsw i32 %39, 1
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %52, %37
%56 = phi i32 [ %53, %52 ], [ %39, %37 ]
%57 = shl nuw nsw i64 %38, 1
%58 = add nuw nsw i64 %57, 9
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %58
%60 = sext i32 %46 to i64
%61 = getelementptr inbounds i8, i8* %1, i64 %60
%62 = call i32 (i8*, i8*, ...) @sscanf(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %61)
%63 = add nuw nsw i64 %38, 1
%64 = load i8, i8* %7
%65 = zext i8 %64 to i64
%66 = icmp ult i64 %63, %65
br i1 %66, label %37, label %86
67: ; preds = %28
%68 = call i64 @memcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 2)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.13, i64 0, i64 0))
br label %90
72: ; preds = %67
%73 = call i64 @memcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 2)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %86
75: ; preds = %72
%76 = call i32 (i8*, i8*, ...) @sscanf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i16* %6)
%77 = call i32 (i8*, i8*, ...) @sscanf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i64* %5)
%78 = load i64, i64* %5
%79 = shl i64 %78, 15
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0), i64 %79)
%81 = load i64, i64* %5
%82 = icmp eq i64 %81, 0
%83 = shl i64 %81, 15
%84 = add i64 %83, -32768
%85 = select i1 %82, i64 0, i64 %84
store i64 %85, i64* %5
br label %86
86: ; preds = %55, %32, %72, %75
%87 = phi i32 [ %29, %75 ], [ %29, %72 ], [ %29, %32 ], [ %56, %55 ]
%88 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%89 = icmp eq i32 %88, 1
br i1 %89, label %28, label %90
90: ; preds = %86, %16, %70
%91 = phi i32 [ %29, %70 ], [ 0, %16 ], [ %87, %86 ]
%92 = call i32 @fclose(i32* %12)
br label %93
93: ; preds = %90, %14
%94 = phi i32 [ -1, %14 ], [ %91, %90 ]
ret i32 %94
}