#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 BUFSIZ;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int n;
  FILE *from, *to;
  char buf[BUFSIZ];
  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 ((n = fread(buf, sizeof(char), BUFSIZ, from)) > 0) {
    fwrite(buf, sizeof(char), n, to);
  }
  fclose(from);
  fclose(to);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e2 <main+0x72>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121c <main+0xac>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1256 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    125b <main+0xeb>
mov    -0x40(%rbp),%rdi
mov    0x2d72(%rip),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    129c <main+0x12c>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
jmp    125b <main+0xeb>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    0x2e50(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x3,%edi
jne    122d <main+0xbd>
mov    0x8(%r12),%rdi
lea    0xe6b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1250 <main+0xe0>
mov    %rax,%r14
mov    0x10(%r12),%rdi
lea    0xe50(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1257 <main+0xe7>
mov    %rax,%r15
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    120c <main+0x9c>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
jmp    11e0 <main+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xdbf(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%r12),%rdi
jmp    125c <main+0xec>
mov    0x10(%r12),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s from-file to-file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"a\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%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, 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.1, 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.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = load i32, i32* @BUFSIZ
%28 = call i32 @fread(i8* %5, i32 1, i32 %27, i32* %15)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %34, label %40
30: ; preds = %21
%31 = load i8*, i8** %22
%32 = tail call i32 @perror(i8* %31)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26, %34
%35 = phi i32 [ %38, %34 ], [ %28, %26 ]
%36 = call i32 @fwrite(i8* %5, i32 1, i32 %35, i32* %24)
%37 = load i32, i32* @BUFSIZ
%38 = call i32 @fread(i8* %5, i32 1, i32 %37, i32* %15)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %34, label %40
40: ; preds = %34, %26
%41 = tail call i32 @fclose(i32* %15)
%42 = tail call i32 @fclose(i32* %24)
ret i32 0
}