#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  printf("BUFSIZ is %d\n", 32768);
  FILE *from, *to;
  char line[32768];
  if (argc != 3) {
    fprintf(stderr, "Usage: %s from-file to-file\n", *argv);
    exit(1);
  }
  from = fopen(argv[1], "r");
  if (from == NULL) {
    perror(argv[1]);
    exit(1);
  }
  to = fopen(argv[2], "a");
  if (to == NULL) {
    perror(argv[2]);
    exit(1);
  }
  while (fread(line, 32768, 1, from) != NULL) {
    fwrite(line, 32768, 1, to);
  }
  fclose(from);
  fclose(to);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
mov    $0x8000,%esi
call   1050 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
je     11da <main+0x5a>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1214 <main+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    124e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1253 <main+0xd3>
lea    -0x8020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x8000,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     1296 <main+0x116>
lea    -0x8020(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x8000,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
jmp    1253 <main+0xd3>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x8008,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xe66(%rip),%rdi
mov    $0x8000,%esi
call   1050 <printf@plt>
cmp    $0x3,%ebx
jne    1260 <main+0xe0>
mov    0x8(%r15),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1282 <main+0x102>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1288 <main+0x108>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x8000,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     123f <main+0xbf>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x8000,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x8000,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    1210 <main+0x90>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xd9b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%r15),%rdi
jmp    128c <main+0x10c>
mov    0x10(%r15),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"BUFSIZ is %d\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s from-file to-file\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"a\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 [32768 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 32768)
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %18
%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 ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %7
%36 = load i32*, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %31
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @perror(i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %31
br label %45
45: ; preds = %50, %44
%46 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%47 = load i32*, i32** %6
%48 = call i32* @fread(i8* %46, i32 32768, i32 1, i32* %47)
%49 = icmp ne i32* %48, null
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%52 = load i32*, i32** %7
%53 = call i32 @fwrite(i8* %51, i32 32768, i32 1, i32* %52)
br label %45
54: ; preds = %45
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"BUFSIZ is %d\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Usage: %s from-file to-file\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"a\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32768 x i8]
%4 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 32768)
%5 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32 %0, 3
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i8*, i8** %13
%19 = tail call i32 @perror(i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = call i32* @fread(i8* %5, i32 32768, i32 1, i32* %15)
%28 = icmp eq i32* %27, null
br i1 %28, label %37, label %33
29: ; preds = %21
%30 = load i8*, i8** %22
%31 = tail call i32 @perror(i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %26, %33
%34 = call i32 @fwrite(i8* %5, i32 32768, i32 1, i32* %24)
%35 = call i32* @fread(i8* %5, i32 32768, i32 1, i32* %15)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %33
37: ; preds = %33, %26
%38 = tail call i32 @fclose(i32* %15)
%39 = tail call i32 @fclose(i32* %24)
ret i32 0
}