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

/* Variables and functions */
int O_CLOEXEC;
int O_RDONLY;
int check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ copy_fd_to_file(int, char const *const);
int /*<<< orphan*/ open(char const *const, int);
void copy_file(const char *const in, const char *const out) {
  int in_fd = check(open(in, O_RDONLY | O_CLOEXEC), "open(copy_file)");
  copy_fd_to_file(in_fd, out);
  check(close(in_fd), "close(copy_file)");
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,%edi
lea    0xe8c(%rip),%rsi
call   1060 <check@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <copy_fd_to_file@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    %eax,%edi
lea    0xe77(%rip),%rsi
call   1060 <check@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e9b(%rip),%rax
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
lea    0xe9c(%rip),%rsi
mov    %eax,%edi
call   1060 <check@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <copy_fd_to_file@plt>
mov    %ebp,%edi
call   1030 <close@plt>
lea    0xe8b(%rip),%rsi
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <check@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@.str = [16 x i8] c"open(copy_file)\00"
@.str.1 = [17 x i8] c"close(copy_file)\00"
define void @copy_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @O_CLOEXEC
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9)
%11 = call i32 @check(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = load i8*, i8** %4
%14 = call i32 @copy_fd_to_file(i32 %12, i8* %13)
%15 = load i32, i32* %5
%16 = call i32 @close(i32 %15)
%17 = call i32 @check(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@.str = [16 x i8] c"open(copy_file)\00"
@.str.1 = [17 x i8] c"close(copy_file)\00"
define void @copy_file(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @O_CLOEXEC
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = tail call i32 @check(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @copy_fd_to_file(i32 %7, i8* %1)
%9 = tail call i32 @close(i32 %7)
%10 = tail call i32 @check(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret void
}