#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fstat(int, struct stat *);
int open(char const *, int, int);
int open_or_die(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ sendfile(int, int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void exe_cp(const char *src, const char *dest) {
  int in_fd = open_or_die(src, O_RDONLY);
  int out_fd = open(dest, O_RDWR | O_CREAT | O_TRUNC, 0755);
  struct stat info;
  fstat(in_fd, &info);
  sendfile(out_fd, in_fd, NULL, info.st_size);
  close(in_fd);
  close(out_fd);
}


x86 assembly (clang, -O0):
<exe_cp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1040 <open_or_die@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    0x2e6f(%rip),%rax
or     (%rax),%esi
mov    0x2e5e(%rip),%rax
or     (%rax),%esi
mov    $0x1ed,%edx
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <fstat@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sendfile@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exe_cp>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1040 <open_or_die@plt>
mov    0x2e6d(%rip),%rcx
mov    0x2e86(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %eax,%ebp
mov    0x2e71(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1ed,%edx
call   1060 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %ebp,%edi
call   1070 <fstat@plt>
mov    (%rsp),%ecx
mov    %ebx,%edi
mov    %ebp,%esi
xor    %edx,%edx
call   1050 <sendfile@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <close@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @exe_cp(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open_or_die(i8* %8, i32 %9)
store i32 %10, i32* %5
%11 = load i8*, i8** %4
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_CREAT
%14 = or i32 %12, %13
%15 = load i32, i32* @O_TRUNC
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %11, i32 %16, i32 493)
store i32 %17, i32* %6
%18 = load i32, i32* %5
%19 = call i32 @fstat(i32 %18, %struct.stat* %7)
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @sendfile(i32 %20, i32 %21, i32* null, i32 %23)
%25 = load i32, i32* %5
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @exe_cp(i8* %0, i8* nocapture %1) {
%3 = alloca %struct.stat
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open_or_die(i8* %0, i32 %4)
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* %1, i32 %10, i32 493)
%12 = bitcast %struct.stat* %3 to i8*
%13 = call i32 @fstat(i32 %5, %struct.stat* %3)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @sendfile(i32 %11, i32 %5, i32* null, i32 %15)
%17 = tail call i32 @close(i32 %5)
%18 = tail call i32 @close(i32 %11)
ret void
}