#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_WRONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ close(int);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ put_wav_header(int, int, int, int, int);
int read(int, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
int /*<<< orphan*/ write(int, char *, int);
int read_entry(int fd_in) {
  int swapped = 0, size, samp, bits, chans;
  char filename[14], buf[512];
  int fd_out, pos = 0;
  printf("new entry at %x\n", (unsigned int)lseek(fd_in, 0, SEEK_CUR));
  read(fd_in, buf, 70);
  if (buf[3])
    swapped++;
  if (swapped) {
    size = (buf[0] << 16) | (buf[1] << 24) | (buf[2]) | (buf[3] << 8);
    samp = (buf[4] << 16) | (buf[5] << 24) | (buf[6]) | (buf[7] << 8);
    bits = (buf[8] << 16) | (buf[9] << 24) | (buf[10]) | (buf[11] << 8);
    chans = (buf[12] << 16) | (buf[13] << 24) | (buf[14]) | (buf[15] << 8);
    size += 2;
    strncpy(&filename[0], &buf[52], 14);
  } else {
    size = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
    samp = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
    bits = buf[8] | (buf[9] << 8) | (buf[10] << 16) | (buf[11] << 24);
    chans = buf[12] | (buf[13] << 8) | (buf[14] << 16) | (buf[15] << 24);
    strncpy(&filename[0], &buf[50], 14);
  }
  if (!size)
    return -1;
  printf("entry %x: %s size: %x %d/%d/%d\n",
         (unsigned int)lseek(fd_in, 0, SEEK_CUR), filename, size, samp, bits,
         chans);
  strncpy(buf, filename, 14);
  if (strrchr(buf, '.')) {
    char *loc = strrchr(buf, '.');
    strncpy(loc, ".wav", 5);
  }
  printf("Writing out %s...\n", buf);
  fd_out = open(buf, O_WRONLY | O_CREAT, 0666);
  put_wav_header(fd_out, samp, bits, chans, size);
  while (pos < size) {
    int ret = read(fd_in, buf, (size - pos > 512) ? 512 : size - pos);
    write(fd_out, buf, ret);
    pos += ret;
  }
  close(fd_out);
  if (size % 4) {
    int aligned = size + (4 - (size % 4));
    printf("aligned: %d, pos: %d, %d\n", aligned, pos, aligned - pos);
    lseek(fd_in, aligned - pos, SEEK_CUR);
    return 70 + size + aligned - pos;
  }
  return 70 + size;
}


x86 assembly (clang, -O0):
<read_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x238(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %eax,%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x46,%edx
call   1090 <read@plt>
cmpb   $0x0,-0x22d(%rbp)
je     11fc <read_entry+0x6c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     12e5 <read_entry+0x155>
movsbl -0x230(%rbp),%eax
shl    $0x10,%eax
movsbl -0x22f(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
movsbl -0x22e(%rbp),%ecx
or     %ecx,%eax
movsbl -0x22d(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
movsbl -0x22c(%rbp),%eax
shl    $0x10,%eax
movsbl -0x22b(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
movsbl -0x22a(%rbp),%ecx
or     %ecx,%eax
movsbl -0x229(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
movsbl -0x228(%rbp),%eax
shl    $0x10,%eax
movsbl -0x227(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
movsbl -0x226(%rbp),%ecx
or     %ecx,%eax
movsbl -0x225(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x224(%rbp),%eax
shl    $0x10,%eax
movsbl -0x223(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
movsbl -0x222(%rbp),%ecx
or     %ecx,%eax
movsbl -0x221(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
lea    -0x2a(%rbp),%rdi
lea    -0x230(%rbp),%rsi
add    $0x34,%rsi
mov    $0xe,%edx
call   1030 <strncpy@plt>
jmp    13b6 <read_entry+0x226>
movsbl -0x230(%rbp),%eax
movsbl -0x22f(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movsbl -0x22e(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movsbl -0x22d(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
movsbl -0x22c(%rbp),%eax
movsbl -0x22b(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movsbl -0x22a(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movsbl -0x229(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x14(%rbp)
movsbl -0x228(%rbp),%eax
movsbl -0x227(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movsbl -0x226(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movsbl -0x225(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x224(%rbp),%eax
movsbl -0x223(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movsbl -0x222(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movsbl -0x221(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
lea    -0x2a(%rbp),%rdi
lea    -0x230(%rbp),%rsi
add    $0x32,%rsi
mov    $0xe,%edx
call   1030 <strncpy@plt>
cmpl   $0x0,-0x10(%rbp)
jne    13cc <read_entry+0x23c>
movl   $0xffffffff,-0x4(%rbp)
jmp    160e <read_entry+0x47e>
mov    -0x8(%rbp),%edi
mov    0x2c0a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %eax,%esi
lea    -0x2a(%rbp),%rdx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
mov    -0x1c(%rbp),%eax
lea    0xc17(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x230(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
mov    $0xe,%edx
call   1030 <strncpy@plt>
lea    -0x230(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
cmp    $0x0,%rax
je     1464 <read_entry+0x2d4>
lea    -0x230(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x240(%rbp)
mov    -0x240(%rbp),%rdi
lea    0xbd7(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
lea    -0x230(%rbp),%rsi
lea    0xbc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x230(%rbp),%rdi
mov    0x2b41(%rip),%rax
mov    (%rax),%esi
mov    0x2b68(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10a0 <open@plt>
mov    %eax,-0x234(%rbp)
mov    -0x234(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   10b0 <put_wav_header@plt>
mov    -0x238(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1560 <read_entry+0x3d0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x254(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x10(%rbp),%eax
sub    -0x238(%rbp),%eax
cmp    $0x200,%eax
jle    1504 <read_entry+0x374>
mov    $0x200,%eax
mov    %eax,-0x258(%rbp)
jmp    1513 <read_entry+0x383>
mov    -0x10(%rbp),%eax
sub    -0x238(%rbp),%eax
mov    %eax,-0x258(%rbp)
mov    -0x250(%rbp),%rsi
mov    -0x254(%rbp),%edi
mov    -0x258(%rbp),%edx
call   1090 <read@plt>
mov    %eax,-0x244(%rbp)
mov    -0x234(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x244(%rbp),%edx
call   1040 <write@plt>
mov    -0x244(%rbp),%eax
add    -0x238(%rbp),%eax
mov    %eax,-0x238(%rbp)
jmp    14ba <read_entry+0x32a>
mov    -0x234(%rbp),%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1605 <read_entry+0x475>
mov    -0x10(%rbp),%eax
mov    %eax,-0x25c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x25c(%rbp),%eax
mov    $0x4,%ecx
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x248(%rbp)
mov    -0x248(%rbp),%esi
mov    -0x238(%rbp),%edx
mov    -0x248(%rbp),%ecx
sub    -0x238(%rbp),%ecx
lea    0xa82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x248(%rbp),%esi
sub    -0x238(%rbp),%esi
mov    0x29fc(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
mov    -0x10(%rbp),%eax
add    $0x46,%eax
add    -0x248(%rbp),%eax
sub    -0x238(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160e <read_entry+0x47e>
mov    -0x10(%rbp),%eax
add    $0x46,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_entry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %edi,%r14d
mov    0x2e35(%rip),%rbp
mov    0x0(%rbp),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
lea    0xe44(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0x46,%edx
call   1090 <read@plt>
movsbl 0x23(%rsp),%r12d
movsbl 0x20(%rsp),%eax
test   %r12d,%r12d
je     1286 <read_entry+0xf6>
shl    $0x10,%eax
movzbl 0x21(%rsp),%ecx
shl    $0x18,%ecx
movsbl 0x22(%rsp),%edx
or     %ecx,%edx
shl    $0x8,%r12d
or     %eax,%r12d
or     %edx,%r12d
movsbl 0x24(%rsp),%eax
shl    $0x10,%eax
movzbl 0x25(%rsp),%ecx
shl    $0x18,%ecx
or     %eax,%ecx
movsbl 0x26(%rsp),%eax
movsbl 0x27(%rsp),%r15d
shl    $0x8,%r15d
or     %eax,%r15d
or     %ecx,%r15d
movsbl 0x28(%rsp),%eax
shl    $0x10,%eax
movzbl 0x29(%rsp),%ecx
shl    $0x18,%ecx
or     %eax,%ecx
movsbl 0x2a(%rsp),%eax
movsbl 0x2b(%rsp),%ebx
shl    $0x8,%ebx
or     %eax,%ebx
or     %ecx,%ebx
movsbl 0x2c(%rsp),%eax
shl    $0x10,%eax
movzbl 0x2d(%rsp),%ecx
shl    $0x18,%ecx
or     %eax,%ecx
movsbl 0x2e(%rsp),%eax
movsbl 0x2f(%rsp),%r13d
shl    $0x8,%r13d
or     %eax,%r13d
or     %ecx,%r13d
add    $0x2,%r12d
mov    $0x34,%eax
jmp    1314 <read_entry+0x184>
movsbl 0x21(%rsp),%r12d
shl    $0x8,%r12d
movsbl 0x22(%rsp),%ecx
shl    $0x10,%ecx
or     %eax,%r12d
or     %ecx,%r12d
movsbl 0x24(%rsp),%eax
movsbl 0x25(%rsp),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x26(%rsp),%eax
shl    $0x10,%eax
movzbl 0x27(%rsp),%r15d
shl    $0x18,%r15d
or     %eax,%r15d
or     %ecx,%r15d
movsbl 0x28(%rsp),%eax
movsbl 0x29(%rsp),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x2a(%rsp),%eax
shl    $0x10,%eax
movzbl 0x2b(%rsp),%ebx
shl    $0x18,%ebx
or     %eax,%ebx
or     %ecx,%ebx
movsbl 0x2c(%rsp),%eax
movsbl 0x2d(%rsp),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movsbl 0x2e(%rsp),%eax
shl    $0x10,%eax
movzbl 0x2f(%rsp),%r13d
shl    $0x18,%r13d
or     %eax,%r13d
or     %ecx,%r13d
mov    $0x32,%eax
lea    (%rsp,%rax,1),%rsi
add    $0x20,%rsi
lea    0x12(%rsp),%rdi
mov    $0xe,%edx
call   1030 <strncpy@plt>
test   %r12d,%r12d
je     14a6 <read_entry+0x316>
mov    0x0(%rbp),%edx
xor    %ebp,%ebp
mov    %r14d,0xc(%rsp)
mov    %r14d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %r13d,(%rsp)
lea    0xcbe(%rip),%rdi
lea    0x12(%rsp),%rdx
mov    %eax,%esi
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
lea    0x12(%rsp),%rsi
mov    $0xe,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     13a7 <read_entry+0x217>
lea    0xc97(%rip),%rsi
mov    %rax,%rdi
mov    $0x5,%edx
call   1030 <strncpy@plt>
lea    0xc88(%rip),%rdi
lea    0x20(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2c04(%rip),%rax
mov    0x2c2d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
call   10a0 <open@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
mov    %r12d,%r8d
call   10b0 <put_wav_header@plt>
test   %r12d,%r12d
mov    0xc(%rsp),%r15d
jle    1444 <read_entry+0x2b4>
xor    %ebp,%ebp
lea    0x20(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edx
sub    %ebp,%edx
cmp    $0x200,%edx
mov    $0x200,%eax
cmovge %eax,%edx
mov    %r15d,%edi
mov    %r13,%rsi
call   1090 <read@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1040 <write@plt>
add    %ebx,%ebp
cmp    %ebp,%r12d
jg     1410 <read_entry+0x280>
mov    %r14d,%edi
call   1080 <close@plt>
lea    0x3(%r12),%ecx
test   %r12d,%r12d
cmovns %r12d,%ecx
and    $0xfffffffc,%ecx
mov    %r12d,%eax
sub    %ecx,%eax
je     14a0 <read_entry+0x310>
mov    %r12d,%r14d
sub    %eax,%r14d
lea    0x4(%r14),%esi
mov    %esi,%ebx
sub    %ebp,%ebx
lea    0xbd2(%rip),%rdi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2b57(%rip),%rax
mov    (%rax),%edx
mov    0xc(%rsp),%edi
mov    %ebx,%esi
call   1070 <lseek@plt>
add    %r14d,%r12d
add    $0x4,%r12d
sub    %ebp,%r12d
add    $0x46,%r12d
jmp    14ac <read_entry+0x31c>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"new entry at %x\0A\00"
@SEEK_CUR = global i32 0
@.str.1 = [32 x i8] c"entry %x: %s size: %x %d/%d/%d\0A\00"
@.str.2 = [5 x i8] c".wav\00"
@.str.3 = [19 x i8] c"Writing out %s...\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.4 = [26 x i8] c"aligned: %d, pos: %d, %d\0A\00"
define i32 @read_entry(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [14 x i8]
%10 = alloca [512 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %12
%16 = load i32, i32* %3
%17 = load i32, i32* @SEEK_CUR
%18 = call i64 @lseek(i32 %16, i32 0, i32 %17)
%19 = trunc i64 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %3
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%23 = call i32 @read(i32 %21, i8* %22, i32 70)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 3
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %1
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %1
%31 = load i32, i32* %4
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %111
33: ; preds = %30
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = shl i32 %36, 16
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = shl i32 %40, 24
%42 = or i32 %37, %41
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 2
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = or i32 %42, %45
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 3
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = shl i32 %49, 8
%51 = or i32 %46, %50
store i32 %51, i32* %5
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 4
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = shl i32 %54, 16
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 5
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = shl i32 %58, 24
%60 = or i32 %55, %59
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 6
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = or i32 %60, %63
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 7
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = shl i32 %67, 8
%69 = or i32 %64, %68
store i32 %69, i32* %6
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 8
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = shl i32 %72, 16
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 9
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = shl i32 %76, 24
%78 = or i32 %73, %77
%79 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 10
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = or i32 %78, %81
%83 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 11
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = shl i32 %85, 8
%87 = or i32 %82, %86
store i32 %87, i32* %7
%88 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 12
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = shl i32 %90, 16
%92 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 13
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = shl i32 %94, 24
%96 = or i32 %91, %95
%97 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 14
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = or i32 %96, %99
%101 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 15
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = shl i32 %103, 8
%105 = or i32 %100, %104
store i32 %105, i32* %8
%106 = load i32, i32* %5
%107 = add nsw i32 %106, 2
store i32 %107, i32* %5
%108 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%109 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 52
%110 = call i32 @strncpy(i8* %108, i8* %109, i32 14)
br label %187
111: ; preds = %30
%112 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 1
%116 = load i8, i8* %115
%117 = sext i8 %116 to i32
%118 = shl i32 %117, 8
%119 = or i32 %114, %118
%120 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 2
%121 = load i8, i8* %120
%122 = sext i8 %121 to i32
%123 = shl i32 %122, 16
%124 = or i32 %119, %123
%125 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 3
%126 = load i8, i8* %125
%127 = sext i8 %126 to i32
%128 = shl i32 %127, 24
%129 = or i32 %124, %128
store i32 %129, i32* %5
%130 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 4
%131 = load i8, i8* %130
%132 = sext i8 %131 to i32
%133 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 5
%134 = load i8, i8* %133
%135 = sext i8 %134 to i32
%136 = shl i32 %135, 8
%137 = or i32 %132, %136
%138 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 6
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = shl i32 %140, 16
%142 = or i32 %137, %141
%143 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 7
%144 = load i8, i8* %143
%145 = sext i8 %144 to i32
%146 = shl i32 %145, 24
%147 = or i32 %142, %146
store i32 %147, i32* %6
%148 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 8
%149 = load i8, i8* %148
%150 = sext i8 %149 to i32
%151 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 9
%152 = load i8, i8* %151
%153 = sext i8 %152 to i32
%154 = shl i32 %153, 8
%155 = or i32 %150, %154
%156 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 10
%157 = load i8, i8* %156
%158 = sext i8 %157 to i32
%159 = shl i32 %158, 16
%160 = or i32 %155, %159
%161 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 11
%162 = load i8, i8* %161
%163 = sext i8 %162 to i32
%164 = shl i32 %163, 24
%165 = or i32 %160, %164
store i32 %165, i32* %7
%166 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 12
%167 = load i8, i8* %166
%168 = sext i8 %167 to i32
%169 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 13
%170 = load i8, i8* %169
%171 = sext i8 %170 to i32
%172 = shl i32 %171, 8
%173 = or i32 %168, %172
%174 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 14
%175 = load i8, i8* %174
%176 = sext i8 %175 to i32
%177 = shl i32 %176, 16
%178 = or i32 %173, %177
%179 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 15
%180 = load i8, i8* %179
%181 = sext i8 %180 to i32
%182 = shl i32 %181, 24
%183 = or i32 %178, %182
store i32 %183, i32* %8
%184 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%185 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 50
%186 = call i32 @strncpy(i8* %184, i8* %185, i32 14)
br label %187
187: ; preds = %111, %33
%188 = load i32, i32* %5
%189 = icmp ne i32 %188, 0
br i1 %189, label %191, label %190
190: ; preds = %187
store i32 -1, i32* %2
br label %286
191: ; preds = %187
%192 = load i32, i32* %3
%193 = load i32, i32* @SEEK_CUR
%194 = call i64 @lseek(i32 %192, i32 0, i32 %193)
%195 = trunc i64 %194 to i32
%196 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%197 = load i32, i32* %5
%198 = load i32, i32* %6
%199 = load i32, i32* %7
%200 = load i32, i32* %8
%201 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %195, i8* %196, i32 %197, i32 %198, i32 %199, i32 %200)
%202 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%203 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%204 = call i32 @strncpy(i8* %202, i8* %203, i32 14)
%205 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%206 = call i8* @strrchr(i8* %205, i8 signext 46)
%207 = icmp ne i8* %206, null
br i1 %207, label %208, label %213
208: ; preds = %191
%209 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%210 = call i8* @strrchr(i8* %209, i8 signext 46)
store i8* %210, i8** %13
%211 = load i8*, i8** %13
%212 = call i32 @strncpy(i8* %211, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
br label %213
213: ; preds = %208, %191
%214 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%215 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %214)
%216 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%217 = load i32, i32* @O_WRONLY
%218 = load i32, i32* @O_CREAT
%219 = or i32 %217, %218
%220 = call i32 @open(i8* %216, i32 %219, i32 438)
store i32 %220, i32* %11
%221 = load i32, i32* %11
%222 = load i32, i32* %6
%223 = load i32, i32* %7
%224 = load i32, i32* %8
%225 = load i32, i32* %5
%226 = call i32 @put_wav_header(i32 %221, i32 %222, i32 %223, i32 %224, i32 %225)
br label %227
227: ; preds = %243, %213
%228 = load i32, i32* %12
%229 = load i32, i32* %5
%230 = icmp slt i32 %228, %229
br i1 %230, label %231, label %253
231: ; preds = %227
%232 = load i32, i32* %3
%233 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%234 = load i32, i32* %5
%235 = load i32, i32* %12
%236 = sub nsw i32 %234, %235
%237 = icmp sgt i32 %236, 512
br i1 %237, label %238, label %239
238: ; preds = %231
br label %243
239: ; preds = %231
%240 = load i32, i32* %5
%241 = load i32, i32* %12
%242 = sub nsw i32 %240, %241
br label %243
243: ; preds = %239, %238
%244 = phi i32 [ 512, %238 ], [ %242, %239 ]
%245 = call i32 @read(i32 %232, i8* %233, i32 %244)
store i32 %245, i32* %14
%246 = load i32, i32* %11
%247 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%248 = load i32, i32* %14
%249 = call i32 @write(i32 %246, i8* %247, i32 %248)
%250 = load i32, i32* %14
%251 = load i32, i32* %12
%252 = add nsw i32 %251, %250
store i32 %252, i32* %12
br label %227
253: ; preds = %227
%254 = load i32, i32* %11
%255 = call i32 @close(i32 %254)
%256 = load i32, i32* %5
%257 = srem i32 %256, 4
%258 = icmp ne i32 %257, 0
br i1 %258, label %259, label %283
259: ; preds = %253
%260 = load i32, i32* %5
%261 = load i32, i32* %5
%262 = srem i32 %261, 4
%263 = sub nsw i32 4, %262
%264 = add nsw i32 %260, %263
store i32 %264, i32* %15
%265 = load i32, i32* %15
%266 = load i32, i32* %12
%267 = load i32, i32* %15
%268 = load i32, i32* %12
%269 = sub nsw i32 %267, %268
%270 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %265, i32 %266, i32 %269)
%271 = load i32, i32* %3
%272 = load i32, i32* %15
%273 = load i32, i32* %12
%274 = sub nsw i32 %272, %273
%275 = load i32, i32* @SEEK_CUR
%276 = call i64 @lseek(i32 %271, i32 %274, i32 %275)
%277 = load i32, i32* %5
%278 = add nsw i32 70, %277
%279 = load i32, i32* %15
%280 = add nsw i32 %278, %279
%281 = load i32, i32* %12
%282 = sub nsw i32 %280, %281
store i32 %282, i32* %2
br label %286
283: ; preds = %253
%284 = load i32, i32* %5
%285 = add nsw i32 70, %284
store i32 %285, i32* %2
br label %286
286: ; preds = %283, %259, %190
%287 = load i32, i32* %2
ret i32 %287
}

LLVM IR (-O2):
@.str = [17 x i8] c"new entry at %x\0A\00"
@SEEK_CUR = global i32 0
@.str.1 = [32 x i8] c"entry %x: %s size: %x %d/%d/%d\0A\00"
@.str.2 = [5 x i8] c".wav\00"
@.str.3 = [19 x i8] c"Writing out %s...\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.4 = [26 x i8] c"aligned: %d, pos: %d, %d\0A\00"
define i32 @read_entry(i32 %0) {
%2 = alloca [14 x i8]
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @SEEK_CUR
%7 = tail call i64 @lseek(i32 %0, i32 0, i32 %6)
%8 = trunc i64 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @read(i32 %0, i8* %5, i32 70)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 3
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
br i1 %13, label %85, label %16
16: ; preds = %1
%17 = shl nsw i32 %15, 16
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 1
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = shl nuw i32 %20, 24
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = sext i8 %12 to i32
%26 = shl nsw i32 %25, 8
%27 = or i32 %17, %26
%28 = or i32 %27, %21
%29 = or i32 %28, %24
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = shl nsw i32 %32, 16
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 5
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = shl nuw i32 %36, 24
%38 = or i32 %37, %33
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 6
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = or i32 %38, %41
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 7
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = shl nsw i32 %45, 8
%47 = or i32 %42, %46
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 8
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = shl nsw i32 %50, 16
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 9
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = shl nuw i32 %54, 24
%56 = or i32 %55, %51
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 10
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = or i32 %56, %59
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 11
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = shl nsw i32 %63, 8
%65 = or i32 %60, %64
%66 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 12
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = shl nsw i32 %68, 16
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 13
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = shl nuw i32 %72, 24
%74 = or i32 %73, %69
%75 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 14
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = or i32 %74, %77
%79 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 15
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = shl nsw i32 %81, 8
%83 = or i32 %78, %82
%84 = add nsw i32 %29, 2
br label %150
85: ; preds = %1
%86 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 1
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = shl nsw i32 %88, 8
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 2
%91 = load i8, i8* %90
%92 = sext i8 %91 to i32
%93 = shl nsw i32 %92, 16
%94 = or i32 %89, %15
%95 = or i32 %94, %93
%96 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 4
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 5
%100 = load i8, i8* %99
%101 = sext i8 %100 to i32
%102 = shl nsw i32 %101, 8
%103 = or i32 %102, %98
%104 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 6
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = shl nsw i32 %106, 16
%108 = or i32 %103, %107
%109 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 7
%110 = load i8, i8* %109
%111 = zext i8 %110 to i32
%112 = shl nuw i32 %111, 24
%113 = or i32 %108, %112
%114 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 8
%115 = load i8, i8* %114
%116 = sext i8 %115 to i32
%117 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 9
%118 = load i8, i8* %117
%119 = sext i8 %118 to i32
%120 = shl nsw i32 %119, 8
%121 = or i32 %120, %116
%122 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 10
%123 = load i8, i8* %122
%124 = sext i8 %123 to i32
%125 = shl nsw i32 %124, 16
%126 = or i32 %121, %125
%127 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 11
%128 = load i8, i8* %127
%129 = zext i8 %128 to i32
%130 = shl nuw i32 %129, 24
%131 = or i32 %126, %130
%132 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 12
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 13
%136 = load i8, i8* %135
%137 = sext i8 %136 to i32
%138 = shl nsw i32 %137, 8
%139 = or i32 %138, %134
%140 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 14
%141 = load i8, i8* %140
%142 = sext i8 %141 to i32
%143 = shl nsw i32 %142, 16
%144 = or i32 %139, %143
%145 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 15
%146 = load i8, i8* %145
%147 = zext i8 %146 to i32
%148 = shl nuw i32 %147, 24
%149 = or i32 %144, %148
br label %150
150: ; preds = %85, %16
%151 = phi i64 [ 50, %85 ], [ 52, %16 ]
%152 = phi i32 [ %131, %85 ], [ %65, %16 ]
%153 = phi i32 [ %149, %85 ], [ %83, %16 ]
%154 = phi i32 [ %113, %85 ], [ %47, %16 ]
%155 = phi i32 [ %95, %85 ], [ %84, %16 ]
%156 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %151
%157 = call i32 @strncpy(i8* %4, i8* %156, i32 14)
%158 = icmp eq i32 %155, 0
br i1 %158, label %203, label %159
159: ; preds = %150
%160 = load i32, i32* @SEEK_CUR
%161 = call i64 @lseek(i32 %0, i32 0, i32 %160)
%162 = trunc i64 %161 to i32
%163 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %162, i8* %4, i32 %155, i32 %154, i32 %152, i32 %153)
%164 = call i32 @strncpy(i8* %5, i8* %4, i32 14)
%165 = call i8* @strrchr(i8* %5, i8 signext 46)
%166 = icmp eq i8* %165, null
br i1 %166, label %169, label %167
167: ; preds = %159
%168 = call i32 @strncpy(i8* %165, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
br label %169
169: ; preds = %167, %159
%170 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%171 = load i32, i32* @O_WRONLY
%172 = load i32, i32* @O_CREAT
%173 = or i32 %172, %171
%174 = call i32 @open(i8* %5, i32 %173, i32 438)
%175 = call i32 @put_wav_header(i32 %174, i32 %154, i32 %152, i32 %153, i32 %155)
%176 = icmp sgt i32 %155, 0
br i1 %176, label %177, label %186
177: ; preds = %169, %177
%178 = phi i32 [ %184, %177 ], [ 0, %169 ]
%179 = sub nsw i32 %155, %178
%180 = icmp slt i32 %179, 512
%181 = select i1 %180, i32 %179, i32 512
%182 = call i32 @read(i32 %0, i8* %5, i32 %181)
%183 = call i32 @write(i32 %174, i8* %5, i32 %182)
%184 = add nsw i32 %182, %178
%185 = icmp sgt i32 %155, %184
br i1 %185, label %177, label %186
186: ; preds = %177, %169
%187 = phi i32 [ 0, %169 ], [ %184, %177 ]
%188 = call i32 @close(i32 %174)
%189 = srem i32 %155, 4
%190 = icmp eq i32 %189, 0
br i1 %190, label %201, label %191
191: ; preds = %186
%192 = sub nsw i32 4, %189
%193 = add nsw i32 %192, %155
%194 = sub nsw i32 %193, %187
%195 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %193, i32 %187, i32 %194)
%196 = load i32, i32* @SEEK_CUR
%197 = call i64 @lseek(i32 %0, i32 %194, i32 %196)
%198 = add nsw i32 %155, 70
%199 = add nsw i32 %198, %193
%200 = sub i32 %199, %187
br label %203
201: ; preds = %186
%202 = add nsw i32 %155, 70
br label %203
203: ; preds = %150, %201, %191
%204 = phi i32 [ %200, %191 ], [ %202, %201 ], [ -1, %150 ]
ret i32 %204
}