#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 EXIT_FAILURE;
int EXIT_SUCCESS;
char *basename(char const *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *, char *);
int cpyfile(const char *src, const char *dst) {
  FILE *srcfile, *dstfile;
  char dstpath[BUFSIZ], buffer[BUFSIZ];
  snprintf(dstpath, (size_t)BUFSIZ, "%s/%s", dst, basename(src));
  srcfile = fopen(src, "r");
  dstfile = fopen(dstpath, "w");
  if (srcfile == NULL || dstfile == NULL) {
    return EXIT_FAILURE;
  }
  while (!feof(srcfile)) {
    size_t numb;
    numb = fread(buffer, 1, BUFSIZ, srcfile);
    fwrite(buffer, 1, numb, dstfile);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<cpyfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    0x2e1f(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <basename@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rcx
mov    -0x58(%rbp),%rdi
mov    %rax,%r8
lea    0xe11(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1070 <fopen@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,-0x20(%rbp)
lea    0xdf5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1232 <cpyfile+0xd2>
cmpq   $0x0,-0x28(%rbp)
jne    124a <cpyfile+0xea>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    12ba <cpyfile+0x15a>
jmp    124f <cpyfile+0xef>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    126d <cpyfile+0x10d>
jmp    12a7 <cpyfile+0x147>
mov    -0x70(%rbp),%rdi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x70(%rbp),%rdi
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
jmp    124f <cpyfile+0xef>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpyfile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r13
mov    0x2e65(%rip),%rax
movslq (%rax),%rbx
mov    %ebx,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
call   1050 <basename@plt>
lea    0xe5a(%rip),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
mov    %rax,%r8
call   1040 <snprintf@plt>
lea    0xe48(%rip),%rsi
mov    %r13,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe38(%rip),%rsi
mov    %r12,%rdi
call   1070 <fopen@plt>
mov    0x2df9(%rip),%r12
test   %rbx,%rbx
je     1243 <cpyfile+0xe3>
mov    %rax,%r15
test   %rax,%rax
je     1243 <cpyfile+0xe3>
mov    %rbx,%rdi
call   1060 <feof@plt>
mov    0x2dd5(%rip),%r12
test   %eax,%eax
jne    1243 <cpyfile+0xe3>
mov    0x2dda(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1210 <cpyfile+0xb0>
mov    (%r12),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @cpyfile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %8
%16 = alloca i8, i64 %14
store i64 %14, i64* %9
%17 = load i32, i32* @BUFSIZ
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %10
%20 = load i32, i32* @BUFSIZ
%21 = sext i32 %20 to i64
%22 = load i8*, i8** %5
%23 = load i8*, i8** %4
%24 = call i8* @basename(i8* %23)
%25 = call i32 @snprintf(i8* %16, i64 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
%26 = load i8*, i8** %4
%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** %6
%28 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %7
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %34, label %31
31: ; preds = %2
%32 = load i32*, i32** %7
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %31, %2
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
store i32 1, i32* %11
br label %51
36: ; preds = %31
br label %37
37: ; preds = %42, %36
%38 = load i32*, i32** %6
%39 = call i32 @feof(i32* %38)
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
br i1 %41, label %42, label %49
42: ; preds = %37
%43 = load i32, i32* @BUFSIZ
%44 = load i32*, i32** %6
%45 = call i64 @fread(i8* %19, i32 1, i32 %43, i32* %44)
store i64 %45, i64* %12
%46 = load i64, i64* %12
%47 = load i32*, i32** %7
%48 = call i32 @fwrite(i8* %19, i32 1, i64 %46, i32* %47)
br label %37
49: ; preds = %37
%50 = load i32, i32* @EXIT_SUCCESS
store i32 %50, i32* %3
store i32 1, i32* %11
br label %51
51: ; preds = %49, %34
%52 = load i8*, i8** %8
%53 = load i32, i32* %3
ret i32 %53
}

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