#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 */

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *get_modelname(unsigned int);
scalar_t__ get_modelnum(unsigned int);
int /*<<< orphan*/ int2be(unsigned int, unsigned char *);
unsigned int le2int(unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, unsigned char *, unsigned int);
void dump_app(char *name, unsigned char *p, unsigned char *flash) {
  char filename[64];
  unsigned char header[8];
  unsigned int i;
  unsigned int sum;
  int outfile;
  unsigned int unknown1;
  unsigned int offset;
  unsigned int length;
  unsigned int loadaddr;
  unsigned int unknown2;
  unsigned int checksum;
  unsigned int version;
  unsigned int unknown3;
  char *modelname;
  unknown1 = le2int(p + 0x08);
  offset = le2int(p + 0x0c);
  length = le2int(p + 0x10);
  loadaddr = le2int(p + 0x14);
  unknown2 = le2int(p + 0x18);
  checksum = le2int(p + 0x1c);
  version = le2int(p + 0x20);
  unknown3 = le2int(p + 0x24);
  modelname = get_modelname(version);
  sum = 0;
  for (i = offset; i < offset + length; i++) {
    sum += flash[i];
  }
  printf("Image: %s\n", name);
  printf("unknown1: %08x\n", unknown1);
  printf("offset:   %08x\n", offset);
  printf("length:   %08x\n", length);
  printf("loadaddr: %08x\n", loadaddr);
  printf("unknown2: %08x\n", unknown2);
  printf("checksum: %08x  (flashsplit sum: %08x)\n", checksum, sum);
  printf("version:  %08x  (ipod model: %s)\n", version, modelname);
  printf("unknown3: %08x\n", unknown3);
  printf("\n");
  if (modelname == NULL) {
    printf("Unknown version, not exporting to .ipod file\n");
    return;
  } else if (checksum != sum) {
    printf("Checksum mismatch, not exporting to .ipod file\n");
  } else {
    sum += get_modelnum(version);
    int2be(sum, header);
    memcpy(header + 4, modelname, 4);
    sprintf(filename, "%s.ipod", name);
    outfile = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0666);
    if (outfile < 0) {
      fprintf(stderr, "[ERR]  Couldn't open file %s\n", filename);
      return;
    }
    write(outfile, header, 8);
    write(outfile, flash + offset, length);
    close(outfile);
  }
  sprintf(filename, "%s.bin", name);
  outfile = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0666);
  if (outfile < 0) {
    fprintf(stderr, "[ERR]  Couldn't open file %s\n", filename);
    return;
  }
  write(outfile, flash + offset, length);
  close(outfile);
}


