#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*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ cp(char *, char *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
int copy_file(const char *dirname, const char *filename) {
  DIR *dir;
  dir = opendir(dirname);
  if (dir != NULL) {
    char source[256], dest[256];
    sprintf(source, "%s/%s", dirname, filename);
    sprintf(dest, "./%s", filename);
    cp(source, dest);
    closedir(dir);
  } else {
    perror("oops!");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d2 <copy_file+0x82>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1040 <cp@plt>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
jmp    11ea <copy_file+0x9a>
lea    0xe32(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <copy_file+0xa1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1030 <opendir@plt>
test   %rax,%rax
je     11d1 <copy_file+0x81>
mov    %rax,%r15
lea    0xe87(%rip),%rsi
xor    %r14d,%r14d
lea    0x100(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xe6b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <cp@plt>
mov    %r15,%rdi
call   1050 <closedir@plt>
mov    %r14d,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe33(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%r14d
jmp    11be <copy_file+0x6e>

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"./%s\00"
@.str.2 = [6 x i8] c"oops!\00"
define i32 @copy_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @opendir(i8* %9)
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %26
13: ; preds = %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%19 = load i8*, i8** %5
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%23 = call i32 @cp(i8* %21, i8* %22)
%24 = load i32*, i32** %6
%25 = call i32 @closedir(i32* %24)
br label %28
26: ; preds = %2
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %29
28: ; preds = %13
store i32 0, i32* %3
br label %29
29: ; preds = %28, %26
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"./%s\00"
@.str.2 = [6 x i8] c"oops!\00"
define i32 @copy_file(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = tail call i32* @opendir(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%11 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%12 = call i32 @cp(i8* %8, i8* %9)
%13 = call i32 @closedir(i32* %5)
br label %16
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %7, %14
%17 = phi i32 [ 0, %7 ], [ 1, %14 ]
ret i32 %17
}