#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*/ EALREADY;
scalar_t__ ENOENT;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ compare_file();
int /*<<< orphan*/ do_copy(char *, char *);
scalar_t__ do_copy_force(char *, char *);
scalar_t__ errno;
scalar_t__ touch(char *);
scalar_t__ unlink(char *);
void test_overwite(void) {
  assert(unlink("/tmp/test-cp-src") == 0 || errno == ENOENT);
  assert(unlink("/tmp/test-cp-dst") == 0 || errno == ENOENT);
  assert(touch("/tmp/test-cp-src") == 0);
  assert(touch("/tmp/test-cp-dst") == 0);
  assert(do_copy("/tmp/test-cp-src", "/tmp/test-cp-dst") == -EALREADY);
  assert(do_copy_force("/tmp/test-cp-src", "/tmp/test-cp-dst") == 0);
  compare_file();
}


x86 assembly (clang, -O0):
<test_overwite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1040 <unlink@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x1(%rbp)
je     11a0 <test_overwite+0x40>
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1(%rbp)
mov    -0x1(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe5d(%rip),%rdi
call   1040 <unlink@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x2(%rbp)
je     11e5 <test_overwite+0x85>
mov    0x2e06(%rip),%rax
mov    (%rax),%rax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2(%rbp)
mov    -0x2(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe07(%rip),%rdi
call   1030 <touch@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xdfb(%rip),%rdi
call   1030 <touch@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xdcd(%rip),%rdi
lea    0xdd7(%rip),%rsi
call   1080 <do_copy@plt>
xor    %ecx,%ecx
mov    0x2d98(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xda0(%rip),%rdi
lea    0xdaa(%rip),%rsi
call   1070 <do_copy_force@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1060 <compare_file@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_overwite>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe91(%rip),%r14
mov    %r14,%rdi
call   1040 <unlink@plt>
test   %rax,%rax
sete   %al
mov    0x2e54(%rip),%r12
mov    (%r12),%rcx
mov    0x2e39(%rip),%rbx
cmp    (%rbx),%rcx
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
lea    0xe6b(%rip),%r15
mov    %r15,%rdi
call   1040 <unlink@plt>
test   %rax,%rax
sete   %al
mov    (%r12),%rcx
cmp    (%rbx),%rcx
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    %r14,%rdi
call   1030 <touch@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %r15,%rdi
call   1030 <touch@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <do_copy@plt>
mov    0x2dda(%rip),%rcx
xor    %edi,%edi
add    (%rcx),%eax
sete   %dil
call   1050 <assert@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <do_copy_force@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <compare_file@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"/tmp/test-cp-src\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [17 x i8] c"/tmp/test-cp-dst\00"
@EALREADY = global i32 0
define void @test_overwite() {
%1 = call i64 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i64 %1, 0
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = load i64, i64* @errno
%5 = load i64, i64* @ENOENT
%6 = icmp eq i64 %4, %5
br label %7
7: ; preds = %3, %0
%8 = phi i1 [ true, %0 ], [ %6, %3 ]
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i64 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = load i64, i64* @errno
%15 = load i64, i64* @ENOENT
%16 = icmp eq i64 %14, %15
br label %17
17: ; preds = %13, %7
%18 = phi i1 [ true, %7 ], [ %16, %13 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i64 @touch(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i64 @touch(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @do_copy(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EALREADY
%31 = sub nsw i32 0, %30
%32 = icmp eq i32 %29, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i64 @do_copy_force(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = call i32 (...) @compare_file()
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"/tmp/test-cp-src\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [17 x i8] c"/tmp/test-cp-dst\00"
@EALREADY = global i32 0
define void @test_overwite() {
%1 = tail call i64 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i64 %1, 0
%3 = load i64, i64* @errno
%4 = load i64, i64* @ENOENT
%5 = icmp eq i64 %3, %4
%6 = select i1 %2, i1 true, i1 %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i64 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp eq i64 %11, %12
%14 = select i1 %10, i1 true, i1 %13
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i64 @touch(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call i64 @touch(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i32 @do_copy(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EALREADY
%27 = sub nsw i32 0, %26
%28 = icmp eq i32 %25, %27
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = tail call i64 @do_copy_force(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
%34 = tail call i32 @assert(i32 %33)
%35 = tail call i32 (...) @compare_file()
ret void
}