#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*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *audio;
  FILE *video;
  FILE *out;
  uint16_t scanline[(160 * 16)];
  uint16_t samples[((6 * 16))];
  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);
  }
  while (1) {
    memset(samples, 0, sizeof(samples));
    if (fread(scanline, sizeof(scanline), 1, video) == 0) {
      break;
    }
    (void)fread(samples, sizeof(samples), 1, audio);
    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    $0x29b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    11ad <main+0x2d>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe44(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1203 <main+0x83>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1b(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe16(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdee(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1259 <main+0xd9>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdc5(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xdc0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdb3(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12af <main+0x12f>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xd6f(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xd6a(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12b4 <main+0x134>
lea    -0x29b0(%rbp),%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1050 <memset@plt>
lea    -0x2830(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x2800,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jne    12f0 <main+0x170>
jmp    1343 <main+0x1c3>
lea    -0x29b0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x180,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x2830(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x2800,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
lea    -0x29b0(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x180,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
jmp    12b4 <main+0x134>
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   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2980,%rsp
cmp    $0x5,%edi
jl     119f <main+0x1f>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rsi,%r12
mov    0x8(%rsi),%rdi
lea    0xe53(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11c7 <main+0x47>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%rdx
jmp    1217 <main+0x97>
mov    %rax,%r14
mov    0x10(%r12),%rdi
lea    0xe2a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11f0 <main+0x70>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r12),%rdx
jmp    1217 <main+0x97>
mov    %rax,%r15
mov    0x18(%r12),%rdi
lea    0xe1c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    1239 <main+0xb9>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    0x18(%r12),%rdx
lea    0xde5(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xde0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rax,%r13
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1050 <memset@plt>
lea    0x180(%rsp),%rdi
mov    $0x2800,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12e8 <main+0x168>
mov    %rsp,%rbx
lea    0x180(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x180,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r12,%rdi
mov    $0x2800,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x180,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    $0x2800,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    1280 <main+0x100>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1090 <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 [2560 x i32]
%10 = alloca [96 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %30
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %15
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %34, i32** %6
%35 = load i32*, i32** %6
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %45
37: ; preds = %30
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %30
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %49, i32** %8
%50 = load i32*, i32** %8
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %60
52: ; preds = %45
%53 = load i32, i32* @stderr
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %56)
%58 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %45
br label %61
61: ; preds = %60, %69
%62 = getelementptr inbounds [96 x i32], [96 x i32]* %10, i64 0, i64 0
%63 = call i32 @memset(i32* %62, i32 0, i32 384)
%64 = getelementptr inbounds [2560 x i32], [2560 x i32]* %9, i64 0, i64 0
%65 = load i32*, i32** %7
%66 = call i64 @fread(i32* %64, i32 10240, i32 1, i32* %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %61
br label %79
69: ; preds = %61
%70 = getelementptr inbounds [96 x i32], [96 x i32]* %10, i64 0, i64 0
%71 = load i32*, i32** %6
%72 = call i64 @fread(i32* %70, i32 384, i32 1, i32* %71)
%73 = getelementptr inbounds [2560 x i32], [2560 x i32]* %9, i64 0, i64 0
%74 = load i32*, i32** %8
%75 = call i32 @fwrite(i32* %73, i32 10240, i32 1, i32* %74)
%76 = getelementptr inbounds [96 x i32], [96 x i32]* %10, i64 0, i64 0
%77 = load i32*, i32** %8
%78 = call i32 @fwrite(i32* %76, i32 384, i32 1, i32* %77)
br label %61
79: ; preds = %68
%80 = load i32*, i32** %7
%81 = call i32 @fclose(i32* %80)
%82 = load i32*, i32** %6
%83 = call i32 @fclose(i32* %82)
%84 = load i32*, i32** %8
%85 = call i32 @fclose(i32* %84)
%86 = 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 [2560 x i32]
%4 = alloca [96 x i32]
%5 = bitcast [2560 x i32]* %3 to i8*
%6 = bitcast [96 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 %43, label %37
37: ; preds = %32
%38 = getelementptr inbounds [96 x i32], [96 x i32]* %4, i64 0, i64 0
%39 = call i32 @memset(i32* %38, i32 0, i32 384)
%40 = getelementptr inbounds [2560 x i32], [2560 x i32]* %3, i64 0, i64 0
%41 = call i64 @fread(i32* %40, i32 10240, i32 1, i32* %13)
%42 = icmp eq i64 %41, 0
br i1 %42, label %56, label %49
43: ; preds = %32
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %33
%46 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %37, %49
%50 = call i64 @fread(i32* %38, i32 384, i32 1, i32* %24)
%51 = call i32 @fwrite(i32* %40, i32 10240, i32 1, i32* %35)
%52 = call i32 @fwrite(i32* %38, i32 384, i32 1, i32* %35)
%53 = call i32 @memset(i32* %38, i32 0, i32 384)
%54 = call i64 @fread(i32* %40, i32 10240, i32 1, i32* %13)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %49
56: ; preds = %49, %37
%57 = call i32 @fclose(i32* %13)
%58 = call i32 @fclose(i32* %24)
%59 = call i32 @fclose(i32* %35)
%60 = call i32 @exit(i32 0)
unreachable
}