#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_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char const *, int, int);
int smf_core_copy_to_fd(char const *, int);
int smf_core_copy_file(const char *source, const char *dest) {
  int out, result;
  if ((out = open(dest, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR)) == -1)
    return 0;
  result = smf_core_copy_to_fd(source, out);
  close(out);
  return result;
}


x86 assembly (clang, -O0):
<smf_core_copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
mov    0x2e93(%rip),%rax
or     (%rax),%esi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    0x2e69(%rip),%rax
or     (%rax),%edx
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    118e <smf_core_copy_file+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11ab <smf_core_copy_file+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <smf_core_copy_to_fd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smf_core_copy_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbx
mov    0x2eb8(%rip),%rcx
mov    0x2e71(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    0x2e9e(%rip),%rcx
or     (%rcx),%esi
mov    0x2e6d(%rip),%rcx
mov    0x2e76(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %rax,%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     118c <smf_core_copy_file+0x5c>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <smf_core_copy_to_fd@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
jmp    118e <smf_core_copy_file+0x5e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @smf_core_copy_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_WRONLY
%11 = or i32 %9, %10
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IRUSR
%15 = load i32, i32* @S_IWUSR
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %8, i32 %13, i32 %16)
store i32 %17, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 0, i32* %3
br label %27
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = call i32 @smf_core_copy_to_fd(i8* %21, i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %7
store i32 %26, i32* %3
br label %27
27: ; preds = %20, %19
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @smf_core_copy_file(i8* %0, i8* nocapture %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_WRONLY
%5 = or i32 %4, %3
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* %1, i32 %7, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = tail call i32 @smf_core_copy_to_fd(i8* %0, i32 %11)
%15 = tail call i32 @close(i32 %11)
br label %16
16: ; preds = %2, %13
%17 = phi i32 [ %14, %13 ], [ 0, %2 ]
ret i32 %17
}