x86 assembly (clang, -O0):
<dump_app>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1090 <le2int@plt>
mov    %eax,-0x78(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xc,%rdi
call   1090 <le2int@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
call   1090 <le2int@plt>
mov    %eax,-0x80(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x14,%rdi
call   1090 <le2int@plt>
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x18,%rdi
call   1090 <le2int@plt>
mov    %eax,-0x88(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1c,%rdi
call   1090 <le2int@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x20,%rdi
call   1090 <le2int@plt>
mov    %eax,-0x90(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x24,%rdi
call   1090 <le2int@plt>
mov    %eax,-0x94(%rbp)
mov    -0x90(%rbp),%edi
call   10c0 <get_modelname@plt>
mov    %rax,-0xa0(%rbp)
movl   $0x0,-0x70(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    -0x7c(%rbp),%ecx
add    -0x80(%rbp),%ecx
cmp    %ecx,%eax
jae    12a5 <dump_app+0xf5>
mov    -0x18(%rbp),%rax
mov    -0x6c(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
add    -0x70(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1275 <dump_app+0xc5>
mov    -0x8(%rbp),%rsi
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%esi
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x7c(%rbp),%esi
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x80(%rbp),%esi
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x84(%rbp),%esi
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x88(%rbp),%esi
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8c(%rbp),%esi
mov    -0x70(%rbp),%edx
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x90(%rbp),%esi
mov    -0xa0(%rbp),%rdx
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x94(%rbp),%esi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0xa0(%rbp)
jne    1387 <dump_app+0x1d7>
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1505 <dump_app+0x355>
mov    -0x8c(%rbp),%eax
cmp    -0x70(%rbp),%eax
je     13a9 <dump_app+0x1f9>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    147b <dump_app+0x2cb>
mov    -0x90(%rbp),%edi
call   1050 <get_modelnum@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%edi
lea    -0x68(%rbp),%rsi
call   10a0 <int2be@plt>
lea    -0x68(%rbp),%rdi
add    $0x4,%rdi
mov    -0xa0(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd1f(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2bf4(%rip),%rax
mov    (%rax),%esi
mov    0x2be3(%rip),%rax
or     (%rax),%esi
mov    0x2baa(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10b0 <open@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    144d <dump_app+0x29d>
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xcd8(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1505 <dump_app+0x355>
mov    -0x74(%rbp),%edi
lea    -0x68(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x74(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x7c(%rbp),%eax
add    %rax,%rsi
mov    -0x80(%rbp),%edx
call   1030 <write@plt>
mov    -0x74(%rbp),%edi
call   1060 <close@plt>
jmp    1480 <dump_app+0x2d0>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xcaa(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2b59(%rip),%rax
mov    (%rax),%esi
mov    0x2b48(%rip),%rax
or     (%rax),%esi
mov    0x2b0f(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10b0 <open@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    14e8 <dump_app+0x338>
mov    0x2aff(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xc3d(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1505 <dump_app+0x355>
mov    -0x74(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x7c(%rbp),%eax
add    %rax,%rsi
mov    -0x80(%rbp),%edx
call   1030 <write@plt>
mov    -0x74(%rbp),%edi
call   1060 <close@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_app>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,0x28(%rsp)
lea    0x8(%rsi),%rdi
call   10b0 <le2int@plt>
mov    %eax,0x18(%rsp)
lea    0xc(%rbp),%rdi
call   10b0 <le2int@plt>
mov    %eax,%r13d
lea    0x10(%rbp),%rdi
call   10b0 <le2int@plt>
mov    %eax,%r14d
lea    0x14(%rbp),%rdi
call   10b0 <le2int@plt>
mov    %eax,0x14(%rsp)
lea    0x18(%rbp),%rdi
call   10b0 <le2int@plt>
mov    %eax,0x10(%rsp)
lea    0x1c(%rbp),%rdi
call   10b0 <le2int@plt>
mov    %eax,%r12d
lea    0x20(%rbp),%rdi
call   10b0 <le2int@plt>
mov    %eax,%ebx
add    $0x24,%rbp
mov    %rbp,%rdi
call   10b0 <le2int@plt>
mov    %eax,0x1c(%rsp)
mov    %ebx,0xc(%rsp)
mov    %ebx,%edi
call   10e0 <get_modelname@plt>
mov    %rax,%rbp
mov    %r14d,0x8(%rsp)
mov    %r14d,%ecx
add    %r13d,%ecx
xor    %r14d,%r14d
cmp    %ecx,%r13d
jae    13a1 <dump_app+0x1d1>
mov    %r13d,%eax
mov    %ecx,%ecx
mov    %rcx,%rdx
sub    %rax,%rdx
xor    %r14d,%r14d
cmp    $0x8,%rdx
jb     1390 <dump_app+0x1c0>
mov    %rbp,%rbx
mov    %rdx,%r8
and    $0xfffffffffffffff8,%r8
lea    -0x8(%r8),%rsi
mov    %rsi,%r9
shr    $0x3,%r9
add    $0x1,%r9
test   %rsi,%rsi
je     1324 <dump_app+0x154>
mov    %r9,%rdi
and    $0xfffffffffffffffe,%rdi
lea    (%rax,%r15,1),%rbp
add    $0xc,%rbp
pxor   %xmm2,%xmm2
xor    %esi,%esi
pxor   %xmm0,%xmm0
pxor   %xmm1,%xmm1
nopw   0x0(%rax,%rax,1)
movd   -0xc(%rbp,%rsi,1),%xmm3
movd   -0x8(%rbp,%rsi,1),%xmm4
punpcklbw %xmm2,%xmm3
punpcklwd %xmm2,%xmm3
paddd  %xmm0,%xmm3
punpcklbw %xmm2,%xmm4
punpcklwd %xmm2,%xmm4
paddd  %xmm1,%xmm4
movd   -0x4(%rbp,%rsi,1),%xmm0
movd   0x0(%rbp,%rsi,1),%xmm1
punpcklbw %xmm2,%xmm0
punpcklwd %xmm2,%xmm0
paddd  %xmm3,%xmm0
punpcklbw %xmm2,%xmm1
punpcklwd %xmm2,%xmm1
paddd  %xmm4,%xmm1
add    $0x10,%rsi
add    $0xfffffffffffffffe,%rdi
jne    12d0 <dump_app+0x100>
jmp    132e <dump_app+0x15e>
pxor   %xmm0,%xmm0
xor    %esi,%esi
pxor   %xmm1,%xmm1
test   $0x1,%r9b
mov    %rbx,%rbp
je     1363 <dump_app+0x193>
add    %rax,%rsi
movd   (%r15,%rsi,1),%xmm2
movd   0x4(%r15,%rsi,1),%xmm3
pxor   %xmm4,%xmm4
punpcklbw %xmm4,%xmm2
punpcklwd %xmm4,%xmm2
paddd  %xmm2,%xmm0
punpcklbw %xmm4,%xmm3
punpcklwd %xmm4,%xmm3
paddd  %xmm3,%xmm1
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%r14d
cmp    %r8,%rdx
je     13a1 <dump_app+0x1d1>
add    %r8,%rax
cs nopw 0x0(%rax,%rax,1)
movzbl (%r15,%rax,1),%edx
add    %edx,%r14d
add    $0x1,%rax
cmp    %rax,%rcx
jne    1390 <dump_app+0x1c0>
lea    0xc58(%rip),%rdi
mov    0x28(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc4d(%rip),%rdi
mov    0x18(%rsp),%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc4b(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc4a(%rip),%rdi
mov    0x8(%rsp),%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc48(%rip),%rdi
mov    0x14(%rsp),%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc46(%rip),%rdi
mov    0x10(%rsp),%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc44(%rip),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc58(%rip),%rdi
mov    0xc(%rsp),%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc65(%rip),%rdi
mov    0x1c(%rsp),%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %rbp,%rbp
je     1506 <dump_app+0x336>
cmp    %r14d,%r12d
jne    1520 <dump_app+0x350>
mov    0xc(%rsp),%edi
call   1070 <get_modelnum@plt>
add    %eax,%r12d
lea    0x20(%rsp),%rsi
mov    %r12d,%edi
call   10c0 <int2be@plt>
lea    0x24(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   10a0 <memcpy@plt>
lea    0xc1c(%rip),%rsi
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10f0 <sprintf@plt>
mov    0x2b48(%rip),%rax
mov    0x2b39(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2afe(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
mov    $0x1b6,%edx
call   10d0 <open@plt>
test   %eax,%eax
js     158e <dump_app+0x3be>
mov    %eax,%ebp
lea    0x20(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1050 <write@plt>
mov    %r13d,%esi
add    %r15,%rsi
mov    %ebp,%edi
mov    0x8(%rsp),%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    152c <dump_app+0x35c>
lea    0xc04(%rip),%rdi
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xbbb(%rip),%rdi
call   1040 <puts@plt>
lea    0xba8(%rip),%rsi
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10f0 <sprintf@plt>
mov    0x2aae(%rip),%rax
mov    0x2a9f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2a64(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
mov    $0x1b6,%edx
call   10d0 <open@plt>
test   %eax,%eax
js     158e <dump_app+0x3be>
mov    %eax,%ebp
mov    %r13d,%eax
add    %rax,%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    0x8(%rsp),%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    15a8 <dump_app+0x3d8>
mov    0x2a3b(%rip),%rax
mov    (%rax),%edi
lea    0xb1f(%rip),%rsi
lea    0x30(%rsp),%rdx
call   1090 <fprintf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Image: %s\0A\00"
@.str.1 = [16 x i8] c"unknown1: %08x\0A\00"
@.str.2 = [16 x i8] c"offset: %08x\0A\00"
@.str.3 = [16 x i8] c"length: %08x\0A\00"
@.str.4 = [16 x i8] c"loadaddr: %08x\0A\00"
@.str.5 = [16 x i8] c"unknown2: %08x\0A\00"
@.str.6 = [40 x i8] c"checksum: %08x (flashsplit sum: %08x)\0A\00"
@.str.7 = [34 x i8] c"version: %08x (ipod model: %s)\0A\00"
@.str.8 = [16 x i8] c"unknown3: %08x\0A\00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [46 x i8] c"Unknown version, not exporting to .ipod file\0A\00"
@.str.11 = [48 x i8] c"Checksum mismatch, not exporting to .ipod file\0A\00"
@.str.12 = [8 x i8] c"%s.ipod\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.13 = [30 x i8] c"[ERR] Couldn't open file %s\0A\00"
@.str.14 = [7 x i8] c"%s.bin\00"
define void @dump_app(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [64 x i8]
%8 = alloca [8 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 8
%23 = call i32 @le2int(i8* %22)
store i32 %23, i32* %12
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 12
%26 = call i32 @le2int(i8* %25)
store i32 %26, i32* %13
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 16
%29 = call i32 @le2int(i8* %28)
store i32 %29, i32* %14
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 20
%32 = call i32 @le2int(i8* %31)
store i32 %32, i32* %15
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 24
%35 = call i32 @le2int(i8* %34)
store i32 %35, i32* %16
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 28
%38 = call i32 @le2int(i8* %37)
store i32 %38, i32* %17
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 32
%41 = call i32 @le2int(i8* %40)
store i32 %41, i32* %18
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 36
%44 = call i32 @le2int(i8* %43)
store i32 %44, i32* %19
%45 = load i32, i32* %18
%46 = call i8* @get_modelname(i32 %45)
store i8* %46, i8** %20
store i32 0, i32* %10
%47 = load i32, i32* %13
store i32 %47, i32* %9
br label %48
48: ; preds = %63, %3
%49 = load i32, i32* %9
%50 = load i32, i32* %13
%51 = load i32, i32* %14
%52 = add i32 %50, %51
%53 = icmp ult i32 %49, %52
br i1 %53, label %54, label %66
54: ; preds = %48
%55 = load i8*, i8** %6
%56 = load i32, i32* %9
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = load i32, i32* %10
%62 = add i32 %61, %60
store i32 %62, i32* %10
br label %63
63: ; preds = %54
%64 = load i32, i32* %9
%65 = add i32 %64, 1
store i32 %65, i32* %9
br label %48
66: ; preds = %48
%67 = load i8*, i8** %4
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %67)
%69 = load i32, i32* %12
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = load i32, i32* %13
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %14
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %73)
%75 = load i32, i32* %15
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %16
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %77)
%79 = load i32, i32* %17
%80 = load i32, i32* %10
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %79, i32 %80)
%82 = load i32, i32* %18
%83 = load i8*, i8** %20
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i32 %82, i8* %83)
%85 = load i32, i32* %19
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %85)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%88 = load i8*, i8** %20
%89 = icmp eq i8* %88, null
br i1 %89, label %90, label %92
90: ; preds = %66
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0))
br label %169
92: ; preds = %66
%93 = load i32, i32* %17
%94 = load i32, i32* %10
%95 = icmp ne i32 %93, %94
br i1 %95, label %96, label %98
96: ; preds = %92
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.11, i64 0, i64 0))
br label %141
98: ; preds = %92
%99 = load i32, i32* %18
%100 = call i64 @get_modelnum(i32 %99)
%101 = load i32, i32* %10
%102 = zext i32 %101 to i64
%103 = add nsw i64 %102, %100
%104 = trunc i64 %103 to i32
store i32 %104, i32* %10
%105 = load i32, i32* %10
%106 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%107 = call i32 @int2be(i32 %105, i8* %106)
%108 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%109 = getelementptr inbounds i8, i8* %108, i64 4
%110 = load i8*, i8** %20
%111 = call i32 @memcpy(i8* %109, i8* %110, i32 4)
%112 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%113 = load i8*, i8** %4
%114 = call i32 @sprintf(i8* %112, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i8* %113)
%115 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%116 = load i32, i32* @O_CREAT
%117 = load i32, i32* @O_TRUNC
%118 = or i32 %116, %117
%119 = load i32, i32* @O_WRONLY
%120 = or i32 %118, %119
%121 = call i32 @open(i8* %115, i32 %120, i32 438)
store i32 %121, i32* %11
%122 = load i32, i32* %11
%123 = icmp slt i32 %122, 0
br i1 %123, label %124, label %128
124: ; preds = %98
%125 = load i32, i32* @stderr
%126 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%127 = call i32 @fprintf(i32 %125, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0), i8* %126)
br label %169
128: ; preds = %98
%129 = load i32, i32* %11
%130 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%131 = call i32 @write(i32 %129, i8* %130, i32 8)
%132 = load i32, i32* %11
%133 = load i8*, i8** %6
%134 = load i32, i32* %13
%135 = zext i32 %134 to i64
%136 = getelementptr inbounds i8, i8* %133, i64 %135
%137 = load i32, i32* %14
%138 = call i32 @write(i32 %132, i8* %136, i32 %137)
%139 = load i32, i32* %11
%140 = call i32 @close(i32 %139)
br label %141
141: ; preds = %128, %96
br label %142
142: ; preds = %141
%143 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%144 = load i8*, i8** %4
%145 = call i32 @sprintf(i8* %143, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i8* %144)
%146 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%147 = load i32, i32* @O_CREAT
%148 = load i32, i32* @O_TRUNC
%149 = or i32 %147, %148
%150 = load i32, i32* @O_WRONLY
%151 = or i32 %149, %150
%152 = call i32 @open(i8* %146, i32 %151, i32 438)
store i32 %152, i32* %11
%153 = load i32, i32* %11
%154 = icmp slt i32 %153, 0
br i1 %154, label %155, label %159
155: ; preds = %142
%156 = load i32, i32* @stderr
%157 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%158 = call i32 @fprintf(i32 %156, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0), i8* %157)
br label %169
159: ; preds = %142
%160 = load i32, i32* %11
%161 = load i8*, i8** %6
%162 = load i32, i32* %13
%163 = zext i32 %162 to i64
%164 = getelementptr inbounds i8, i8* %161, i64 %163
%165 = load i32, i32* %14
%166 = call i32 @write(i32 %160, i8* %164, i32 %165)
%167 = load i32, i32* %11
%168 = call i32 @close(i32 %167)
br label %169
169: ; preds = %159, %155, %124, %90
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"Image: %s\0A\00"
@.str.1 = [16 x i8] c"unknown1: %08x\0A\00"
@.str.2 = [16 x i8] c"offset: %08x\0A\00"
@.str.3 = [16 x i8] c"length: %08x\0A\00"
@.str.4 = [16 x i8] c"loadaddr: %08x\0A\00"
@.str.5 = [16 x i8] c"unknown2: %08x\0A\00"
@.str.6 = [40 x i8] c"checksum: %08x (flashsplit sum: %08x)\0A\00"
@.str.7 = [34 x i8] c"version: %08x (ipod model: %s)\0A\00"
@.str.8 = [16 x i8] c"unknown3: %08x\0A\00"
@.str.12 = [8 x i8] c"%s.ipod\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.13 = [30 x i8] c"[ERR] Couldn't open file %s\0A\00"
@.str.14 = [7 x i8] c"%s.bin\00"
@str = [47 x i8] c"Checksum mismatch, not exporting to .ipod file\00"
@str.15 = [45 x i8] c"Unknown version, not exporting to .ipod file\00"
define void @dump_app(i8* %0, i8* %1, i8* nocapture %2) {
%4 = alloca [64 x i8]
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds i8, i8* %1, i64 8
%9 = tail call i32 @le2int(i8* %8)
%10 = getelementptr inbounds i8, i8* %1, i64 12
%11 = tail call i32 @le2int(i8* %10)
%12 = getelementptr inbounds i8, i8* %1, i64 16
%13 = tail call i32 @le2int(i8* %12)
%14 = getelementptr inbounds i8, i8* %1, i64 20
%15 = tail call i32 @le2int(i8* %14)
%16 = getelementptr inbounds i8, i8* %1, i64 24
%17 = tail call i32 @le2int(i8* %16)
%18 = getelementptr inbounds i8, i8* %1, i64 28
%19 = tail call i32 @le2int(i8* %18)
%20 = getelementptr inbounds i8, i8* %1, i64 32
%21 = tail call i32 @le2int(i8* %20)
%22 = getelementptr inbounds i8, i8* %1, i64 36
%23 = tail call i32 @le2int(i8* %22)
%24 = tail call i8* @get_modelname(i32 %21)
%25 = add i32 %13, %11
%26 = icmp ult i32 %11, %25
br i1 %26, label %27, label %110
27: ; preds = %3
%28 = zext i32 %11 to i64
%29 = zext i32 %25 to i64
%30 = sub nsw i64 %29, %28
%31 = icmp ult i64 %30, 8
br i1 %31, label %98, label %32
32: ; preds = %27
%33 = and i64 %30, -8
%34 = add nsw i64 %33, %28
%35 = add nsw i64 %33, -8
%36 = lshr exact i64 %35, 3
%37 = add nuw nsw i64 %36, 1
%38 = and i64 %37, 1
%39 = icmp eq i64 %35, 0
br i1 %39, label %73, label %40
40: ; preds = %32
%41 = and i64 %37, 4611686018427387902
br label %42
42: ; preds = %42, %40
%43 = phi i64 [ 0, %40 ], [ %70, %42 ]
%44 = phi <4 x i32> [ zeroinitializer, %40 ], [ %68, %42 ]
%45 = phi <4 x i32> [ zeroinitializer, %40 ], [ %69, %42 ]
%46 = phi i64 [ 0, %40 ], [ %71, %42 ]
%47 = add i64 %43, %28
%48 = getelementptr inbounds i8, i8* %2, i64 %47
%49 = bitcast i8* %48 to <4 x i8>*
%50 = load <4 x i8>, <4 x i8>* %49
%51 = getelementptr inbounds i8, i8* %48, i64 4
%52 = bitcast i8* %51 to <4 x i8>*
%53 = load <4 x i8>, <4 x i8>* %52
%54 = zext <4 x i8> %50 to <4 x i32>
%55 = zext <4 x i8> %53 to <4 x i32>
%56 = add <4 x i32> %44, %54
%57 = add <4 x i32> %45, %55
%58 = or i64 %43, 8
%59 = add i64 %58, %28
%60 = getelementptr inbounds i8, i8* %2, i64 %59
%61 = bitcast i8* %60 to <4 x i8>*
%62 = load <4 x i8>, <4 x i8>* %61
%63 = getelementptr inbounds i8, i8* %60, i64 4
%64 = bitcast i8* %63 to <4 x i8>*
%65 = load <4 x i8>, <4 x i8>* %64
%66 = zext <4 x i8> %62 to <4 x i32>
%67 = zext <4 x i8> %65 to <4 x i32>
%68 = add <4 x i32> %56, %66
%69 = add <4 x i32> %57, %67
%70 = add nuw i64 %43, 16
%71 = add i64 %46, 2
%72 = icmp eq i64 %71, %41
br i1 %72, label %73, label %42
73: ; preds = %42, %32
%74 = phi <4 x i32> [ undef, %32 ], [ %68, %42 ]
%75 = phi <4 x i32> [ undef, %32 ], [ %69, %42 ]
%76 = phi i64 [ 0, %32 ], [ %70, %42 ]
%77 = phi <4 x i32> [ zeroinitializer, %32 ], [ %68, %42 ]
%78 = phi <4 x i32> [ zeroinitializer, %32 ], [ %69, %42 ]
%79 = icmp eq i64 %38, 0
br i1 %79, label %92, label %80
80: ; preds = %73
%81 = add i64 %76, %28
%82 = getelementptr inbounds i8, i8* %2, i64 %81
%83 = bitcast i8* %82 to <4 x i8>*
%84 = load <4 x i8>, <4 x i8>* %83
%85 = getelementptr inbounds i8, i8* %82, i64 4
%86 = bitcast i8* %85 to <4 x i8>*
%87 = load <4 x i8>, <4 x i8>* %86
%88 = zext <4 x i8> %84 to <4 x i32>
%89 = zext <4 x i8> %87 to <4 x i32>
%90 = add <4 x i32> %77, %88
%91 = add <4 x i32> %78, %89
br label %92
92: ; preds = %73, %80
%93 = phi <4 x i32> [ %74, %73 ], [ %90, %80 ]
%94 = phi <4 x i32> [ %75, %73 ], [ %91, %80 ]
%95 = add <4 x i32> %94, %93
%96 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %95)
%97 = icmp eq i64 %30, %33
br i1 %97, label %110, label %98
98: ; preds = %27, %92
%99 = phi i64 [ %28, %27 ], [ %34, %92 ]
%100 = phi i32 [ 0, %27 ], [ %96, %92 ]
br label %101
101: ; preds = %98, %101
%102 = phi i64 [ %108, %101 ], [ %99, %98 ]
%103 = phi i32 [ %107, %101 ], [ %100, %98 ]
%104 = getelementptr inbounds i8, i8* %2, i64 %102
%105 = load i8, i8* %104
%106 = zext i8 %105 to i32
%107 = add i32 %103, %106
%108 = add nuw nsw i64 %102, 1
%109 = icmp eq i64 %108, %29
br i1 %109, label %110, label %101
110: ; preds = %101, %92, %3
%111 = phi i32 [ 0, %3 ], [ %96, %92 ], [ %107, %101 ]
%112 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%113 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%114 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%115 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%116 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %15)
%117 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%118 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %19, i32 %111)
%119 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i32 %21, i8* %24)
%120 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %23)
%121 = tail call i32 @putchar(i32 10)
%122 = icmp eq i8* %24, null
br i1 %122, label %123, label %125
123: ; preds = %110
%124 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.15, i64 0, i64 0))
br label %170
125: ; preds = %110
%126 = icmp eq i32 %19, %111
br i1 %126, label %129, label %127
127: ; preds = %125
%128 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %153
129: ; preds = %125
%130 = tail call i64 @get_modelnum(i32 %21)
%131 = trunc i64 %130 to i32
%132 = add i32 %19, %131
%133 = call i32 @int2be(i32 %132, i8* %7)
%134 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 4
%135 = call i32 @memcpy(i8* %134, i8* %24, i32 4)
%136 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i8* %0)
%137 = load i32, i32* @O_CREAT
%138 = load i32, i32* @O_TRUNC
%139 = or i32 %138, %137
%140 = load i32, i32* @O_WRONLY
%141 = or i32 %139, %140
%142 = call i32 @open(i8* %6, i32 %141, i32 438)
%143 = icmp slt i32 %142, 0
br i1 %143, label %144, label %147
144: ; preds = %129
%145 = load i32, i32* @stderr
%146 = call i32 @fprintf(i32 %145, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0), i8* %6)
br label %170
147: ; preds = %129
%148 = call i32 @write(i32 %142, i8* %7, i32 8)
%149 = zext i32 %11 to i64
%150 = getelementptr inbounds i8, i8* %2, i64 %149
%151 = call i32 @write(i32 %142, i8* %150, i32 %13)
%152 = call i32 @close(i32 %142)
br label %153
153: ; preds = %127, %147
%154 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i8* %0)
%155 = load i32, i32* @O_CREAT
%156 = load i32, i32* @O_TRUNC
%157 = or i32 %156, %155
%158 = load i32, i32* @O_WRONLY
%159 = or i32 %157, %158
%160 = call i32 @open(i8* %6, i32 %159, i32 438)
%161 = icmp slt i32 %160, 0
br i1 %161, label %162, label %165
162: ; preds = %153
%163 = load i32, i32* @stderr
%164 = call i32 @fprintf(i32 %163, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0), i8* %6)
br label %170
165: ; preds = %153
%166 = zext i32 %11 to i64
%167 = getelementptr inbounds i8, i8* %2, i64 %166
%168 = call i32 @write(i32 %160, i8* %167, i32 %13)
%169 = call i32 @close(i32 %160)
br label %170
170: ; preds = %165, %162, %144, %123
ret void
}