#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int copyFileInto(const char *filename, FILE *destfile) {
  FILE *srcfile = fopen(filename, "rb");
  if (!srcfile) {
    printf("Unable to open file \"%s\"!", filename);
    return 0;
  }
  char buf[1024];
  int readsize;
  while ((readsize = fread(buf, 1, 1024, srcfile)) > 0)
    fwrite(buf, 1, readsize, destfile);
  fclose(srcfile);
  return 1;
}


x86 assembly (clang, -O0):
<copyFileInto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119e <copyFileInto+0x4e>
mov    -0x10(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <copyFileInto+0xac>
jmp    11a3 <copyFileInto+0x53>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jle    11ec <copyFileInto+0x9c>
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    11a3 <copyFileInto+0x53>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyFileInto>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d5 <copyFileInto+0x85>
mov    %rax,%rbp
mov    %rsp,%rdi
mov    $0x1,%r14d
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11cb <copyFileInto+0x7b>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11a0 <copyFileInto+0x50>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    11e7 <copyFileInto+0x97>
lea    0xe27(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [26 x i8] c"Unable to open file \22%s\22!\00"
define i32 @copyFileInto(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %3
br label %30
16: ; preds = %2
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i32 @fread(i8* %18, i32 1, i32 1024, i32* %19)
store i32 %20, i32* %8
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = load i32, i32* %8
%25 = load i32*, i32** %5
%26 = call i32 @fwrite(i8* %23, i32 1, i32 %24, i32* %25)
br label %17
27: ; preds = %17
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
store i32 1, i32* %3
br label %30
30: ; preds = %27, %13
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [26 x i8] c"Unable to open file \22%s\22!\00"
define i32 @copyFileInto(i8* %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %19
8: ; preds = %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i32 @fread(i8* %9, i32 1, i32 1024, i32* %4)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8, %12
%13 = phi i32 [ %15, %12 ], [ %10, %8 ]
%14 = call i32 @fwrite(i8* %9, i32 1, i32 %13, i32* %1)
%15 = call i32 @fread(i8* %9, i32 1, i32 1024, i32* %4)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12, %8
%18 = tail call i32 @fclose(i32* %4)
br label %19
19: ; preds = %17, %6
%20 = phi i32 [ 1, %17 ], [ 0, %6 ]
ret i32 %20
}