#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*/ vbuf;
typedef long long uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ die(char *, ...);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fpa, *fpv, *fout;
  unsigned char header[5], header2[5];
  unsigned char vbuf[65536], abuf[65536];
  unsigned int usec;
  uint64_t elapsed_usec = 0LL;
  unsigned int target_samples, elapsed_samples = 0;
  unsigned int samples;
  size_t n, size;
  fpv = fopen("myvideo.bin", "rb");
  if (!fpv)
    die("unable to read %s\n", "myvideo.bin");
  fpa = fopen("myvideo.raw", "rb");
  if (!fpa)
    die("unable to read %s\n", "myvideo.raw");
  fout = fopen("VIDEO.BIN", "wb");
  if (!fout)
    die("unable to write %s\n", "VIDEO.BIN");
  while (!feof(fpv)) {
    n = fread(header, 1, 5, fpv);
    if (n != 5) {
      if (feof(fpv))
        break;
      die("unable to read video header");
    }
    if (header[0] == '*') {
      size = (header[1] | (header[2] << 8)) * 3;
      usec = header[3] | (header[4] << 8);
      if (size > sizeof(vbuf))
        die("vbuf not big enough");
      n = fread(vbuf, 1, size, fpv);
      if (n != size)
        die("unable to read video data");
      printf("v: %u %u", (int)size, usec);
      if (usec == 0xFFFF)
        die("opps");
      elapsed_usec += usec;
      target_samples = ((uint64_t)elapsed_usec *
                        (uint64_t)(44117.64706 * 1000.0) / 1000000000LL);
      target_samples += 2560;
      samples = (target_samples - elapsed_samples + 127) / 128 * 128;
      elapsed_samples += samples;
      printf(", s=%u, n=%u", target_samples, samples);
      n = fread(abuf, 1, samples * 2, fpa);
      if (n < samples * 2) {
        printf(", n(audio) = %d", (int)n);
        n &= ~1;
      }
      header2[0] = '%';
      header2[1] = samples & 255;
      header2[2] = samples >> 8;
      header2[3] = 0;
      header2[4] = 0;
      fwrite(header2, 1, 5, fout);
      fwrite(abuf, 2, samples, fout);
      fwrite(header, 1, 5, fout);
      fwrite(vbuf, 1, size, fout);
    } else if (header[0] == '%') {
      size = (header[1] | (header[2] << 8)) * 3;
      n = fread(vbuf, 1, size, fpv);
      if (n != size)
        die("unable to read video data");
    } else {
      die("unknown header type");
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20060,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20040(%rbp)
movl   $0x0,-0x20048(%rbp)
lea    0xe72(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11be <main+0x5e>
lea    0xe5f(%rip),%rdi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1070 <die@plt>
lea    0xe5d(%rip),%rdi
lea    0xe40(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f5 <main+0x95>
lea    0xe28(%rip),%rdi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1070 <die@plt>
lea    0xe32(%rip),%rdi
lea    0xe35(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122c <main+0xcc>
lea    0xe1d(%rip),%rdi
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1070 <die@plt>
jmp    1231 <main+0xd1>
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1250 <main+0xf0>
jmp    1596 <main+0x436>
lea    -0x25(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <fread@plt>
mov    %rax,-0x20058(%rbp)
cmpq   $0x5,-0x20058(%rbp)
05
je     12a2 <main+0x142>
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     1294 <main+0x134>
jmp    1596 <main+0x436>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
movzbl -0x25(%rbp),%eax
cmp    $0x2a,%eax
jne    1500 <main+0x3a0>
movzbl -0x24(%rbp),%eax
movzbl -0x23(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
imul   $0x3,%eax,%eax
cltq
mov    %rax,-0x20060(%rbp)
movzbl -0x22(%rbp),%eax
movzbl -0x21(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x20034(%rbp)
cmpq   $0x10000,-0x20060(%rbp)
jbe    12fa <main+0x19a>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
lea    -0x10030(%rbp),%rdi
mov    -0x20060(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x20058(%rbp)
mov    -0x20058(%rbp),%rax
cmp    -0x20060(%rbp),%rax
je     133f <main+0x1df>
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
mov    -0x20060(%rbp),%rax
mov    %eax,%esi
mov    -0x20034(%rbp),%edx
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xffff,-0x20034(%rbp)
jne    137a <main+0x21a>
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
mov    -0x20034(%rbp),%eax
add    -0x20040(%rbp),%rax
mov    %rax,-0x20040(%rbp)
imul   $0x2a12e8f,-0x20040(%rbp),%rax
8f 2e a1 02
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %eax,-0x20044(%rbp)
mov    -0x20044(%rbp),%eax
add    $0xa00,%eax
mov    %eax,-0x20044(%rbp)
mov    -0x20044(%rbp),%eax
sub    -0x20048(%rbp),%eax
add    $0x7f,%eax
shr    $0x7,%eax
shl    $0x7,%eax
mov    %eax,-0x2004c(%rbp)
mov    -0x2004c(%rbp),%eax
add    -0x20048(%rbp),%eax
mov    %eax,-0x20048(%rbp)
mov    -0x20044(%rbp),%esi
mov    -0x2004c(%rbp),%edx
lea    0xcad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20030(%rbp),%rdi
mov    -0x2004c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,%eax
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x20058(%rbp)
mov    -0x20058(%rbp),%rax
mov    -0x2004c(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,%ecx
cmp    %rcx,%rax
jae    146e <main+0x30e>
mov    -0x20058(%rbp),%rax
mov    %eax,%esi
lea    0xc5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20058(%rbp),%rax
and    $0xfffffffffffffffe,%rax
mov    %rax,-0x20058(%rbp)
movb   $0x25,-0x2a(%rbp)
mov    -0x2004c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x29(%rbp)
mov    -0x2004c(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x28(%rbp)
movb   $0x0,-0x27(%rbp)
movb   $0x0,-0x26(%rbp)
lea    -0x2a(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1080 <fwrite@plt>
lea    -0x20030(%rbp),%rdi
mov    -0x2004c(%rbp),%eax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x2,%esi
call   1080 <fwrite@plt>
lea    -0x25(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1080 <fwrite@plt>
lea    -0x10030(%rbp),%rdi
mov    -0x20060(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
jmp    1583 <main+0x423>
movzbl -0x25(%rbp),%eax
cmp    $0x25,%eax
jne    1570 <main+0x410>
movzbl -0x24(%rbp),%eax
movzbl -0x23(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
imul   $0x3,%eax,%eax
cltq
mov    %rax,-0x20060(%rbp)
lea    -0x10030(%rbp),%rdi
mov    -0x20060(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x20058(%rbp)
mov    -0x20058(%rbp),%rax
cmp    -0x20060(%rbp),%rax
je     156b <main+0x40b>
lea    0xb1b(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
jmp    157e <main+0x41e>
lea    0xb4d(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
jmp    1583 <main+0x423>
lea    0xa96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1231 <main+0xd1>
xor    %eax,%eax
add    $0x20060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20028,%rsp
lea    0xe78(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11b1 <main+0x41>
lea    0xe6c(%rip),%rdi
lea    0xe56(%rip),%rsi
xor    %eax,%eax
call   1080 <die@plt>
lea    0xe6a(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
jne    11e3 <main+0x73>
lea    0xe3a(%rip),%rdi
lea    0xe46(%rip),%rsi
xor    %eax,%eax
call   1080 <die@plt>
lea    0xe44(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1213 <main+0xa3>
lea    0xe36(%rip),%rdi
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1080 <die@plt>
mov    %r13,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     1234 <main+0xc4>
xor    %eax,%eax
add    $0x20028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x2(%rsp),%rbp
xor    %eax,%eax
mov    %rax,0x10(%rsp)
movl   $0x0,0xc(%rsp)
jmp    12e3 <main+0x173>
nopl   (%rax)
add    %ebp,0xc(%rsp)
movb   $0x25,0x7(%rsp)
and    $0x80,%bl
mov    %bl,0x8(%rsp)
mov    %bh,0x9(%rsp)
movw   $0x0,0xa(%rsp)
mov    $0x5,%edx
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    %ebp,%edx
lea    0x10020(%rsp),%rdi
mov    $0x2,%esi
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    $0x5,%edx
lea    0x2(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1220 <main+0xb0>
mov    $0x5,%edx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r13,%rcx
call   1040 <fread@plt>
cmp    $0x5,%rax
je     131d <main+0x1ad>
mov    %r13,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1220 <main+0xb0>
lea    0xd39(%rip),%rdi
xor    %eax,%eax
call   1080 <die@plt>
movzbl 0x2(%rsp),%eax
cmp    $0x25,%al
je     1440 <main+0x2d0>
cmp    $0x2a,%al
jne    1470 <main+0x300>
movzwl 0x3(%rsp),%eax
lea    (%rax,%rax,2),%r12
movzwl 0x5(%rsp),%r14d
cmp    $0x10001,%r12d
jb     1358 <main+0x1e8>
lea    0xd1a(%rip),%rdi
xor    %eax,%eax
call   1080 <die@plt>
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <fread@plt>
cmp    %r12,%rax
je     1380 <main+0x210>
lea    0xd06(%rip),%rdi
xor    %eax,%eax
call   1080 <die@plt>
lea    0xd12(%rip),%rdi
mov    %r12d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffff,%r14d
jne    13ab <main+0x23b>
lea    0xcfe(%rip),%rdi
xor    %eax,%eax
call   1080 <die@plt>
mov    0x10(%rsp),%rcx
add    %r14,%rcx
mov    %rcx,0x10(%rsp)
imul   $0x2a12e8f,%rcx,%rax
movabs $0x112e0be826d694b3,%rcx
0b 2e 11
imul   %rcx
mov    %rdx,%rax
shr    $0x1a,%rax
shr    $0x3f,%rdx
lea    (%rax,%rdx,1),%esi
add    $0xa00,%esi
mov    %esi,%ebx
sub    0xc(%rsp),%ebx
add    $0x7f,%ebx
mov    %ebx,%ebp
and    $0xffffff80,%ebp
lea    0xcb2(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x0(%rbp,%rbp,1),%r14d
lea    0x10020(%rsp),%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    0x18(%rsp),%rcx
call   1040 <fread@plt>
cmp    %r14,%rax
jae    1250 <main+0xe0>
lea    0xc87(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1250 <main+0xe0>
nopl   0x0(%rax,%rax,1)
movzwl 0x3(%rsp),%eax
lea    (%rax,%rax,2),%rbx
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1040 <fread@plt>
cmp    %rbx,%rax
je     12c8 <main+0x158>
lea    0xc11(%rip),%rdi
jmp    1477 <main+0x307>
lea    0xc4d(%rip),%rdi
xor    %eax,%eax
call   1080 <die@plt>
jmp    12c8 <main+0x158>

LLVM IR (-O0):
@.str = [12 x i8] c"myvideo.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"unable to read %s\0A\00"
@.str.3 = [12 x i8] c"myvideo.raw\00"
@.str.4 = [10 x i8] c"VIDEO.BIN\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [20 x i8] c"unable to write %s\0A\00"
@.str.7 = [28 x i8] c"unable to read video header\00"
@.str.8 = [20 x i8] c"vbuf not big enough\00"
@.str.9 = [26 x i8] c"unable to read video data\00"
@.str.10 = [9 x i8] c"v: %u %u\00"
@.str.11 = [5 x i8] c"opps\00"
@.str.12 = [13 x i8] c", s=%u, n=%u\00"
@.str.13 = [16 x i8] c", n(audio) = %d\00"
@.str.14 = [20 x i8] c"unknown header type\00"
@.str.15 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [5 x i8]
%6 = alloca [5 x i8]
%7 = alloca [65536 x i8]
%8 = alloca [65536 x i8]
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %10
store i32 0, i32* %12
%16 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %3
%17 = load i32*, i32** %3
%18 = icmp ne i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %0
%20 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %0
%22 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %2
%23 = load i32*, i32** %2
%24 = icmp ne i32* %23, null
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %28, i32** %4
%29 = load i32*, i32** %4
%30 = icmp ne i32* %29, null
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
br label %34
34: ; preds = %195, %33
%35 = load i32*, i32** %3
%36 = call i64 @feof(i32* %35)
%37 = icmp ne i64 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %197
39: ; preds = %34
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%41 = load i32*, i32** %3
%42 = call i64 @fread(i8* %40, i32 1, i64 5, i32* %41)
store i64 %42, i64* %14
%43 = load i64, i64* %14
%44 = icmp ne i64 %43, 5
br i1 %44, label %45, label %52
45: ; preds = %39
%46 = load i32*, i32** %3
%47 = call i64 @feof(i32* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %45
br label %197
50: ; preds = %45
%51 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %52
52: ; preds = %50, %39
%53 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %55, 42
br i1 %56, label %57, label %166
57: ; preds = %52
%58 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 1
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 2
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = shl i32 %63, 8
%65 = or i32 %60, %64
%66 = mul nsw i32 %65, 3
%67 = sext i32 %66 to i64
store i64 %67, i64* %15
%68 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 3
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 4
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = shl i32 %73, 8
%75 = or i32 %70, %74
store i32 %75, i32* %9
%76 = load i64, i64* %15
%77 = icmp ugt i64 %76, 65536
br i1 %77, label %78, label %80
78: ; preds = %57
%79 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %80
80: ; preds = %78, %57
%81 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%82 = load i64, i64* %15
%83 = load i32*, i32** %3
%84 = call i64 @fread(i8* %81, i32 1, i64 %82, i32* %83)
store i64 %84, i64* %14
%85 = load i64, i64* %14
%86 = load i64, i64* %15
%87 = icmp ne i64 %85, %86
br i1 %87, label %88, label %90
88: ; preds = %80
%89 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %90
90: ; preds = %88, %80
%91 = load i64, i64* %15
%92 = trunc i64 %91 to i32
%93 = load i32, i32* %9
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i32 %92, i32 %93)
%95 = load i32, i32* %9
%96 = icmp eq i32 %95, 65535
br i1 %96, label %97, label %99
97: ; preds = %90
%98 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %99
99: ; preds = %97, %90
%100 = load i32, i32* %9
%101 = zext i32 %100 to i64
%102 = load i64, i64* %10
%103 = add nsw i64 %102, %101
store i64 %103, i64* %10
%104 = load i64, i64* %10
%105 = mul nsw i64 %104, 44117647
%106 = sdiv i64 %105, 1000000000
%107 = trunc i64 %106 to i32
store i32 %107, i32* %11
%108 = load i32, i32* %11
%109 = add i32 %108, 2560
store i32 %109, i32* %11
%110 = load i32, i32* %11
%111 = load i32, i32* %12
%112 = sub i32 %110, %111
%113 = add i32 %112, 127
%114 = udiv i32 %113, 128
%115 = mul i32 %114, 128
store i32 %115, i32* %13
%116 = load i32, i32* %13
%117 = load i32, i32* %12
%118 = add i32 %117, %116
store i32 %118, i32* %12
%119 = load i32, i32* %11
%120 = load i32, i32* %13
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 %119, i32 %120)
%122 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%123 = load i32, i32* %13
%124 = mul i32 %123, 2
%125 = zext i32 %124 to i64
%126 = load i32*, i32** %2
%127 = call i64 @fread(i8* %122, i32 1, i64 %125, i32* %126)
store i64 %127, i64* %14
%128 = load i64, i64* %14
%129 = load i32, i32* %13
%130 = mul i32 %129, 2
%131 = zext i32 %130 to i64
%132 = icmp ult i64 %128, %131
br i1 %132, label %133, label %139
133: ; preds = %99
%134 = load i64, i64* %14
%135 = trunc i64 %134 to i32
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %135)
%137 = load i64, i64* %14
%138 = and i64 %137, -2
store i64 %138, i64* %14
br label %139
139: ; preds = %133, %99
%140 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
store i8 37, i8* %140
%141 = load i32, i32* %13
%142 = and i32 %141, 255
%143 = trunc i32 %142 to i8
%144 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 1
store i8 %143, i8* %144
%145 = load i32, i32* %13
%146 = lshr i32 %145, 8
%147 = trunc i32 %146 to i8
%148 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 2
store i8 %147, i8* %148
%149 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 3
store i8 0, i8* %149
%150 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 4
store i8 0, i8* %150
%151 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%152 = load i32*, i32** %4
%153 = call i32 @fwrite(i8* %151, i32 1, i64 5, i32* %152)
%154 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%155 = load i32, i32* %13
%156 = zext i32 %155 to i64
%157 = load i32*, i32** %4
%158 = call i32 @fwrite(i8* %154, i32 2, i64 %156, i32* %157)
%159 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%160 = load i32*, i32** %4
%161 = call i32 @fwrite(i8* %159, i32 1, i64 5, i32* %160)
%162 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%163 = load i64, i64* %15
%164 = load i32*, i32** %4
%165 = call i32 @fwrite(i8* %162, i32 1, i64 %163, i32* %164)
br label %195
166: ; preds = %52
%167 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%168 = load i8, i8* %167
%169 = zext i8 %168 to i32
%170 = icmp eq i32 %169, 37
br i1 %170, label %171, label %192
171: ; preds = %166
%172 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 1
%173 = load i8, i8* %172
%174 = zext i8 %173 to i32
%175 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 2
%176 = load i8, i8* %175
%177 = zext i8 %176 to i32
%178 = shl i32 %177, 8
%179 = or i32 %174, %178
%180 = mul nsw i32 %179, 3
%181 = sext i32 %180 to i64
store i64 %181, i64* %15
%182 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%183 = load i64, i64* %15
%184 = load i32*, i32** %3
%185 = call i64 @fread(i8* %182, i32 1, i64 %183, i32* %184)
store i64 %185, i64* %14
%186 = load i64, i64* %14
%187 = load i64, i64* %15
%188 = icmp ne i64 %186, %187
br i1 %188, label %189, label %191
189: ; preds = %171
%190 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %191
191: ; preds = %189, %171
br label %194
192: ; preds = %166
%193 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0))
br label %194
194: ; preds = %192, %191
br label %195
195: ; preds = %194, %139
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %34
197: ; preds = %49, %34
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"myvideo.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"unable to read %s\0A\00"
@.str.3 = [12 x i8] c"myvideo.raw\00"
@.str.4 = [10 x i8] c"VIDEO.BIN\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [20 x i8] c"unable to write %s\0A\00"
@.str.7 = [28 x i8] c"unable to read video header\00"
@.str.8 = [20 x i8] c"vbuf not big enough\00"
@.str.9 = [26 x i8] c"unable to read video data\00"
@.str.10 = [9 x i8] c"v: %u %u\00"
@.str.11 = [5 x i8] c"opps\00"
@.str.12 = [13 x i8] c", s=%u, n=%u\00"
@.str.13 = [16 x i8] c", n(audio) = %d\00"
@.str.14 = [20 x i8] c"unknown header type\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = alloca [5 x i8]
%3 = alloca [65536 x i8]
%4 = alloca [65536 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = tail call i64 @feof(i32* %9)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %124
26: ; preds = %23
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 1
%28 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 2
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 3
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 4
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 1
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 3
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
br label %35
35: ; preds = %26, %118
%36 = phi i64 [ 0, %26 ], [ %120, %118 ]
%37 = phi i32 [ 0, %26 ], [ %119, %118 ]
%38 = call i64 @fread(i8* %5, i32 1, i64 5, i32* %9)
%39 = icmp eq i64 %38, 5
br i1 %39, label %45, label %40
40: ; preds = %35
%41 = tail call i64 @feof(i32* %9)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %124
43: ; preds = %40
%44 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %43, %35
%46 = load i8, i8* %5
switch i8 %46, label %116 [
i8 42, label %47
i8 37, label %104
]
47: ; preds = %45
%48 = load i8, i8* %27
%49 = zext i8 %48 to i32
%50 = load i8, i8* %28
%51 = zext i8 %50 to i32
%52 = shl nuw nsw i32 %51, 8
%53 = or i32 %52, %49
%54 = mul nuw nsw i32 %53, 3
%55 = zext i32 %54 to i64
%56 = load i8, i8* %29
%57 = zext i8 %56 to i32
%58 = load i8, i8* %30
%59 = zext i8 %58 to i32
%60 = shl nuw nsw i32 %59, 8
%61 = or i32 %60, %57
%62 = icmp ugt i32 %54, 65536
br i1 %62, label %63, label %65
63: ; preds = %47
%64 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
br label %65
65: ; preds = %63, %47
%66 = call i64 @fread(i8* %7, i32 1, i64 %55, i32* %9)
%67 = icmp eq i64 %66, %55
br i1 %67, label %70, label %68
68: ; preds = %65
%69 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %70
70: ; preds = %68, %65
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i32 %54, i32 %61)
%72 = icmp eq i32 %61, 65535
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %75
75: ; preds = %73, %70
%76 = zext i32 %61 to i64
%77 = add nsw i64 %36, %76
%78 = mul nsw i64 %77, 44117647
%79 = sdiv i64 %78, 1000000000
%80 = trunc i64 %79 to i32
%81 = add i32 %80, 2560
%82 = sub i32 %81, %37
%83 = add i32 %82, 127
%84 = and i32 %83, -128
%85 = add i32 %84, %37
%86 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 %81, i32 %84)
%87 = shl i32 %84, 1
%88 = zext i32 %87 to i64
%89 = call i64 @fread(i8* %8, i32 1, i64 %88, i32* %14)
%90 = icmp ult i64 %89, %88
br i1 %90, label %91, label %94
91: ; preds = %75
%92 = trunc i64 %89 to i32
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %92)
br label %94
94: ; preds = %91, %75
store i8 37, i8* %6
%95 = trunc i32 %83 to i8
%96 = and i8 %95, -128
store i8 %96, i8* %31
%97 = lshr i32 %83, 8
%98 = trunc i32 %97 to i8
store i8 %98, i8* %32
store i8 0, i8* %33
store i8 0, i8* %34
%99 = call i32 @fwrite(i8* %6, i32 1, i64 5, i32* %19)
%100 = zext i32 %84 to i64
%101 = call i32 @fwrite(i8* %8, i32 2, i64 %100, i32* %19)
%102 = call i32 @fwrite(i8* %5, i32 1, i64 5, i32* %19)
%103 = call i32 @fwrite(i8* %7, i32 1, i64 %55, i32* %19)
br label %118
104: ; preds = %45
%105 = load i8, i8* %27
%106 = zext i8 %105 to i64
%107 = load i8, i8* %28
%108 = zext i8 %107 to i64
%109 = shl nuw nsw i64 %108, 8
%110 = or i64 %109, %106
%111 = mul nuw nsw i64 %110, 3
%112 = call i64 @fread(i8* %7, i32 1, i64 %111, i32* %9)
%113 = icmp eq i64 %112, %111
br i1 %113, label %118, label %114
114: ; preds = %104
%115 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %118
116: ; preds = %45
%117 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0))
br label %118
118: ; preds = %116, %114, %104, %94
%119 = phi i32 [ %85, %94 ], [ %37, %114 ], [ %37, %104 ], [ %37, %116 ]
%120 = phi i64 [ %77, %94 ], [ %36, %114 ], [ %36, %104 ], [ %36, %116 ]
%121 = tail call i32 @putchar(i32 10)
%122 = tail call i64 @feof(i32* %9)
%123 = icmp eq i64 %122, 0
br i1 %123, label %35, label %124
124: ; preds = %118, %40, %23
ret i32 0
}