#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int fcopy(char *name_src, char *name_dest) {
  char buffer[BUFSIZ];
  FILE *fp_src, *fp_dest;
  size_t nbytes;
  if ((fp_src = fopen(name_src, "r")) == NULL)
    return (1);
  if ((fp_dest = fopen(name_dest, "w")) == NULL) {
    fclose(fp_src);
    return (1);
  }
  while ((nbytes = fread(buffer, 1, BUFSIZ, fp_src)) > 0) {
    fwrite(buffer, 1, nbytes, fp_dest);
  }
  fclose(fp_src);
  fclose(fp_dest);
  return (0);
}


x86 assembly (clang, -O0):
<fcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ad <fcopy+0x6d>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1250 <fcopy+0x110>
mov    -0x18(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11e7 <fcopy+0xa7>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1250 <fcopy+0x110>
jmp    11ec <fcopy+0xac>
mov    -0x50(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jbe    1230 <fcopy+0xf0>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    11ec <fcopy+0xac>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcopy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    0x2e8b(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe8f(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11da <fcopy+0x9a>
mov    %rax,%r14
lea    0xe7d(%rip),%rsi
mov    %r15,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11e1 <fcopy+0xa1>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11ce <fcopy+0x8e>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1060 <fwrite@plt>
jmp    11a0 <fcopy+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
jmp    11e9 <fcopy+0xa9>
mov    $0x1,%ebx
jmp    11f1 <fcopy+0xb1>
mov    $0x1,%ebx
mov    %r14,%r15
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @fcopy(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i8*, i8** %4
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %8
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 1, i32* %3
store i32 1, i32* %11
br label %42
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %9
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32*, i32** %8
%26 = call i32 @fclose(i32* %25)
store i32 1, i32* %3
store i32 1, i32* %11
br label %42
27: ; preds = %20
br label %28
28: ; preds = %33, %27
%29 = load i32, i32* @BUFSIZ
%30 = load i32*, i32** %8
%31 = call i64 @fread(i8* %15, i32 1, i32 %29, i32* %30)
store i64 %31, i64* %10
%32 = icmp ugt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i64, i64* %10
%35 = load i32*, i32** %9
%36 = call i32 @fwrite(i8* %15, i32 1, i64 %34, i32* %35)
br label %28
37: ; preds = %28
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
%40 = load i32*, i32** %9
%41 = call i32 @fclose(i32* %40)
store i32 0, i32* %3
store i32 1, i32* %11
br label %42
42: ; preds = %37, %24, %19
%43 = load i8*, i8** %6
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @fcopy(i8* nocapture %0, i8* nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %27, label %8
8: ; preds = %2
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = load i32, i32* @BUFSIZ
%13 = call i64 @fread(i8* %5, i32 1, i32 %12, i32* %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %11, %15
%16 = phi i64 [ %19, %15 ], [ %13, %11 ]
%17 = call i32 @fwrite(i8* %5, i32 1, i64 %16, i32* %9)
%18 = load i32, i32* @BUFSIZ
%19 = call i64 @fread(i8* %5, i32 1, i32 %18, i32* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %11
%22 = tail call i32 @fclose(i32* %6)
br label %23
23: ; preds = %8, %21
%24 = phi i32* [ %9, %21 ], [ %6, %8 ]
%25 = phi i32 [ 0, %21 ], [ 1, %8 ]
%26 = tail call i32 @fclose(i32* %24)
br label %27
27: ; preds = %23, %2
%28 = phi i32 [ 1, %2 ], [ %25, %23 ]
ret i32 %28
}