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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ int2le(int, unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ short2le(int, unsigned char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc) {
  static const char *apple_stop_sign = "{{~~  /-----\\   "
                                       "{{~~ /       \\  "
                                       "{{~~|         | "
                                       "{{~~| S T O P | "
                                       "{{~~|         | "
                                       "{{~~ \\       /  "
                                       "{{~~  \\-----/   "
                                       "Copyright(C) 200"
                                       "1 Apple Computer"
                                       ", Inc.----------"
                                       "----------------"
                                       "----------------"
                                       "----------------"
                                       "----------------"
                                       "----------------"
                                       "---------------";
  size_t len;
  int length;
  int rsrclength;
  int rsrcoffset;
  FILE *file;
  unsigned int sum = 0;
  unsigned int rsrcsum = 0;
  unsigned char *outbuf;
  int bufsize;
  int i;
  file = fopen(iname, "rb");
  if (!file) {
    perror(iname);
    return -1;
  }
  fseek(file, 0, SEEK_END);
  length = ftell(file);
  fseek(file, 0, SEEK_SET);
  bufsize = (length + 0x4600);
  if (fake_rsrc) {
    bufsize = (bufsize + 0x400) & ~0x200;
  }
  outbuf = malloc(bufsize);
  if (!outbuf) {
    printf("out of memory!\n");
    return -1;
  }
  len = fread(outbuf + 0x4600, 1, length, file);
  if (len < (size_t)length) {
    perror(iname);
    return -2;
  }
  fclose(file);
  for (i = 0x4600; i < 0x4600 + length; i++)
    sum += outbuf[i];
  memset(outbuf, 0, 0x4600);
  strcpy((char *)outbuf, apple_stop_sign);
  memcpy(&outbuf[0x100], "]ih[", 4);
  int2le(0x4000, &outbuf[0x104]);
  short2le(0x10c, &outbuf[0x108]);
  short2le(fw_ver, &outbuf[0x10a]);
  memcpy(&outbuf[0x4200], "!ATAsoso", 8);
  int2le(0, &outbuf[0x4208]);
  int2le(0x4400, &outbuf[0x420c]);
  int2le(length, &outbuf[0x4210]);
  int2le(0x10000000, &outbuf[0x4214]);
  int2le(0, &outbuf[0x4218]);
  int2le(sum, &outbuf[0x421c]);
  int2le(0x00006012, &outbuf[0x4220]);
  int2le(0xffffffff, &outbuf[0x4224]);
  if (fake_rsrc) {
    rsrcoffset = (length + 0x4600 + 0x200) & ~0x200;
    rsrclength = 0x200;
    rsrcsum = 0;
    memcpy(&outbuf[0x4228], "!ATAcrsr", 8);
    int2le(0, &outbuf[0x4230]);
    int2le(rsrcoffset, &outbuf[0x4234]);
    int2le(rsrclength, &outbuf[0x4238]);
    int2le(0x10000000, &outbuf[0x423c]);
    int2le(0, &outbuf[0x4240]);
    int2le(rsrcsum, &outbuf[0x4244]);
    int2le(0x0000b000, &outbuf[0x4248]);
    int2le(0xffffffff, &outbuf[0x424c]);
  }
  file = fopen(oname, "wb");
  if (!file) {
    perror(oname);
    return -3;
  }
  len = fwrite(outbuf, 1, length + 0x4600, file);
  if (len < (size_t)length) {
    perror(oname);
    return -4;
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<ipod_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xef1(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1238 <ipod_encode+0x58>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15eb <ipod_encode+0x40b>
mov    -0x40(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x2c(%rbp),%eax
add    $0x4600,%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1291 <ipod_encode+0xb1>
mov    -0x54(%rbp),%eax
add    $0x400,%eax
and    $0xfffffdff,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12c0 <ipod_encode+0xe0>
lea    0xe54(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15eb <ipod_encode+0x40b>
mov    -0x50(%rbp),%rdi
add    $0x4600,%rdi
mov    -0x2c(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmp    %rcx,%rax
jae    1306 <ipod_encode+0x126>
mov    -0x10(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    15eb <ipod_encode+0x40b>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x4600,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    $0x4600,%ecx
cmp    %ecx,%eax
jge    134a <ipod_encode+0x16a>
mov    -0x50(%rbp),%rax
movslq -0x58(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1316 <ipod_encode+0x136>
mov    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x4600,%edx
call   1070 <memset@plt>
mov    -0x50(%rbp),%rdi
mov    0x2d2b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x50(%rbp),%rdi
add    $0x100,%rdi
lea    0xd97(%rip),%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
mov    -0x50(%rbp),%rsi
add    $0x104,%rsi
mov    $0x4000,%edi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x108,%rsi
mov    $0x10c,%edi
call   10c0 <short2le@plt>
mov    -0x1c(%rbp),%edi
mov    -0x50(%rbp),%rsi
add    $0x10a,%rsi
call   10c0 <short2le@plt>
mov    -0x50(%rbp),%rdi
add    $0x4200,%rdi
lea    0xd43(%rip),%rsi
mov    $0x8,%edx
call   1090 <memcpy@plt>
mov    -0x50(%rbp),%rsi
add    $0x4208,%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x420c,%rsi
mov    $0x4400,%edi
call   10f0 <int2le@plt>
mov    -0x2c(%rbp),%edi
mov    -0x50(%rbp),%rsi
add    $0x4210,%rsi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x4214,%rsi
mov    $0x10000000,%edi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x4218,%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
mov    -0x44(%rbp),%edi
mov    -0x50(%rbp),%rsi
add    $0x421c,%rsi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x4220,%rsi
mov    $0x6012,%edi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x4224,%rsi
mov    $0xffffffff,%edi
call   10f0 <int2le@plt>
cmpl   $0x0,-0x20(%rbp)
je     1562 <ipod_encode+0x382>
mov    -0x2c(%rbp),%eax
add    $0x4600,%eax
add    $0x200,%eax
and    $0xfffffdff,%eax
mov    %eax,-0x34(%rbp)
movl   $0x200,-0x30(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x50(%rbp),%rdi
add    $0x4228,%rdi
lea    0xc65(%rip),%rsi
mov    $0x8,%edx
call   1090 <memcpy@plt>
mov    -0x50(%rbp),%rsi
add    $0x4230,%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
mov    -0x34(%rbp),%edi
mov    -0x50(%rbp),%rsi
add    $0x4234,%rsi
call   10f0 <int2le@plt>
mov    -0x30(%rbp),%edi
mov    -0x50(%rbp),%rsi
add    $0x4238,%rsi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x423c,%rsi
mov    $0x10000000,%edi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x4240,%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
mov    -0x48(%rbp),%edi
mov    -0x50(%rbp),%rsi
add    $0x4244,%rsi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x4248,%rsi
mov    $0xb000,%edi
call   10f0 <int2le@plt>
mov    -0x50(%rbp),%rsi
add    $0x424c,%rsi
mov    $0xffffffff,%edi
call   10f0 <int2le@plt>
mov    -0x18(%rbp),%rdi
lea    0xbbd(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1596 <ipod_encode+0x3b6>
mov    -0x18(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    15eb <ipod_encode+0x40b>
mov    -0x50(%rbp),%rdi
mov    -0x2c(%rbp),%edx
add    $0x4600,%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1100 <fwrite@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmp    %rcx,%rax
jae    15db <ipod_encode+0x3fb>
mov    -0x18(%rbp),%rdi
call   10e0 <perror@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    15eb <ipod_encode+0x40b>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipod_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeff(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1608 <ipod_encode+0x428>
mov    %rax,%rbp
mov    %r12d,0x4(%rsp)
mov    %rbx,0x10(%rsp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbp,%rdi
call   1080 <ftell@plt>
mov    %eax,%r13d
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
lea    0x4600(%r13),%r12d
lea    0x4a00(%r13),%edi
and    $0xfffffdff,%edi
test   %r15d,%r15d
cmove  %r12d,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12d4 <ipod_encode+0xf4>
mov    %rax,%rbx
lea    0x4600(%rax),%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
movslq %r13d,%rcx
cmp    %rcx,%rax
jb     1617 <ipod_encode+0x437>
mov    %rcx,0x8(%rsp)
mov    %rbp,%rdi
call   1060 <fclose@plt>
test   %r13d,%r13d
jle    12ea <ipod_encode+0x10a>
cmp    $0x4602,%r12d
mov    $0x4601,%eax
cmovge %r12d,%eax
lea    -0x4600(%rax),%rdx
cmp    $0x8,%rdx
jae    12f2 <ipod_encode+0x112>
xor    %r14d,%r14d
mov    $0x4600,%ecx
jmp    13e0 <ipod_encode+0x200>
lea    0xe42(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    15dd <ipod_encode+0x3fd>
xor    %r14d,%r14d
jmp    13f0 <ipod_encode+0x210>
mov    %rdx,%rcx
and    $0xfffffffffffffff8,%rcx
lea    -0x8(%rcx),%rsi
mov    %rsi,%rbp
shr    $0x3,%rbp
add    $0x1,%rbp
test   %rsi,%rsi
je     15ec <ipod_encode+0x40c>
mov    %rbp,%rsi
and    $0xfffffffffffffffe,%rsi
pxor   %xmm2,%xmm2
mov    $0x4600,%edi
pxor   %xmm0,%xmm0
pxor   %xmm1,%xmm1
nopl   0x0(%rax)
movd   (%rbx,%rdi,1),%xmm3
movd   0x4(%rbx,%rdi,1),%xmm4
punpcklbw %xmm2,%xmm3
punpcklwd %xmm2,%xmm3
paddd  %xmm0,%xmm3
punpcklbw %xmm2,%xmm4
punpcklwd %xmm2,%xmm4
paddd  %xmm1,%xmm4
movd   0x8(%rbx,%rdi,1),%xmm0
movd   0xc(%rbx,%rdi,1),%xmm1
punpcklbw %xmm2,%xmm0
punpcklwd %xmm2,%xmm0
paddd  %xmm3,%xmm0
punpcklbw %xmm2,%xmm1
punpcklwd %xmm2,%xmm1
paddd  %xmm4,%xmm1
add    $0x10,%rdi
add    $0xfffffffffffffffe,%rsi
jne    1330 <ipod_encode+0x150>
test   $0x1,%bpl
je     13ae <ipod_encode+0x1ce>
movd   (%rbx,%rdi,1),%xmm2
movd   0x4(%rbx,%rdi,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    %rcx,%rdx
je     13f0 <ipod_encode+0x210>
add    $0x4600,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx,%rcx,1),%edx
add    %edx,%r14d
add    $0x1,%rcx
cmp    %rcx,%rax
jne    13e0 <ipod_encode+0x200>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4600,%edx
call   1070 <memset@plt>
lea    0xbfa(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x100(%rbx),%rdi
lea    0xce7(%rip),%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
lea    0x104(%rbx),%rsi
mov    $0x4000,%edi
call   10f0 <int2le@plt>
lea    0x108(%rbx),%rsi
mov    $0x10c,%edi
call   10c0 <short2le@plt>
lea    0x10a(%rbx),%rsi
mov    0x4(%rsp),%edi
call   10c0 <short2le@plt>
lea    0x4200(%rbx),%rdi
lea    0xca2(%rip),%rsi
mov    $0x8,%edx
call   1090 <memcpy@plt>
lea    0x4208(%rbx),%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
lea    0x420c(%rbx),%rsi
mov    $0x4400,%edi
call   10f0 <int2le@plt>
lea    0x4210(%rbx),%rsi
mov    %r13d,%edi
call   10f0 <int2le@plt>
lea    0x4214(%rbx),%rsi
mov    $0x10000000,%edi
call   10f0 <int2le@plt>
lea    0x4218(%rbx),%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
lea    0x421c(%rbx),%rsi
mov    %r14d,%edi
call   10f0 <int2le@plt>
lea    0x4220(%rbx),%rsi
mov    $0x6012,%edi
call   10f0 <int2le@plt>
lea    0x4224(%rbx),%rsi
mov    $0xffffffff,%edi
call   10f0 <int2le@plt>
test   %r15d,%r15d
je     159d <ipod_encode+0x3bd>
add    $0x4800,%r13d
and    $0xfffffdff,%r13d
lea    0x4228(%rbx),%rdi
lea    0xbfe(%rip),%rsi
mov    $0x8,%edx
call   1090 <memcpy@plt>
lea    0x4230(%rbx),%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
lea    0x4234(%rbx),%rsi
mov    %r13d,%edi
call   10f0 <int2le@plt>
lea    0x4238(%rbx),%rsi
mov    $0x200,%edi
call   10f0 <int2le@plt>
lea    0x423c(%rbx),%rsi
mov    $0x10000000,%edi
call   10f0 <int2le@plt>
lea    0x4240(%rbx),%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
lea    0x4244(%rbx),%rsi
xor    %edi,%edi
call   10f0 <int2le@plt>
lea    0x4248(%rbx),%rsi
mov    $0xb000,%edi
call   10f0 <int2le@plt>
mov    %rbx,%rsi
add    $0x424c,%rsi
mov    $0xffffffff,%edi
call   10f0 <int2le@plt>
lea    0xb76(%rip),%rsi
mov    0x10(%rsp),%r14
mov    %r14,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1626 <ipod_encode+0x446>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rax,%rcx
call   1100 <fwrite@plt>
cmp    0x8(%rsp),%rax
jb     1635 <ipod_encode+0x455>
mov    %rbp,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
pxor   %xmm0,%xmm0
mov    $0x4600,%edi
pxor   %xmm1,%xmm1
test   $0x1,%bpl
jne    1387 <ipod_encode+0x1a7>
jmp    13ae <ipod_encode+0x1ce>
mov    %r14,%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%eax
jmp    15dd <ipod_encode+0x3fd>
mov    %r14,%rdi
call   10e0 <perror@plt>
mov    $0xfffffffe,%eax
jmp    15dd <ipod_encode+0x3fd>
mov    %r14,%rdi
call   10e0 <perror@plt>
mov    $0xfffffffd,%eax
jmp    15dd <ipod_encode+0x3fd>
mov    %r14,%rdi
call   10e0 <perror@plt>
mov    $0xfffffffc,%eax
jmp    15dd <ipod_encode+0x3fd>

LLVM IR (-O0):
@ipod_encode.apple_stop_sign = internal global i8* getelementptr inbounds ([256 x i8], [256 x i8]* @.str, i32 0, i32 0)
@.str = [256 x i8] c"{{~~ /-----\\ {{~~ / \\ {{~~| | {{~~| S T O P | {{~~| | {{~~ \\ / {{~~ \\-----/ Copyright(C) 2001 Apple Computer, Inc.---------------------------------------------------------------------------------------------------------\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [16 x i8] c"out of memory!\0A\00"
@.str.3 = [5 x i8] c"]ih[\00"
@.str.4 = [9 x i8] c"!ATAsoso\00"
@.str.5 = [9 x i8] c"!ATAcrsr\00"
@.str.6 = [3 x i8] c"wb\00"
define i32 @ipod_encode(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %15
store i32 0, i32* %16
%20 = load i8*, i8** %6
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %14
%22 = load i32*, i32** %14
%23 = icmp ne i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %4
%25 = load i8*, i8** %6
%26 = call i32 @perror(i8* %25)
store i32 -1, i32* %5
br label %193
27: ; preds = %4
%28 = load i32*, i32** %14
%29 = load i32, i32* @SEEK_END
%30 = call i32 @fseek(i32* %28, i32 0, i32 %29)
%31 = load i32*, i32** %14
%32 = call i32 @ftell(i32* %31)
store i32 %32, i32* %11
%33 = load i32*, i32** %14
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32, i32* %11
%37 = add nsw i32 %36, 17920
store i32 %37, i32* %18
%38 = load i32, i32* %9
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %27
%41 = load i32, i32* %18
%42 = add nsw i32 %41, 1024
%43 = and i32 %42, -513
store i32 %43, i32* %18
br label %44
44: ; preds = %40, %27
%45 = load i32, i32* %18
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %17
%47 = load i8*, i8** %17
%48 = icmp ne i8* %47, null
br i1 %48, label %51, label %49
49: ; preds = %44
%50 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %193
51: ; preds = %44
%52 = load i8*, i8** %17
%53 = getelementptr inbounds i8, i8* %52, i64 17920
%54 = load i32, i32* %11
%55 = load i32*, i32** %14
%56 = call i64 @fread(i8* %53, i32 1, i32 %54, i32* %55)
store i64 %56, i64* %10
%57 = load i64, i64* %10
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = icmp ult i64 %57, %59
br i1 %60, label %61, label %64
61: ; preds = %51
%62 = load i8*, i8** %6
%63 = call i32 @perror(i8* %62)
store i32 -2, i32* %5
br label %193
64: ; preds = %51
%65 = load i32*, i32** %14
%66 = call i32 @fclose(i32* %65)
store i32 17920, i32* %19
br label %67
67: ; preds = %81, %64
%68 = load i32, i32* %19
%69 = load i32, i32* %11
%70 = add nsw i32 17920, %69
%71 = icmp slt i32 %68, %70
br i1 %71, label %72, label %84
72: ; preds = %67
%73 = load i8*, i8** %17
%74 = load i32, i32* %19
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = load i32, i32* %15
%80 = add i32 %79, %78
store i32 %80, i32* %15
br label %81
81: ; preds = %72
%82 = load i32, i32* %19
%83 = add nsw i32 %82, 1
store i32 %83, i32* %19
br label %67
84: ; preds = %67
%85 = load i8*, i8** %17
%86 = call i32 @memset(i8* %85, i32 0, i32 17920)
%87 = load i8*, i8** %17
%88 = load i8*, i8** @ipod_encode.apple_stop_sign
%89 = call i32 @strcpy(i8* %87, i8* %88)
%90 = load i8*, i8** %17
%91 = getelementptr inbounds i8, i8* %90, i64 256
%92 = call i32 @memcpy(i8* %91, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%93 = load i8*, i8** %17
%94 = getelementptr inbounds i8, i8* %93, i64 260
%95 = call i32 @int2le(i32 16384, i8* %94)
%96 = load i8*, i8** %17
%97 = getelementptr inbounds i8, i8* %96, i64 264
%98 = call i32 @short2le(i32 268, i8* %97)
%99 = load i32, i32* %8
%100 = load i8*, i8** %17
%101 = getelementptr inbounds i8, i8* %100, i64 266
%102 = call i32 @short2le(i32 %99, i8* %101)
%103 = load i8*, i8** %17
%104 = getelementptr inbounds i8, i8* %103, i64 16896
%105 = call i32 @memcpy(i8* %104, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%106 = load i8*, i8** %17
%107 = getelementptr inbounds i8, i8* %106, i64 16904
%108 = call i32 @int2le(i32 0, i8* %107)
%109 = load i8*, i8** %17
%110 = getelementptr inbounds i8, i8* %109, i64 16908
%111 = call i32 @int2le(i32 17408, i8* %110)
%112 = load i32, i32* %11
%113 = load i8*, i8** %17
%114 = getelementptr inbounds i8, i8* %113, i64 16912
%115 = call i32 @int2le(i32 %112, i8* %114)
%116 = load i8*, i8** %17
%117 = getelementptr inbounds i8, i8* %116, i64 16916
%118 = call i32 @int2le(i32 268435456, i8* %117)
%119 = load i8*, i8** %17
%120 = getelementptr inbounds i8, i8* %119, i64 16920
%121 = call i32 @int2le(i32 0, i8* %120)
%122 = load i32, i32* %15
%123 = load i8*, i8** %17
%124 = getelementptr inbounds i8, i8* %123, i64 16924
%125 = call i32 @int2le(i32 %122, i8* %124)
%126 = load i8*, i8** %17
%127 = getelementptr inbounds i8, i8* %126, i64 16928
%128 = call i32 @int2le(i32 24594, i8* %127)
%129 = load i8*, i8** %17
%130 = getelementptr inbounds i8, i8* %129, i64 16932
%131 = call i32 @int2le(i32 -1, i8* %130)
%132 = load i32, i32* %9
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %169
134: ; preds = %84
%135 = load i32, i32* %11
%136 = add nsw i32 %135, 17920
%137 = add nsw i32 %136, 512
%138 = and i32 %137, -513
store i32 %138, i32* %13
store i32 512, i32* %12
store i32 0, i32* %16
%139 = load i8*, i8** %17
%140 = getelementptr inbounds i8, i8* %139, i64 16936
%141 = call i32 @memcpy(i8* %140, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8)
%142 = load i8*, i8** %17
%143 = getelementptr inbounds i8, i8* %142, i64 16944
%144 = call i32 @int2le(i32 0, i8* %143)
%145 = load i32, i32* %13
%146 = load i8*, i8** %17
%147 = getelementptr inbounds i8, i8* %146, i64 16948
%148 = call i32 @int2le(i32 %145, i8* %147)
%149 = load i32, i32* %12
%150 = load i8*, i8** %17
%151 = getelementptr inbounds i8, i8* %150, i64 16952
%152 = call i32 @int2le(i32 %149, i8* %151)
%153 = load i8*, i8** %17
%154 = getelementptr inbounds i8, i8* %153, i64 16956
%155 = call i32 @int2le(i32 268435456, i8* %154)
%156 = load i8*, i8** %17
%157 = getelementptr inbounds i8, i8* %156, i64 16960
%158 = call i32 @int2le(i32 0, i8* %157)
%159 = load i32, i32* %16
%160 = load i8*, i8** %17
%161 = getelementptr inbounds i8, i8* %160, i64 16964
%162 = call i32 @int2le(i32 %159, i8* %161)
%163 = load i8*, i8** %17
%164 = getelementptr inbounds i8, i8* %163, i64 16968
%165 = call i32 @int2le(i32 45056, i8* %164)
%166 = load i8*, i8** %17
%167 = getelementptr inbounds i8, i8* %166, i64 16972
%168 = call i32 @int2le(i32 -1, i8* %167)
br label %169
169: ; preds = %134, %84
%170 = load i8*, i8** %7
%171 = call i32* @fopen(i8* %170, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %171, i32** %14
%172 = load i32*, i32** %14
%173 = icmp ne i32* %172, null
br i1 %173, label %177, label %174
174: ; preds = %169
%175 = load i8*, i8** %7
%176 = call i32 @perror(i8* %175)
store i32 -3, i32* %5
br label %193
177: ; preds = %169
%178 = load i8*, i8** %17
%179 = load i32, i32* %11
%180 = add nsw i32 %179, 17920
%181 = load i32*, i32** %14
%182 = call i64 @fwrite(i8* %178, i32 1, i32 %180, i32* %181)
store i64 %182, i64* %10
%183 = load i64, i64* %10
%184 = load i32, i32* %11
%185 = sext i32 %184 to i64
%186 = icmp ult i64 %183, %185
br i1 %186, label %187, label %190
187: ; preds = %177
%188 = load i8*, i8** %7
%189 = call i32 @perror(i8* %188)
store i32 -4, i32* %5
br label %193
190: ; preds = %177
%191 = load i32*, i32** %14
%192 = call i32 @fclose(i32* %191)
store i32 0, i32* %5
br label %193
193: ; preds = %190, %187, %174, %61, %49, %24
%194 = load i32, i32* %5
ret i32 %194
}

LLVM IR (-O2):
@.str = [256 x i8] c"{{~~ /-----\\ {{~~ / \\ {{~~| | {{~~| S T O P | {{~~| | {{~~ \\ / {{~~ \\-----/ Copyright(C) 2001 Apple Computer, Inc.---------------------------------------------------------------------------------------------------------\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [5 x i8] c"]ih[\00"
@.str.4 = [9 x i8] c"!ATAsoso\00"
@.str.5 = [9 x i8] c"!ATAcrsr\00"
@.str.6 = [3 x i8] c"wb\00"
@str = [15 x i8] c"out of memory!\00"
define i32 @ipod_encode(i8* nocapture %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @perror(i8* %0)
br label %180
9: ; preds = %4
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %5, i32 0, i32 %10)
%12 = tail call i32 @ftell(i32* %5)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %5, i32 0, i32 %13)
%15 = add i32 %12, 17920
%16 = icmp eq i32 %3, 0
%17 = add nsw i32 %12, 18944
%18 = and i32 %17, -513
%19 = select i1 %16, i32 %15, i32 %18
%20 = tail call i8* @malloc(i32 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %9
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %180
24: ; preds = %9
%25 = getelementptr inbounds i8, i8* %20, i64 17920
%26 = tail call i64 @fread(i8* %25, i32 1, i32 %12, i32* %5)
%27 = sext i32 %12 to i64
%28 = icmp ult i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i32 @perror(i8* %0)
br label %180
31: ; preds = %24
%32 = tail call i32 @fclose(i32* %5)
%33 = icmp sgt i32 %12, 0
br i1 %33, label %34, label %117
34: ; preds = %31
%35 = call i32 @llvm.smax.i32(i32 %15, i32 17921)
%36 = zext i32 %35 to i64
%37 = add nsw i64 %36, -17920
%38 = icmp ult i64 %37, 8
br i1 %38, label %105, label %39
39: ; preds = %34
%40 = and i64 %37, -8
%41 = add nsw i64 %40, 17920
%42 = add nsw i64 %40, -8
%43 = lshr exact i64 %42, 3
%44 = add nuw nsw i64 %43, 1
%45 = and i64 %44, 1
%46 = icmp eq i64 %42, 0
br i1 %46, label %81, label %47
47: ; preds = %39
%48 = and i64 %44, 4611686018427387902
br label %49
49: ; preds = %49, %47
%50 = phi i64 [ 0, %47 ], [ %76, %49 ]
%51 = phi <4 x i32> [ zeroinitializer, %47 ], [ %74, %49 ]
%52 = phi <4 x i32> [ zeroinitializer, %47 ], [ %75, %49 ]
%53 = phi i64 [ 0, %47 ], [ %77, %49 ]
%54 = add i64 %50, 17920
%55 = getelementptr inbounds i8, i8* %20, i64 %54
%56 = bitcast i8* %55 to <4 x i8>*
%57 = load <4 x i8>, <4 x i8>* %56
%58 = getelementptr inbounds i8, i8* %55, i64 4
%59 = bitcast i8* %58 to <4 x i8>*
%60 = load <4 x i8>, <4 x i8>* %59
%61 = zext <4 x i8> %57 to <4 x i32>
%62 = zext <4 x i8> %60 to <4 x i32>
%63 = add <4 x i32> %51, %61
%64 = add <4 x i32> %52, %62
%65 = add i64 %50, 17928
%66 = getelementptr inbounds i8, i8* %20, i64 %65
%67 = bitcast i8* %66 to <4 x i8>*
%68 = load <4 x i8>, <4 x i8>* %67
%69 = getelementptr inbounds i8, i8* %66, i64 4
%70 = bitcast i8* %69 to <4 x i8>*
%71 = load <4 x i8>, <4 x i8>* %70
%72 = zext <4 x i8> %68 to <4 x i32>
%73 = zext <4 x i8> %71 to <4 x i32>
%74 = add <4 x i32> %63, %72
%75 = add <4 x i32> %64, %73
%76 = add nuw i64 %50, 16
%77 = add i64 %53, 2
%78 = icmp eq i64 %77, %48
br i1 %78, label %79, label %49
79: ; preds = %49
%80 = add i64 %50, 17936
br label %81
81: ; preds = %79, %39
%82 = phi <4 x i32> [ undef, %39 ], [ %74, %79 ]
%83 = phi <4 x i32> [ undef, %39 ], [ %75, %79 ]
%84 = phi i64 [ 17920, %39 ], [ %80, %79 ]
%85 = phi <4 x i32> [ zeroinitializer, %39 ], [ %74, %79 ]
%86 = phi <4 x i32> [ zeroinitializer, %39 ], [ %75, %79 ]
%87 = icmp eq i64 %45, 0
br i1 %87, label %99, label %88
88: ; preds = %81
%89 = getelementptr inbounds i8, i8* %20, i64 %84
%90 = bitcast i8* %89 to <4 x i8>*
%91 = load <4 x i8>, <4 x i8>* %90
%92 = getelementptr inbounds i8, i8* %89, i64 4
%93 = bitcast i8* %92 to <4 x i8>*
%94 = load <4 x i8>, <4 x i8>* %93
%95 = zext <4 x i8> %91 to <4 x i32>
%96 = zext <4 x i8> %94 to <4 x i32>
%97 = add <4 x i32> %85, %95
%98 = add <4 x i32> %86, %96
br label %99
99: ; preds = %81, %88
%100 = phi <4 x i32> [ %82, %81 ], [ %97, %88 ]
%101 = phi <4 x i32> [ %83, %81 ], [ %98, %88 ]
%102 = add <4 x i32> %101, %100
%103 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %102)
%104 = icmp eq i64 %37, %40
br i1 %104, label %117, label %105
105: ; preds = %34, %99
%106 = phi i64 [ 17920, %34 ], [ %41, %99 ]
%107 = phi i32 [ 0, %34 ], [ %103, %99 ]
br label %108
108: ; preds = %105, %108
%109 = phi i64 [ %115, %108 ], [ %106, %105 ]
%110 = phi i32 [ %114, %108 ], [ %107, %105 ]
%111 = getelementptr inbounds i8, i8* %20, i64 %109
%112 = load i8, i8* %111
%113 = zext i8 %112 to i32
%114 = add i32 %110, %113
%115 = add nuw nsw i64 %109, 1
%116 = icmp eq i64 %115, %36
br i1 %116, label %117, label %108
117: ; preds = %108, %99, %31
%118 = phi i32 [ 0, %31 ], [ %103, %99 ], [ %114, %108 ]
%119 = tail call i32 @memset(i8* %20, i32 0, i32 17920)
%120 = tail call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @.str, i64 0, i64 0))
%121 = getelementptr inbounds i8, i8* %20, i64 256
%122 = tail call i32 @memcpy(i8* %121, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%123 = getelementptr inbounds i8, i8* %20, i64 260
%124 = tail call i32 @int2le(i32 16384, i8* %123)
%125 = getelementptr inbounds i8, i8* %20, i64 264
%126 = tail call i32 @short2le(i32 268, i8* %125)
%127 = getelementptr inbounds i8, i8* %20, i64 266
%128 = tail call i32 @short2le(i32 %2, i8* %127)
%129 = getelementptr inbounds i8, i8* %20, i64 16896
%130 = tail call i32 @memcpy(i8* %129, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%131 = getelementptr inbounds i8, i8* %20, i64 16904
%132 = tail call i32 @int2le(i32 0, i8* %131)
%133 = getelementptr inbounds i8, i8* %20, i64 16908
%134 = tail call i32 @int2le(i32 17408, i8* %133)
%135 = getelementptr inbounds i8, i8* %20, i64 16912
%136 = tail call i32 @int2le(i32 %12, i8* %135)
%137 = getelementptr inbounds i8, i8* %20, i64 16916
%138 = tail call i32 @int2le(i32 268435456, i8* %137)
%139 = getelementptr inbounds i8, i8* %20, i64 16920
%140 = tail call i32 @int2le(i32 0, i8* %139)
%141 = getelementptr inbounds i8, i8* %20, i64 16924
%142 = tail call i32 @int2le(i32 %118, i8* %141)
%143 = getelementptr inbounds i8, i8* %20, i64 16928
%144 = tail call i32 @int2le(i32 24594, i8* %143)
%145 = getelementptr inbounds i8, i8* %20, i64 16932
%146 = tail call i32 @int2le(i32 -1, i8* %145)
br i1 %16, label %168, label %147
147: ; preds = %117
%148 = add nsw i32 %12, 18432
%149 = and i32 %148, -513
%150 = getelementptr inbounds i8, i8* %20, i64 16936
%151 = tail call i32 @memcpy(i8* %150, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8)
%152 = getelementptr inbounds i8, i8* %20, i64 16944
%153 = tail call i32 @int2le(i32 0, i8* %152)
%154 = getelementptr inbounds i8, i8* %20, i64 16948
%155 = tail call i32 @int2le(i32 %149, i8* %154)
%156 = getelementptr inbounds i8, i8* %20, i64 16952
%157 = tail call i32 @int2le(i32 512, i8* %156)
%158 = getelementptr inbounds i8, i8* %20, i64 16956
%159 = tail call i32 @int2le(i32 268435456, i8* %158)
%160 = getelementptr inbounds i8, i8* %20, i64 16960
%161 = tail call i32 @int2le(i32 0, i8* %160)
%162 = getelementptr inbounds i8, i8* %20, i64 16964
%163 = tail call i32 @int2le(i32 0, i8* %162)
%164 = getelementptr inbounds i8, i8* %20, i64 16968
%165 = tail call i32 @int2le(i32 45056, i8* %164)
%166 = getelementptr inbounds i8, i8* %20, i64 16972
%167 = tail call i32 @int2le(i32 -1, i8* %166)
br label %168
168: ; preds = %147, %117
%169 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%170 = icmp eq i32* %169, null
br i1 %170, label %171, label %173
171: ; preds = %168
%172 = tail call i32 @perror(i8* %1)
br label %180
173: ; preds = %168
%174 = tail call i64 @fwrite(i8* %20, i32 1, i32 %15, i32* %169)
%175 = icmp ult i64 %174, %27
br i1 %175, label %176, label %178
176: ; preds = %173
%177 = tail call i32 @perror(i8* %1)
br label %180
178: ; preds = %173
%179 = tail call i32 @fclose(i32* %169)
br label %180
180: ; preds = %178, %176, %171, %29, %22, %7
%181 = phi i32 [ -2, %29 ], [ -4, %176 ], [ 0, %178 ], [ -3, %171 ], [ -1, %22 ], [ -1, %7 ]
ret i32 %181
}