#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 /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(size_t);
int cow_copy(char *, char *);
int errno;
size_t open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
char *strerror(int);
int /*<<< orphan*/ write(size_t, char *, int);
int main(int argc, char **argv) {
  size_t test_desc = open("/data/local/tmp/test", O_WRONLY);
  write(test_desc, "POOP\n", 6);
  close(test_desc);
  int myerrno = cow_copy("/data/local/tmp/test", "/data/local/tmp/test_file1");
  char *errmsg = strerror(errno);
  printf("%s\nNumber: %d\n", errmsg, errno);
  myerrno = cow_copy("/data/local/tmp/test", "/data/local/tmp/test_file2");
  errmsg = strerror(errno);
  printf("%s\nNumber: %d\n", errmsg, errno);
  myerrno = cow_copy("/data/local/tmp/test", "/data/local/tmp/test_file3");
  errmsg = strerror(errno);
  printf("%s\nNumber: %d\n", errmsg, errno);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <open@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%rdi
call   1060 <close@plt>
lea    0xe4c(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1050 <cow_copy@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe0b(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1050 <cow_copy@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
lea    0xdca(%rip),%rdi
lea    0xe23(%rip),%rsi
call   1050 <cow_copy@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
lea    0xdcb(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%r14
mov    %r14,%rdi
call   1070 <open@plt>
mov    %rax,%rbx
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
mov    $0x6,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1060 <close@plt>
lea    0xe78(%rip),%rsi
mov    %r14,%rdi
call   1050 <cow_copy@plt>
mov    0x2e2e(%rip),%rbx
mov    (%rbx),%edi
call   1080 <strerror@plt>
mov    (%rbx),%edx
lea    0xe74(%rip),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe71(%rip),%rsi
mov    %r14,%rdi
call   1050 <cow_copy@plt>
mov    (%rbx),%edi
call   1080 <strerror@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe69(%rip),%rsi
mov    %r14,%rdi
call   1050 <cow_copy@plt>
mov    (%rbx),%edi
call   1080 <strerror@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/data/local/tmp/test\00"
@O_WRONLY = global i32 0
@.str.1 = [6 x i8] c"POOP\0A\00"
@.str.2 = [27 x i8] c"/data/local/tmp/test_file1\00"
@errno = global i32 0
@.str.3 = [15 x i8] c"%s\0ANumber: %d\0A\00"
@.str.4 = [27 x i8] c"/data/local/tmp/test_file2\00"
@.str.5 = [27 x i8] c"/data/local/tmp/test_file3\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_WRONLY
%10 = call i64 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = call i32 @write(i64 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%13 = load i64, i64* %6
%14 = call i32 @close(i64 %13)
%15 = call i32 @cow_copy(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 %15, i32* %7
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = load i32, i32* @errno
%20 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %18, i32 %19)
%21 = call i32 @cow_copy(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 %21, i32* %7
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = load i32, i32* @errno
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %24, i32 %25)
%27 = call i32 @cow_copy(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 %27, i32* %7
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = load i32, i32* @errno
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %30, i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"/data/local/tmp/test\00"
@O_WRONLY = global i32 0
@.str.1 = [6 x i8] c"POOP\0A\00"
@.str.2 = [27 x i8] c"/data/local/tmp/test_file1\00"
@errno = global i32 0
@.str.3 = [15 x i8] c"%s\0ANumber: %d\0A\00"
@.str.4 = [27 x i8] c"/data/local/tmp/test_file2\00"
@.str.5 = [27 x i8] c"/data/local/tmp/test_file3\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i64 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @write(i64 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%6 = tail call i32 @close(i64 %4)
%7 = tail call i32 @cow_copy(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = load i32, i32* @errno
%11 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32 %10)
%12 = tail call i32 @cow_copy(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = load i32, i32* @errno
%16 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %14, i32 %15)
%17 = tail call i32 @cow_copy(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = load i32, i32* @errno
%21 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %19, i32 %20)
ret i32 0
}