#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 /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int copy_contents(char *file_src, char *file_dst) {
  int fd_src, fd_dst;
  char buffer[1024];
  if ((fd_src = open(file_src, O_RDONLY)) < 0) {
    goto error;
  }
  if ((fd_dst = open(file_dst, O_WRONLY | O_CREAT, 0700)) < 0) {
    goto error;
  }
  while (read(fd_src, buffer, 1024) > 0) {
    write(fd_dst, buffer, strlen(buffer));
  }
  close(fd_src);
  close(fd_dst);
  return 1;
error:
  close(fd_src);
  close(fd_src);
  return 0;
}


x86 assembly (clang, -O0):
<copy_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1188 <copy_contents+0x38>
jmp    1236 <copy_contents+0xe6>
mov    -0x18(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    0x2e5c(%rip),%rax
or     (%rax),%esi
mov    $0x1c0,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11bb <copy_contents+0x6b>
jmp    1236 <copy_contents+0xe6>
jmp    11c0 <copy_contents+0x70>
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jle    121a <copy_contents+0xca>
mov    -0x20(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    11c0 <copy_contents+0x70>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    124d <copy_contents+0xfd>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_contents>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%r15d
test   %eax,%eax
js     1200 <copy_contents+0xb0>
mov    0x2e43(%rip),%rax
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbp,%rdi
mov    $0x1c0,%edx
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     1200 <copy_contents+0xb0>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    11e9 <copy_contents+0x99>
mov    %rsp,%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %rax,%rax
jg     11c0 <copy_contents+0x70>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0x1,%r14d
jmp    1210 <copy_contents+0xc0>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @copy_contents(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDONLY
%11 = call i32 (i8*, i32, ...) @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %39
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = call i32 (i8*, i32, ...) @open(i8* %15, i32 %18, i32 448)
store i32 %19, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %39
22: ; preds = %14
br label %23
23: ; preds = %28, %22
%24 = load i32, i32* %6
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%26 = call i64 @read(i32 %24, i8* %25, i32 1024)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i32, i32* %7
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @write(i32 %29, i8* %30, i32 %32)
br label %23
34: ; preds = %23
%35 = load i32, i32* %6
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
store i32 1, i32* %3
br label %44
39: ; preds = %21, %13
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
store i32 0, i32* %3
br label %44
44: ; preds = %39, %34
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @copy_contents(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %2
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = tail call i32 (i8*, i32, ...) @open(i8* %1, i32 %11, i32 448)
%13 = icmp slt i32 %12, 0
br i1 %13, label %25, label %14
14: ; preds = %8
%15 = call i64 @read(i32 %6, i8* %4, i32 1024)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14, %17
%18 = call i32 @strlen(i8* %4)
%19 = call i32 @write(i32 %12, i8* %4, i32 %18)
%20 = call i64 @read(i32 %6, i8* %4, i32 1024)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %17, %14
%23 = call i32 @close(i32 %6)
%24 = call i32 @close(i32 %12)
br label %28
25: ; preds = %8, %2
%26 = tail call i32 @close(i32 %6)
%27 = tail call i32 @close(i32 %6)
br label %28
28: ; preds = %25, %22
%29 = phi i32 [ 0, %25 ], [ 1, %22 ]
ret i32 %29
}