#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ writebyte(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ writeword(int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *fpin, *fpout;
  int c;
  int i;
  int len;
  if (argc != 3) {
    fprintf(stdout, "Usage: %s [in file] [out file]\n", argv[0]);
    exit(1);
  }
  if ((fpin = fopen(argv[1], "rb")) == NULL) {
    printf("Can't open input file\n");
    exit(1);
  }
  if (fseek(fpin, 0, SEEK_END)) {
    printf("Couldn't determine size of file\n");
    fclose(fpin);
    exit(1);
  }
  len = ftell(fpin);
  fseek(fpin, 0L, SEEK_SET);
  if ((fpout = fopen(argv[2], "wb")) == NULL) {
    printf("Can't open output file\n");
    exit(1);
  }
  writeword(0x3000, fpout);
  for (i = 0; i < len; i++) {
    c = getc(fpin);
    writebyte(c, fpout);
  }
  fclose(fpin);
  fclose(fpout);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e6 <main+0x46>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe29(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121e <main+0x7e>
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     125d <main+0xbd>
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdcd(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12b7 <main+0x117>
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rsi
mov    $0x3000,%edi
call   1050 <writeword@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12fe <main+0x15e>
mov    -0x18(%rbp),%rdi
call   10c0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   10a0 <writebyte@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12cc <main+0x12c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    1274 <main+0xd4>
mov    0x8(%r14),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1296 <main+0xf6>
mov    %rax,%r15
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    129f <main+0xff>
mov    %r15,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    0x10(%r14),%rdi
lea    0xe10(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12bd <main+0x11d>
mov    %rax,%rbx
mov    $0x3000,%edi
mov    %rax,%rsi
call   1050 <writeword@plt>
test   %ebp,%ebp
jle    1257 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   10c0 <getc@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   10a0 <writebyte@plt>
add    $0xffffffff,%ebp
jne    1240 <main+0xa0>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd79(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdc0(%rip),%rdi
jmp    12c4 <main+0x124>
lea    0xd97(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd62(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [32 x i8] c"Usage: %s [in file] [out file]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"Can't open input file\0A\00"
@SEEK_END = global i32 0
@.str.3 = [33 x i8] c"Couldn't determine size of file\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [24 x i8] c"Can't open output file\0A\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 i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = load i32*, i32** %6
%31 = load i32, i32* @SEEK_END
%32 = call i64 @fseek(i32* %30, i64 0, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %29
%40 = load i32*, i32** %6
%41 = call i32 @ftell(i32* %40)
store i32 %41, i32* %10
%42 = load i32*, i32** %6
%43 = load i32, i32* @SEEK_SET
%44 = call i64 @fseek(i32* %42, i64 0, i32 %43)
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %48, i32** %7
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %53
50: ; preds = %39
%51 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %39
%54 = load i32*, i32** %7
%55 = call i32 @writeword(i32 12288, i32* %54)
store i32 0, i32* %9
br label %56
56: ; preds = %66, %53
%57 = load i32, i32* %9
%58 = load i32, i32* %10
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %69
60: ; preds = %56
%61 = load i32*, i32** %6
%62 = call i32 @getc(i32* %61)
store i32 %62, i32* %8
%63 = load i32, i32* %8
%64 = load i32*, i32** %7
%65 = call i32 @writebyte(i32 %63, i32* %64)
br label %66
66: ; preds = %60
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %56
69: ; preds = %56
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [32 x i8] c"Usage: %s [in file] [out file]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@str = [23 x i8] c"Can't open output file\00"
@str.6 = [32 x i8] c"Couldn't determine size of file\00"
@str.7 = [22 x i8] c"Can't open input file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stdout
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = load i32, i32* @SEEK_END
%19 = tail call i64 @fseek(i32* %12, i64 0, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%23 = tail call i32 @fclose(i32* %12)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = tail call i32 @ftell(i32* %12)
%27 = load i32, i32* @SEEK_SET
%28 = tail call i64 @fseek(i32* %12, i64 0, i32 %27)
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %25
%37 = tail call i32 @writeword(i32 12288, i32* %31)
%38 = icmp sgt i32 %26, 0
br i1 %38, label %39, label %45
39: ; preds = %36, %39
%40 = phi i32 [ %43, %39 ], [ 0, %36 ]
%41 = tail call i32 @getc(i32* %12)
%42 = tail call i32 @writebyte(i32 %41, i32* %31)
%43 = add nuw nsw i32 %40, 1
%44 = icmp eq i32 %43, %26
br i1 %44, label %45, label %39
45: ; preds = %39, %36
%46 = tail call i32 @fclose(i32* %12)
%47 = tail call i32 @fclose(i32* %31)
ret i32 0
}