#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*/ uint16_t;
typedef int /*<<< orphan*/ scanline;
typedef int /*<<< orphan*/ samples;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *audio;
  FILE *video;
  FILE *out;
  uint16_t scanline[(128 * 2)];
  uint16_t samples[(12 * 2)];
  int i;
  if (argc > 4)
    exit(1);
  video = fopen(argv[1], "r+");
  if (video == NULL) {
    fprintf(stderr, "[%s]: ", argv[1]);
    perror("file open failed");
    exit(1);
  }
  audio = fopen(argv[2], "r+");
  if (audio == NULL) {
    fprintf(stderr, "[%s]: ", argv[2]);
    perror("file open failed");
    exit(1);
  }
  out = fopen(argv[3], "w");
  if (out == NULL) {
    fprintf(stderr, "[%s]: ", argv[3]);
    perror("file open failed");
    exit(1);
  }
  for (i = 0; i < 96; i++)
    fread(scanline, sizeof(scanline), 1, video);
  while (1) {
    if (fread(scanline, sizeof(scanline), 1, video) == 0)
      break;
    if (fread(samples, sizeof(samples), 1, audio) == 0)
      break;
    fwrite(scanline, sizeof(scanline), 1, out);
    fwrite(samples, sizeof(samples), 1, out);
  }
  fclose(video);
  fclose(audio);
  fclose(out);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    119d <main+0x2d>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe54(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <main+0x83>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2b(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe26(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdfe(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1249 <main+0xd9>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdd5(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xdd0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdc3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    129f <main+0x12f>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xd7f(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xd7a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x494(%rbp)
cmpl   $0x60,-0x494(%rbp)
jge    12e4 <main+0x174>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x400,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x494(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x494(%rbp)
jmp    12a9 <main+0x139>
jmp    12e9 <main+0x179>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x400,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    1312 <main+0x1a2>
jmp    1374 <main+0x204>
lea    -0x490(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x60,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    133b <main+0x1cb>
jmp    1374 <main+0x204>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x400,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
lea    -0x490(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x60,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
jmp    12e9 <main+0x179>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x468,%rsp
cmp    $0x5,%edi
jl     1190 <main+0x20>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rsi,%r12
mov    0x8(%rsi),%rdi
lea    0xe62(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11b8 <main+0x48>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%rdx
jmp    1208 <main+0x98>
mov    %rax,%r14
mov    0x10(%r12),%rdi
lea    0xe39(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11e1 <main+0x71>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r12),%rdx
jmp    1208 <main+0x98>
mov    %rax,%rbx
mov    0x18(%r12),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    122a <main+0xba>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x18(%r12),%rdx
lea    0xdf4(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xdef(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rax,%r15
mov    %rbx,%r12
mov    $0x60,%ebp
lea    0x60(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
add    $0xffffffff,%ebp
jne    1240 <main+0xd0>
lea    0x60(%rsp),%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
mov    %r12,%rbx
je     12ee <main+0x17e>
mov    %rsp,%r12
lea    0x60(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x60,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12ee <main+0x17e>
mov    %r13,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    %r12,%rdi
mov    $0x60,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    %r13,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    1290 <main+0x120>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@stderr = global i32 0
@.str.1 = [7 x i8] c"[%s]: \00"
@.str.2 = [17 x i8] c"file open failed\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [256 x i32]
%10 = alloca [24 x i32]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %31
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %16
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %35, i32** %6
%36 = load i32*, i32** %6
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %46
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %31
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %50, i32** %8
%51 = load i32*, i32** %8
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %61
53: ; preds = %46
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 3
%57 = load i8*, i8** %56
%58 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %57)
%59 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %46
store i32 0, i32* %11
br label %62
62: ; preds = %69, %61
%63 = load i32, i32* %11
%64 = icmp slt i32 %63, 96
br i1 %64, label %65, label %72
65: ; preds = %62
%66 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 0
%67 = load i32*, i32** %7
%68 = call i64 @fread(i32* %66, i32 1024, i32 1, i32* %67)
br label %69
69: ; preds = %65
%70 = load i32, i32* %11
%71 = add nsw i32 %70, 1
store i32 %71, i32* %11
br label %62
72: ; preds = %62
br label %73
73: ; preds = %72, %85
%74 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 0
%75 = load i32*, i32** %7
%76 = call i64 @fread(i32* %74, i32 1024, i32 1, i32* %75)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %73
br label %92
79: ; preds = %73
%80 = getelementptr inbounds [24 x i32], [24 x i32]* %10, i64 0, i64 0
%81 = load i32*, i32** %6
%82 = call i64 @fread(i32* %80, i32 96, i32 1, i32* %81)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %79
br label %92
85: ; preds = %79
%86 = getelementptr inbounds [256 x i32], [256 x i32]* %9, i64 0, i64 0
%87 = load i32*, i32** %8
%88 = call i32 @fwrite(i32* %86, i32 1024, i32 1, i32* %87)
%89 = getelementptr inbounds [24 x i32], [24 x i32]* %10, i64 0, i64 0
%90 = load i32*, i32** %8
%91 = call i32 @fwrite(i32* %89, i32 96, i32 1, i32* %90)
br label %73
92: ; preds = %84, %78
%93 = load i32*, i32** %7
%94 = call i32 @fclose(i32* %93)
%95 = load i32*, i32** %6
%96 = call i32 @fclose(i32* %95)
%97 = load i32*, i32** %8
%98 = call i32 @fclose(i32* %97)
%99 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@stderr = global i32 0
@.str.1 = [7 x i8] c"[%s]: \00"
@.str.2 = [17 x i8] c"file open failed\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i32]
%4 = alloca [24 x i32]
%5 = bitcast [256 x i32]* %3 to i8*
%6 = bitcast [24 x i32]* %4 to i8*
%7 = icmp sgt i32 %0, 4
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %11
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %10
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %22
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %21
%33 = getelementptr inbounds i8*, i8** %1, i64 3
%34 = load i8*, i8** %33
%35 = tail call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %39, label %37
37: ; preds = %32
%38 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 0
br label %49
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %33
%42 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %49
%46 = getelementptr inbounds [24 x i32], [24 x i32]* %4, i64 0, i64 0
%47 = call i64 @fread(i32* %38, i32 1024, i32 1, i32* %13)
%48 = icmp eq i64 %47, 0
br i1 %48, label %62, label %54
49: ; preds = %37, %49
%50 = phi i32 [ 0, %37 ], [ %52, %49 ]
%51 = call i64 @fread(i32* %38, i32 1024, i32 1, i32* %13)
%52 = add nuw nsw i32 %50, 1
%53 = icmp eq i32 %52, 96
br i1 %53, label %45, label %49
54: ; preds = %45, %57
%55 = call i64 @fread(i32* %46, i32 96, i32 1, i32* %24)
%56 = icmp eq i64 %55, 0
br i1 %56, label %62, label %57
57: ; preds = %54
%58 = call i32 @fwrite(i32* %38, i32 1024, i32 1, i32* %35)
%59 = call i32 @fwrite(i32* %46, i32 96, i32 1, i32* %35)
%60 = call i64 @fread(i32* %38, i32 1024, i32 1, i32* %13)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %54
62: ; preds = %57, %54, %45
%63 = tail call i32 @fclose(i32* %13)
%64 = tail call i32 @fclose(i32* %24)
%65 = tail call i32 @fclose(i32* %35)
%66 = tail call i32 @exit(i32 0)
unreachable
}