#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int test_cowcopy(char *, char *);
int main(int argc, char *argv[]) {
  char *src;
  char *dest;
  FILE *fp;
  src = argv[1];
  dest = argv[2];
  int ret = test_cowcopy(src, dest);
  if (ret != 0) {
    printf("test cowcopy ret: %d\n", ret);
    printf("Error! Test cowcopy failed!\n");
    fp = fopen("/data/local/tmp/dest.txt", "w");
    return 1;
  } else {
    printf("Launched test_cowcopy with src:%s dest: %s\n", src, dest);
  }
  fp = fopen("/data/local/tmp/dest.txt", "w");
  return 0;
  src = "..";
  dest = "dest.txt";
  ret = test_cowcopy(src, dest);
  if (ret != 0) {
    printf("test cowcopy ret: %d\n", ret);
    printf("Error! Test cowcopy failed!\n");
    return 1;
  } else {
    printf("Launched test_cowcopy with src:%s dest: %s\n", src, dest);
  }
  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    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <test_cowcopy@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11ba <main+0x8a>
mov    -0x2c(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x4(%rbp)
jmp    11ee <main+0xbe>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5c(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <test_cowcopy@plt>
test   %eax,%eax
je     117f <main+0x3f>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeeb(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
jmp    1196 <main+0x56>
lea    0xeab(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe79(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"test cowcopy ret: %d\0A\00"
@.str.1 = [29 x i8] c"Error! Test cowcopy failed!\0A\00"
@.str.2 = [25 x i8] c"/data/local/tmp/dest.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [44 x i8] c"Launched test_cowcopy with src:%s dest: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
store i8* %12, i8** %6
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
store i8* %15, i8** %7
%16 = load i8*, i8** %6
%17 = load i8*, i8** %7
%18 = call i32 @test_cowcopy(i8* %16, i8* %17)
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i32, i32* %9
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %8
store i32 1, i32* %3
br label %32
26: ; preds = %2
%27 = load i8*, i8** %6
%28 = load i8*, i8** %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %27, i8* %28)
br label %30
30: ; preds = %26
%31 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %8
store i32 0, i32* %3
br label %32
32: ; preds = %30, %21
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [22 x i8] c"test cowcopy ret: %d\0A\00"
@.str.2 = [25 x i8] c"/data/local/tmp/dest.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [44 x i8] c"Launched test_cowcopy with src:%s dest: %s\0A\00"
@str = [28 x i8] c"Error! Test cowcopy failed!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i32 @test_cowcopy(i8* %4, i8* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %14
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %4, i8* %6)
br label %14
14: ; preds = %12, %9
%15 = phi i32 [ 1, %9 ], [ 0, %12 ]
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 %15
}