#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
int copy(FILE *out, const char *dir, const char *filename,
         unsigned char verbose) {
  FILE *in;
  int ch;
  char path[1024];
  int bytes = 0;
  if (!filename) {
    return 0;
  }
  if (dir) {
    strcpy(path, dir);
    strcpy(path + strlen(path), filename);
  } else {
    strcpy(path, filename);
  }
  in = fopen(path, "rb");
  while ((ch = getc(in)) != EOF) {
    putc(ch, out);
    bytes++;
  }
  fclose(in);
  if (verbose) {
    printf("imported file: %s, size=%d\n", path, bytes);
  }
  return bytes;
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
movl   $0x0,-0x444(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ad <copy+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1293 <copy+0x123>
cmpq   $0x0,-0x18(%rbp)
je     11fc <copy+0x8c>
lea    -0x440(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x440(%rbp),%rax
mov    %rax,-0x450(%rbp)
lea    -0x440(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x450(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    120c <copy+0x9c>
lea    -0x440(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x440(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x34(%rbp)
mov    0x2db2(%rip),%rcx
cmp    (%rcx),%eax
je     125e <copy+0xee>
mov    -0x34(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <putc@plt>
mov    -0x444(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x444(%rbp)
jmp    1223 <copy+0xb3>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
cmpb   $0x0,-0x21(%rbp)
je     128a <copy+0x11a>
lea    -0x440(%rbp),%rsi
mov    -0x444(%rbp),%edx
lea    0xd7e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x444(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
test   %rdx,%rdx
je     11ad <copy+0x3d>
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rdi,%r15
test   %rsi,%rsi
je     11b1 <copy+0x41>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
jmp    11b4 <copy+0x44>
xor    %ebp,%ebp
jmp    1229 <copy+0xb9>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe3d(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <getc@plt>
mov    0x2e0b(%rip),%r12
xor    %ebp,%ebp
cmp    (%r12),%eax
je     120b <copy+0x9b>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %r15,%rsi
call   1070 <putc@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    (%r12),%eax
jne    11f0 <copy+0x80>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14b,%r14b
je     1229 <copy+0xb9>
lea    0xde4(%rip),%rdi
mov    %rsp,%rsi
mov    %ebp,%edx
call   1060 <printf@plt>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [28 x i8] c"imported file: %s, size=%d\0A\00"
define i32 @copy(i32* %0, i8* %1, i8* %2, i8 zeroext %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8 %3, i8* %9
store i32 0, i32* %13
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %4
store i32 0, i32* %5
br label %60
17: ; preds = %4
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%22 = load i8*, i8** %7
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = load i8*, i8** %8
%30 = call i32 @strcpy(i8* %28, i8* %29)
br label %35
31: ; preds = %17
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%33 = load i8*, i8** %8
%34 = call i32 @strcpy(i8* %32, i8* %33)
br label %35
35: ; preds = %31, %20
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %37, i32** %10
br label %38
38: ; preds = %43, %35
%39 = load i32*, i32** %10
%40 = call i32 @getc(i32* %39)
store i32 %40, i32* %11
%41 = load i32, i32* @EOF
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32, i32* %11
%45 = load i32*, i32** %6
%46 = call i32 @putc(i32 %44, i32* %45)
%47 = load i32, i32* %13
%48 = add nsw i32 %47, 1
store i32 %48, i32* %13
br label %38
49: ; preds = %38
%50 = load i32*, i32** %10
%51 = call i32 @fclose(i32* %50)
%52 = load i8, i8* %9
%53 = icmp ne i8 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%56 = load i32, i32* %13
%57 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %55, i32 %56)
br label %58
58: ; preds = %54, %49
%59 = load i32, i32* %13
store i32 %59, i32* %5
br label %60
60: ; preds = %58, %16
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [28 x i8] c"imported file: %s, size=%d\0A\00"
define i32 @copy(i32* nocapture %0, i8* %1, i8* %2, i8 zeroext %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %2, null
br i1 %7, label %36, label %8
8: ; preds = %4
%9 = icmp eq i8* %1, null
br i1 %9, label %15, label %10
10: ; preds = %8
%11 = call i32 @strcpy(i8* %6, i8* %1)
%12 = call i32 @strlen(i8* %6)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %13
br label %15
15: ; preds = %8, %10
%16 = phi i8* [ %14, %10 ], [ %6, %8 ]
%17 = call i32 @strcpy(i8* %16, i8* %2)
%18 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @getc(i32* %18)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %30, label %22
22: ; preds = %15, %22
%23 = phi i32 [ %27, %22 ], [ %19, %15 ]
%24 = phi i32 [ %26, %22 ], [ 0, %15 ]
%25 = call i32 @putc(i32 %23, i32* %0)
%26 = add nuw nsw i32 %24, 1
%27 = call i32 @getc(i32* %18)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %22
30: ; preds = %22, %15
%31 = phi i32 [ 0, %15 ], [ %26, %22 ]
%32 = call i32 @fclose(i32* %18)
%33 = icmp eq i8 %3, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 %31)
br label %36
36: ; preds = %30, %34, %4
%37 = phi i32 [ 0, %4 ], [ %31, %34 ], [ %31, %30 ]
ret i32 %37
}