#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 */
struct dev {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fatal_(int, char *, int, char *, ...);
int /*<<< orphan*/ fatal_e_(int, char *, int, char *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ pic_bulk_erase(struct dev *);
int /*<<< orphan*/ pic_enter_LVP(struct dev *);
int /*<<< orphan*/ pic_increment_address(struct dev *);
int /*<<< orphan*/ pic_int_program(struct dev *, int);
int /*<<< orphan*/ pic_load_configuration(struct dev *);
int /*<<< orphan*/ pic_load_data(struct dev *, unsigned int);
int /*<<< orphan*/ pic_reset_address(struct dev *);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
void program_hex_file(struct dev *dev, FILE *f) {
  pic_enter_LVP(dev);
  pic_load_configuration(dev);
  pic_bulk_erase(dev);
  pic_reset_address(dev);
  int l = 1;
  unsigned int pc = 0, len, newpc = 0;
  int r;
  while (true) {
    unsigned int newpc_l, type;
    r = fscanf(f, ":%2x%4x%2x", &len, &newpc_l, &type);
    if (ferror(f))
      do {
        fatal_e_(1,
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/heads/"
                 "master/pickler.c",
                 648, "Can't read from hex file");
      } while (0);
    if (r < 3 || r == EOF)
      do {
        fatal_(1,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/heads/"
               "master/pickler.c",
               650, "%d: Expected colon, length, address, and type", l);
      } while (0);
    len /= 2;
    newpc_l /= 2;
    if (type == 0x01) {
      break;
    } else if (type == 0x04) {
      unsigned int newpc_h;
      r = fscanf(f, "%4x", &newpc_h);
      if (ferror(f))
        do {
          fatal_e_(1,
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/"
                   "heads/master/pickler.c",
                   662, "Can't read from hex file");
        } while (0);
      if (r < 1 || r == EOF)
        do {
          fatal_(1,
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/heads/"
                 "master/pickler.c",
                 664, "%d: Expected upper address", l);
        } while (0);
      newpc = newpc_h << 15;
    } else if (type == 0x00) {
      newpc = (newpc & ~0x7FFF) | newpc_l;
      if ((pc < 0x8000 || pc > newpc) && newpc >= 0x8000) {
        pic_load_configuration(dev);
        pc = 0x8000;
      } else if ((pc >= 0x8000 || pc > newpc) && newpc < 0x8000) {
        pic_reset_address(dev);
        pc = 0x0000;
      }
      while (pc < newpc) {
        pic_increment_address(dev);
        ++pc;
      }
      for (unsigned int i = 0; i < len; ++i) {
        unsigned int low, high;
        r = fscanf(f, "%2x%2x", &low, &high);
        if (ferror(f))
          do {
            fatal_e_(1,
                     "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                     "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/"
                     "heads/master/pickler.c",
                     686, "Can't read from hex file");
          } while (0);
        if (r < 2 || r == EOF)
          do {
            fatal_(1,
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/"
                   "heads/master/pickler.c",
                   688, "Expected word");
          } while (0);
        unsigned int word = low + (high << 8);
        pic_load_data(dev, word);
        pic_int_program(dev, false);
        printf("[0x%04X] = 0x%04X\n", pc, word);
        pic_increment_address(dev);
        ++pc;
      }
    } else {
      do {
        fatal_(1,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/heads/"
               "master/pickler.c",
               697, "Unrecognized type");
      } while (0);
    }
    r = fscanf(f, "%*2x\n");
    if (ferror(f))
      do {
        fatal_e_(1,
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/heads/"
                 "master/pickler.c",
                 702, "Can't read from hex file");
      } while (0);
    if (r == EOF)
      do {
        fatal_(1,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/heads/"
               "master/pickler.c",
               704, "Expected checksum and newline");
      } while (0);
  }
}


x86 assembly (clang, -O0):
<program_hex_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <pic_enter_LVP@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <pic_load_configuration@plt>
mov    -0x8(%rbp),%rdi
call   10d0 <pic_bulk_erase@plt>
mov    -0x8(%rbp),%rdi
call   10e0 <pic_reset_address@plt>
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdec(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
mov    $0x0,%al
call   1090 <fscanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1264 <program_hex_file+0xa4>
jmp    1242 <program_hex_file+0x82>
mov    $0x1,%edi
lea    0xdbd(%rip),%rsi
mov    $0x288,%edx
lea    0xe37(%rip),%rcx
call   1060 <fatal_e_@plt>
jmp    1264 <program_hex_file+0xa4>
cmpl   $0x3,-0x24(%rbp)
jl     1280 <program_hex_file+0xc0>
mov    -0x24(%rbp),%eax
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%eax
jne    12ad <program_hex_file+0xed>
jmp    1285 <program_hex_file+0xc5>
mov    -0x14(%rbp),%r8d
mov    $0x1,%edi
lea    0xd76(%rip),%rsi
mov    $0x28a,%edx
lea    0xe09(%rip),%rcx
mov    $0x0,%al
call   10b0 <fatal_@plt>
jmp    12ad <program_hex_file+0xed>
mov    -0x1c(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    12ce <program_hex_file+0x10e>
jmp    1605 <program_hex_file+0x445>
cmpl   $0x4,-0x2c(%rbp)
jne    1382 <program_hex_file+0x1c2>
mov    -0x10(%rbp),%rdi
lea    0xdf5(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1090 <fscanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     132b <program_hex_file+0x16b>
jmp    1309 <program_hex_file+0x149>
mov    $0x1,%edi
lea    0xcf6(%rip),%rsi
mov    $0x296,%edx
lea    0xd70(%rip),%rcx
call   1060 <fatal_e_@plt>
jmp    132b <program_hex_file+0x16b>
cmpl   $0x1,-0x24(%rbp)
jl     1347 <program_hex_file+0x187>
mov    -0x24(%rbp),%eax
mov    0x2ca9(%rip),%rcx
cmp    (%rcx),%eax
jne    1374 <program_hex_file+0x1b4>
jmp    134c <program_hex_file+0x18c>
mov    -0x14(%rbp),%r8d
mov    $0x1,%edi
lea    0xcaf(%rip),%rsi
mov    $0x298,%edx
lea    0xd74(%rip),%rcx
mov    $0x0,%al
call   10b0 <fatal_@plt>
jmp    1374 <program_hex_file+0x1b4>
mov    -0x30(%rbp),%eax
shl    $0xf,%eax
mov    %eax,-0x20(%rbp)
jmp    1571 <program_hex_file+0x3b1>
cmpl   $0x0,-0x2c(%rbp)
jne    1543 <program_hex_file+0x383>
mov    -0x20(%rbp),%eax
and    $0xffff8000,%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x8000,-0x18(%rbp)
jb     13b3 <program_hex_file+0x1f3>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jbe    13d5 <program_hex_file+0x215>
cmpl   $0x8000,-0x20(%rbp)
jb     13d5 <program_hex_file+0x215>
mov    -0x8(%rbp),%rdi
call   10a0 <pic_load_configuration@plt>
movl   $0x8000,-0x18(%rbp)
jmp    1410 <program_hex_file+0x250>
cmpl   $0x8000,-0x18(%rbp)
jae    13ee <program_hex_file+0x22e>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jbe    140b <program_hex_file+0x24b>
cmpl   $0x8000,-0x20(%rbp)
jae    140b <program_hex_file+0x24b>
mov    -0x8(%rbp),%rdi
call   10e0 <pic_reset_address@plt>
movl   $0x0,-0x18(%rbp)
jmp    1410 <program_hex_file+0x250>
jmp    1415 <program_hex_file+0x255>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    1438 <program_hex_file+0x278>
mov    -0x8(%rbp),%rdi
call   10c0 <pic_increment_address@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1415 <program_hex_file+0x255>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    153e <program_hex_file+0x37e>
mov    -0x10(%rbp),%rdi
lea    0xca1(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
mov    $0x0,%al
call   1090 <fscanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     14a2 <program_hex_file+0x2e2>
jmp    1480 <program_hex_file+0x2c0>
mov    $0x1,%edi
lea    0xb7f(%rip),%rsi
mov    $0x2ae,%edx
lea    0xbf9(%rip),%rcx
call   1060 <fatal_e_@plt>
jmp    14a2 <program_hex_file+0x2e2>
cmpl   $0x2,-0x24(%rbp)
jl     14be <program_hex_file+0x2fe>
mov    -0x24(%rbp),%eax
mov    0x2b32(%rip),%rcx
cmp    (%rcx),%eax
jne    14e7 <program_hex_file+0x327>
jmp    14c3 <program_hex_file+0x303>
mov    $0x1,%edi
lea    0xb3c(%rip),%rsi
mov    $0x2b0,%edx
lea    0xc23(%rip),%rcx
mov    $0x0,%al
call   10b0 <fatal_@plt>
jmp    14e7 <program_hex_file+0x327>
mov    -0x38(%rbp),%eax
mov    -0x3c(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1040 <pic_load_data@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <pic_int_program@plt>
mov    -0x18(%rbp),%esi
mov    -0x40(%rbp),%edx
lea    0xbf3(%rip),%rdi
call   1080 <printf@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <pic_increment_address@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    143f <program_hex_file+0x27f>
jmp    156c <program_hex_file+0x3ac>
jmp    1548 <program_hex_file+0x388>
mov    $0x1,%edi
lea    0xab7(%rip),%rsi
mov    $0x2b9,%edx
lea    0xbbf(%rip),%rcx
mov    $0x0,%al
call   10b0 <fatal_@plt>
jmp    156c <program_hex_file+0x3ac>
jmp    1571 <program_hex_file+0x3b1>
jmp    1576 <program_hex_file+0x3b6>
mov    -0x10(%rbp),%rdi
lea    0xbb0(%rip),%rsi
mov    $0x0,%al
call   1090 <fscanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     15c5 <program_hex_file+0x405>
jmp    15a3 <program_hex_file+0x3e3>
mov    $0x1,%edi
lea    0xa5c(%rip),%rsi
mov    $0x2be,%edx
lea    0xad6(%rip),%rcx
call   1060 <fatal_e_@plt>
jmp    15c5 <program_hex_file+0x405>
mov    -0x24(%rbp),%eax
mov    0x2a19(%rip),%rcx
cmp    (%rcx),%eax
jne    1600 <program_hex_file+0x440>
jmp    15dc <program_hex_file+0x41c>
mov    $0x1,%edi
lea    0xa23(%rip),%rsi
mov    $0x2c0,%edx
lea    0xb43(%rip),%rcx
mov    $0x0,%al
call   10b0 <fatal_@plt>
jmp    1600 <program_hex_file+0x440>
jmp    1209 <program_hex_file+0x49>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<program_hex_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x18(%rsp)
mov    %rdi,%r13
call   1070 <pic_enter_LVP@plt>
mov    %r13,%rdi
call   10a0 <pic_load_configuration@plt>
mov    %r13,%rdi
call   10d0 <pic_bulk_erase@plt>
mov    %r13,%rdi
call   10e0 <pic_reset_address@plt>
lea    0xe06(%rip),%r15
lea    0x8(%rsp),%r12
movl   $0x0,0xc(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
lea    0x14(%rsp),%rcx
lea    0x24(%rsp),%r8
xor    %eax,%eax
call   1090 <fscanf@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     125c <program_hex_file+0x9c>
mov    $0x1,%edi
lea    0xdc0(%rip),%rsi
mov    $0x288,%edx
lea    0xe3a(%rip),%rcx
call   1060 <fatal_e_@plt>
cmp    $0x3,%r14d
jl     126e <program_hex_file+0xae>
mov    0x2d7f(%rip),%rax
cmp    (%rax),%r14d
jne    1293 <program_hex_file+0xd3>
mov    $0x1,%edi
lea    0xd91(%rip),%rsi
mov    $0x28a,%edx
lea    0xe24(%rip),%rcx
mov    $0x1,%r8d
xor    %eax,%eax
call   10b0 <fatal_@plt>
shrl   0x8(%rsp)
mov    0x14(%rsp),%eax
shr    %eax
mov    %eax,0x14(%rsp)
mov    0x24(%rsp),%ecx
test   %ecx,%ecx
je     12e0 <program_hex_file+0x120>
cmp    $0x4,%ecx
je     1320 <program_hex_file+0x160>
cmp    $0x1,%ecx
je     1586 <program_hex_file+0x3c6>
mov    $0x1,%edi
lea    0xd48(%rip),%rsi
mov    $0x2b9,%edx
lea    0xe50(%rip),%rcx
xor    %eax,%eax
call   10b0 <fatal_@plt>
jmp    150f <program_hex_file+0x34f>
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%ebp
and    $0xffff8000,%ebp
or     %eax,%ebp
cmp    $0x8000,%ebx
jae    13ae <program_hex_file+0x1ee>
cmp    $0x8000,%ebp
jae    13ba <program_hex_file+0x1fa>
cmp    %ebp,%ebx
ja     13d1 <program_hex_file+0x211>
jmp    13db <program_hex_file+0x21b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
lea    0xda9(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1090 <fscanf@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1368 <program_hex_file+0x1a8>
mov    $0x1,%edi
lea    0xcb4(%rip),%rsi
mov    $0x296,%edx
lea    0xd2e(%rip),%rcx
call   1060 <fatal_e_@plt>
test   %r14d,%r14d
jle    1379 <program_hex_file+0x1b9>
mov    0x2c74(%rip),%rax
cmp    (%rax),%r14d
jne    139e <program_hex_file+0x1de>
mov    $0x1,%edi
lea    0xc86(%rip),%rsi
mov    $0x298,%edx
lea    0xd4b(%rip),%rcx
mov    $0x1,%r8d
xor    %eax,%eax
call   10b0 <fatal_@plt>
mov    0x10(%rsp),%eax
shl    $0xf,%eax
mov    %eax,0xc(%rsp)
jmp    150f <program_hex_file+0x34f>
cmp    %ebp,%ebx
jbe    13c9 <program_hex_file+0x209>
cmp    $0x7fff,%ebp
jbe    13c9 <program_hex_file+0x209>
mov    %r13,%rdi
call   10a0 <pic_load_configuration@plt>
mov    $0x8000,%ebx
jmp    13db <program_hex_file+0x21b>
cmp    $0x7fff,%ebp
ja     13db <program_hex_file+0x21b>
mov    %r13,%rdi
call   10e0 <pic_reset_address@plt>
xor    %ebx,%ebx
cmp    %ebp,%ebx
jae    13ff <program_hex_file+0x23f>
mov    %rbx,%rax
mov    %ebp,%ebx
sub    %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   10c0 <pic_increment_address@plt>
add    $0xffffffff,%ebx
jne    13f0 <program_hex_file+0x230>
mov    %ebp,%ebx
cmpl   $0x0,0x8(%rsp)
mov    %ebp,0xc(%rsp)
je     150f <program_hex_file+0x34f>
xor    %r15d,%r15d
jmp    1484 <program_hex_file+0x2c4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
lea    0xbdf(%rip),%rsi
mov    $0x2b0,%edx
lea    0xcc6(%rip),%rcx
xor    %eax,%eax
call   10b0 <fatal_@plt>
mov    0x20(%rsp),%ebx
shl    $0x8,%ebx
add    0x10(%rsp),%ebx
mov    %r13,%rdi
mov    %ebx,%esi
call   1040 <pic_load_data@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1050 <pic_int_program@plt>
lea    0xca7(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1080 <printf@plt>
mov    %r13,%rdi
call   10c0 <pic_increment_address@plt>
add    $0x1,%r15d
cmp    0x8(%rsp),%r15d
mov    %r14,%rbx
jae    1500 <program_hex_file+0x340>
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
lea    0xc64(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
xor    %eax,%eax
call   1090 <fscanf@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     14d1 <program_hex_file+0x311>
mov    $0x1,%edi
lea    0xb4b(%rip),%rsi
mov    $0x2ae,%edx
lea    0xbc5(%rip),%rcx
call   1060 <fatal_e_@plt>
mov    %rbx,%r14
lea    (%rbx,%r15,1),%ebp
cmp    $0x2,%r12d
jl     1420 <program_hex_file+0x260>
mov    0x2aff(%rip),%rax
cmp    (%rax),%r12d
jne    143f <program_hex_file+0x27f>
jmp    1420 <program_hex_file+0x260>
nopw   0x0(%rax,%rax,1)
add    %r15d,%ebx
lea    0xaf6(%rip),%r15
lea    0x8(%rsp),%r12
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
lea    0xc13(%rip),%rsi
xor    %eax,%eax
call   1090 <fscanf@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1552 <program_hex_file+0x392>
mov    $0x1,%edi
lea    0xaca(%rip),%rsi
mov    $0x2be,%edx
lea    0xb44(%rip),%rcx
call   1060 <fatal_e_@plt>
mov    0x2a8f(%rip),%rax
cmp    (%rax),%r14d
jne    1210 <program_hex_file+0x50>
mov    $0x1,%edi
lea    0xa9d(%rip),%rsi
mov    $0x2c0,%edx
lea    0xbbd(%rip),%rcx
xor    %eax,%eax
call   10b0 <fatal_@plt>
jmp    1210 <program_hex_file+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dev = type { i32 }
@.str = [11 x i8] c":%2x%4x%2x\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/heads/master/pickler.c\00"
@.str.2 = [25 x i8] c"Can't read from hex file\00"
@EOF = global i32 0
@.str.3 = [46 x i8] c"%d: Expected colon, length, address, and type\00"
@.str.4 = [4 x i8] c"%4x\00"
@.str.5 = [27 x i8] c"%d: Expected upper address\00"
@.str.6 = [7 x i8] c"%2x%2x\00"
@.str.7 = [14 x i8] c"Expected word\00"
@.str.8 = [19 x i8] c"[0x%04X] = 0x%04X\0A\00"
@.str.9 = [18 x i8] c"Unrecognized type\00"
@.str.10 = [6 x i8] c"%*2x\0A\00"
@.str.11 = [30 x i8] c"Expected checksum and newline\00"
define void @program_hex_file(%struct.dev* %0, i32* %1) {
%3 = alloca %struct.dev*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store %struct.dev* %0, %struct.dev** %3
store i32* %1, i32** %4
%17 = load %struct.dev*, %struct.dev** %3
%18 = call i32 @pic_enter_LVP(%struct.dev* %17)
%19 = load %struct.dev*, %struct.dev** %3
%20 = call i32 @pic_load_configuration(%struct.dev* %19)
%21 = load %struct.dev*, %struct.dev** %3
%22 = call i32 @pic_bulk_erase(%struct.dev* %21)
%23 = load %struct.dev*, %struct.dev** %3
%24 = call i32 @pic_reset_address(%struct.dev* %23)
store i32 1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %8
br label %25
25: ; preds = %2, %198
%26 = load i32*, i32** %4
%27 = call i32 (i32*, i8*, ...) @fscanf(i32* %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %7, i32* %10, i32* %11)
store i32 %27, i32* %9
%28 = load i32*, i32** %4
%29 = call i64 @ferror(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = call i32 @fatal_e_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 648, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32
br label %35
35: ; preds = %34, %25
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 3
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load i32, i32* %9
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %47
42: ; preds = %38, %35
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 650, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %43
br label %47
47: ; preds = %46, %38
%48 = load i32, i32* %7
%49 = udiv i32 %48, 2
store i32 %49, i32* %7
%50 = load i32, i32* %10
%51 = udiv i32 %50, 2
store i32 %51, i32* %10
%52 = load i32, i32* %11
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %55
54: ; preds = %47
br label %199
55: ; preds = %47
%56 = load i32, i32* %11
%57 = icmp eq i32 %56, 4
br i1 %57, label %58, label %83
58: ; preds = %55
%59 = load i32*, i32** %4
%60 = call i32 (i32*, i8*, ...) @fscanf(i32* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %12)
store i32 %60, i32* %9
%61 = load i32*, i32** %4
%62 = call i64 @ferror(i32* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %58
br label %65
65: ; preds = %64
%66 = call i32 @fatal_e_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 662, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %67
67: ; preds = %65
br label %68
68: ; preds = %67, %58
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 1
br i1 %70, label %75, label %71
71: ; preds = %68
%72 = load i32, i32* %9
%73 = load i32, i32* @EOF
%74 = icmp eq i32 %72, %73
br i1 %74, label %75, label %80
75: ; preds = %71, %68
br label %76
76: ; preds = %75
%77 = load i32, i32* %5
%78 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 664, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %77)
br label %79
79: ; preds = %76
br label %80
80: ; preds = %79, %71
%81 = load i32, i32* %12
%82 = shl i32 %81, 15
store i32 %82, i32* %8
br label %179
83: ; preds = %55
%84 = load i32, i32* %11
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %174
86: ; preds = %83
%87 = load i32, i32* %8
%88 = and i32 %87, -32768
%89 = load i32, i32* %10
%90 = or i32 %88, %89
store i32 %90, i32* %8
%91 = load i32, i32* %6
%92 = icmp ult i32 %91, 32768
br i1 %92, label %97, label %93
93: ; preds = %86
%94 = load i32, i32* %6
%95 = load i32, i32* %8
%96 = icmp ugt i32 %94, %95
br i1 %96, label %97, label %103
97: ; preds = %93, %86
%98 = load i32, i32* %8
%99 = icmp uge i32 %98, 32768
br i1 %99, label %100, label %103
100: ; preds = %97
%101 = load %struct.dev*, %struct.dev** %3
%102 = call i32 @pic_load_configuration(%struct.dev* %101)
store i32 32768, i32* %6
br label %117
103: ; preds = %97, %93
%104 = load i32, i32* %6
%105 = icmp uge i32 %104, 32768
br i1 %105, label %110, label %106
106: ; preds = %103
%107 = load i32, i32* %6
%108 = load i32, i32* %8
%109 = icmp ugt i32 %107, %108
br i1 %109, label %110, label %116
110: ; preds = %106, %103
%111 = load i32, i32* %8
%112 = icmp ult i32 %111, 32768
br i1 %112, label %113, label %116
113: ; preds = %110
%114 = load %struct.dev*, %struct.dev** %3
%115 = call i32 @pic_reset_address(%struct.dev* %114)
store i32 0, i32* %6
br label %116
116: ; preds = %113, %110, %106
br label %117
117: ; preds = %116, %100
br label %118
118: ; preds = %122, %117
%119 = load i32, i32* %6
%120 = load i32, i32* %8
%121 = icmp ult i32 %119, %120
br i1 %121, label %122, label %127
122: ; preds = %118
%123 = load %struct.dev*, %struct.dev** %3
%124 = call i32 @pic_increment_address(%struct.dev* %123)
%125 = load i32, i32* %6
%126 = add i32 %125, 1
store i32 %126, i32* %6
br label %118
127: ; preds = %118
store i32 0, i32* %13
br label %128
128: ; preds = %170, %127
%129 = load i32, i32* %13
%130 = load i32, i32* %7
%131 = icmp ult i32 %129, %130
br i1 %131, label %132, label %173
132: ; preds = %128
%133 = load i32*, i32** %4
%134 = call i32 (i32*, i8*, ...) @fscanf(i32* %133, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %14, i32* %15)
store i32 %134, i32* %9
%135 = load i32*, i32** %4
%136 = call i64 @ferror(i32* %135)
%137 = icmp ne i64 %136, 0
br i1 %137, label %138, label %142
138: ; preds = %132
br label %139
139: ; preds = %138
%140 = call i32 @fatal_e_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 686, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %141
141: ; preds = %139
br label %142
142: ; preds = %141, %132
%143 = load i32, i32* %9
%144 = icmp slt i32 %143, 2
br i1 %144, label %149, label %145
145: ; preds = %142
%146 = load i32, i32* %9
%147 = load i32, i32* @EOF
%148 = icmp eq i32 %146, %147
br i1 %148, label %149, label %153
149: ; preds = %145, %142
br label %150
150: ; preds = %149
%151 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 688, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %152
152: ; preds = %150
br label %153
153: ; preds = %152, %145
%154 = load i32, i32* %14
%155 = load i32, i32* %15
%156 = shl i32 %155, 8
%157 = add i32 %154, %156
store i32 %157, i32* %16
%158 = load %struct.dev*, %struct.dev** %3
%159 = load i32, i32* %16
%160 = call i32 @pic_load_data(%struct.dev* %158, i32 %159)
%161 = load %struct.dev*, %struct.dev** %3
%162 = call i32 @pic_int_program(%struct.dev* %161, i32 0)
%163 = load i32, i32* %6
%164 = load i32, i32* %16
%165 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %163, i32 %164)
%166 = load %struct.dev*, %struct.dev** %3
%167 = call i32 @pic_increment_address(%struct.dev* %166)
%168 = load i32, i32* %6
%169 = add i32 %168, 1
store i32 %169, i32* %6
br label %170
170: ; preds = %153
%171 = load i32, i32* %13
%172 = add i32 %171, 1
store i32 %172, i32* %13
br label %128
173: ; preds = %128
br label %178
174: ; preds = %83
br label %175
175: ; preds = %174
%176 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 697, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
br label %177
177: ; preds = %175
br label %178
178: ; preds = %177, %173
br label %179
179: ; preds = %178, %80
br label %180
180: ; preds = %179
%181 = load i32*, i32** %4
%182 = call i32 (i32*, i8*, ...) @fscanf(i32* %181, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
store i32 %182, i32* %9
%183 = load i32*, i32** %4
%184 = call i64 @ferror(i32* %183)
%185 = icmp ne i64 %184, 0
br i1 %185, label %186, label %190
186: ; preds = %180
br label %187
187: ; preds = %186
%188 = call i32 @fatal_e_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 702, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %189
189: ; preds = %187
br label %190
190: ; preds = %189, %180
%191 = load i32, i32* %9
%192 = load i32, i32* @EOF
%193 = icmp eq i32 %191, %192
br i1 %193, label %194, label %198
194: ; preds = %190
br label %195
195: ; preds = %194
%196 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 704, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
br label %197
197: ; preds = %195
br label %198
198: ; preds = %197, %190
br label %25
199: ; preds = %54
ret void
}

LLVM IR (-O2):
%struct.dev = type { i32 }
@.str = [11 x i8] c":%2x%4x%2x\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drkitty/pickler/refs/heads/master/pickler.c\00"
@.str.2 = [25 x i8] c"Can't read from hex file\00"
@EOF = global i32 0
@.str.3 = [46 x i8] c"%d: Expected colon, length, address, and type\00"
@.str.4 = [4 x i8] c"%4x\00"
@.str.5 = [27 x i8] c"%d: Expected upper address\00"
@.str.6 = [7 x i8] c"%2x%2x\00"
@.str.7 = [14 x i8] c"Expected word\00"
@.str.8 = [19 x i8] c"[0x%04X] = 0x%04X\0A\00"
@.str.9 = [18 x i8] c"Unrecognized type\00"
@.str.10 = [6 x i8] c"%*2x\0A\00"
@.str.11 = [30 x i8] c"Expected checksum and newline\00"
define void @program_hex_file(%struct.dev* %0, i32* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = tail call i32 @pic_enter_LVP(%struct.dev* %0)
%10 = tail call i32 @pic_load_configuration(%struct.dev* %0)
%11 = tail call i32 @pic_bulk_erase(%struct.dev* %0)
%12 = tail call i32 @pic_reset_address(%struct.dev* %0)
%13 = bitcast i32* %3 to i8*
%14 = bitcast i32* %4 to i8*
%15 = bitcast i32* %5 to i8*
%16 = bitcast i32* %7 to i8*
%17 = bitcast i32* %8 to i8*
%18 = bitcast i32* %6 to i8*
br label %19
19: ; preds = %129, %2
%20 = phi i32 [ 0, %2 ], [ %117, %129 ]
%21 = phi i32 [ 0, %2 ], [ %118, %129 ]
%22 = call i32 (i32*, i8*, ...) @fscanf(i32* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%23 = call i64 @ferror(i32* %1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = call i32 @fatal_e_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 648, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = icmp slt i32 %22, 3
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %22, %29
%31 = select i1 %28, i1 true, i1 %30
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 650, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 1)
br label %34
34: ; preds = %27, %32
%35 = load i32, i32* %3
%36 = lshr i32 %35, 1
store i32 %36, i32* %3
%37 = load i32, i32* %4
%38 = lshr i32 %37, 1
store i32 %38, i32* %4
%39 = load i32, i32* %5
switch i32 %39, label %114 [
i32 1, label %130
i32 4, label %40
i32 0, label %56
]
40: ; preds = %34
%41 = call i32 (i32*, i8*, ...) @fscanf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%42 = call i64 @ferror(i32* %1)
%43 = icmp eq i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = call i32 @fatal_e_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 662, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = icmp slt i32 %41, 1
%48 = load i32, i32* @EOF
%49 = icmp eq i32 %41, %48
%50 = select i1 %47, i1 true, i1 %49
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 664, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 1)
br label %53
53: ; preds = %46, %51
%54 = load i32, i32* %6
%55 = shl i32 %54, 15
br label %116
56: ; preds = %34
%57 = and i32 %20, -32768
%58 = or i32 %38, %57
%59 = icmp ult i32 %21, 32768
br i1 %59, label %64, label %60
60: ; preds = %56
%61 = icmp ugt i32 %21, %58
%62 = icmp ugt i32 %58, 32767
%63 = and i1 %61, %62
br i1 %63, label %66, label %70
64: ; preds = %56
%65 = icmp ugt i32 %58, 32767
br i1 %65, label %66, label %68
66: ; preds = %60, %64
%67 = call i32 @pic_load_configuration(%struct.dev* %0)
br label %74
68: ; preds = %64
%69 = icmp ugt i32 %21, %58
br i1 %69, label %72, label %74
70: ; preds = %60
%71 = icmp ult i32 %58, 32768
br i1 %71, label %72, label %74
72: ; preds = %68, %70
%73 = call i32 @pic_reset_address(%struct.dev* %0)
br label %74
74: ; preds = %68, %70, %72, %66
%75 = phi i32 [ 32768, %66 ], [ 0, %72 ], [ %21, %70 ], [ %21, %68 ]
%76 = icmp ult i32 %75, %58
br i1 %76, label %81, label %77
77: ; preds = %81, %74
%78 = phi i32 [ %75, %74 ], [ %58, %81 ]
%79 = load i32, i32* %3
%80 = icmp eq i32 %79, 0
br i1 %80, label %116, label %86
81: ; preds = %74, %81
%82 = phi i32 [ %84, %81 ], [ %75, %74 ]
%83 = call i32 @pic_increment_address(%struct.dev* %0)
%84 = add i32 %82, 1
%85 = icmp eq i32 %84, %58
br i1 %85, label %77, label %81
86: ; preds = %77, %101
%87 = phi i32 [ %110, %101 ], [ %78, %77 ]
%88 = phi i32 [ %111, %101 ], [ 0, %77 ]
%89 = call i32 (i32*, i8*, ...) @fscanf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %7, i32* %8)
%90 = call i64 @ferror(i32* %1)
%91 = icmp eq i64 %90, 0
br i1 %91, label %94, label %92
92: ; preds = %86
%93 = call i32 @fatal_e_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 686, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %94
94: ; preds = %92, %86
%95 = icmp slt i32 %89, 2
%96 = load i32, i32* @EOF
%97 = icmp eq i32 %89, %96
%98 = select i1 %95, i1 true, i1 %97
br i1 %98, label %99, label %101
99: ; preds = %94
%100 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 688, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %101
101: ; preds = %94, %99
%102 = load i32, i32* %7
%103 = load i32, i32* %8
%104 = shl i32 %103, 8
%105 = add i32 %104, %102
%106 = call i32 @pic_load_data(%struct.dev* %0, i32 %105)
%107 = call i32 @pic_int_program(%struct.dev* %0, i32 0)
%108 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %87, i32 %105)
%109 = call i32 @pic_increment_address(%struct.dev* %0)
%110 = add i32 %87, 1
%111 = add nuw i32 %88, 1
%112 = load i32, i32* %3
%113 = icmp ult i32 %111, %112
br i1 %113, label %86, label %116
114: ; preds = %34
%115 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 697, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
br label %116
116: ; preds = %101, %77, %53, %114
%117 = phi i32 [ %55, %53 ], [ %20, %114 ], [ %58, %77 ], [ %58, %101 ]
%118 = phi i32 [ %21, %53 ], [ %21, %114 ], [ %78, %77 ], [ %110, %101 ]
%119 = call i32 (i32*, i8*, ...) @fscanf(i32* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%120 = call i64 @ferror(i32* %1)
%121 = icmp eq i64 %120, 0
br i1 %121, label %124, label %122
122: ; preds = %116
%123 = call i32 @fatal_e_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 702, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %124
124: ; preds = %122, %116
%125 = load i32, i32* @EOF
%126 = icmp eq i32 %119, %125
br i1 %126, label %127, label %129
127: ; preds = %124
%128 = call i32 (i32, i8*, i32, i8*, ...) @fatal_(i32 1, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 704, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
br label %129
129: ; preds = %124, %127
br label %19
130: ; preds = %34
ret void
}