#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
scalar_t__ EMLINK;
scalar_t__ ENOSYS;
scalar_t__ EPERM;
scalar_t__ EXDEV;
int copy_file(char const *, struct stat const *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, char *);
scalar_t__ link(char const *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int link_or_copy_file(const char *from, const struct stat *st, const char *to) {
  if (link(from, to) == 0)
    return 0;
  if (errno != EXDEV && errno != EPERM && errno != EMLINK && errno != ENOSYS) {
    fprintf(stderr, "Could not link file `%s' to `%s': %s\n", from, to,
            strerror(errno));
    return 1;
  }
  return copy_file(from, st, to);
}


x86 assembly (clang, -O0):
<link_or_copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <link@plt>
cmp    $0x0,%rax
jne    1177 <link_or_copy_file+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1244 <link_or_copy_file+0x104>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
je     1230 <link_or_copy_file+0xf0>
mov    0x2e28(%rip),%rax
mov    (%rax),%rax
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
je     1230 <link_or_copy_file+0xf0>
mov    0x2e0e(%rip),%rax
mov    (%rax),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     1230 <link_or_copy_file+0xf0>
mov    0x2df4(%rip),%rax
mov    (%rax),%rax
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%rax
je     1230 <link_or_copy_file+0xf0>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
lea    0xde1(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1244 <link_or_copy_file+0x104>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <copy_file@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<link_or_copy_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rsi
call   1050 <link@plt>
test   %rax,%rax
je     11c3 <link_or_copy_file+0x83>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rdi
mov    0x2e62(%rip),%rax
cmp    (%rax),%rdi
je     11d0 <link_or_copy_file+0x90>
mov    0x2e36(%rip),%rax
cmp    (%rax),%rdi
je     11d0 <link_or_copy_file+0x90>
mov    0x2e6a(%rip),%rax
cmp    (%rax),%rdi
je     11d0 <link_or_copy_file+0x90>
mov    0x2e4e(%rip),%rax
cmp    (%rax),%rdi
je     11d0 <link_or_copy_file+0x90>
mov    0x2e2a(%rip),%rax
mov    (%rax),%ebp
call   1060 <strerror@plt>
lea    0xe54(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    11c5 <link_or_copy_file+0x85>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <copy_file@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@EXDEV = global i64 0
@EPERM = global i64 0
@EMLINK = global i64 0
@ENOSYS = global i64 0
@stderr = global i32 0
@.str = [38 x i8] c"Could not link file `%s' to `%s': %s\0A\00"
define i32 @link_or_copy_file(i8* %0, %struct.stat* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.stat*
%7 = alloca i8*
store i8* %0, i8** %5
store %struct.stat* %1, %struct.stat** %6
store i8* %2, i8** %7
%8 = load i8*, i8** %5
%9 = load i8*, i8** %7
%10 = call i64 @link(i8* %8, i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 0, i32* %4
br label %41
13: ; preds = %3
%14 = load i64, i64* @errno
%15 = load i64, i64* @EXDEV
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %36
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = load i64, i64* @EPERM
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = load i64, i64* @EMLINK
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @ENOSYS
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %5
%32 = load i8*, i8** %7
%33 = load i64, i64* @errno
%34 = call i8* @strerror(i64 %33)
%35 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %32, i8* %34)
store i32 1, i32* %4
br label %41
36: ; preds = %25, %21, %17, %13
%37 = load i8*, i8** %5
%38 = load %struct.stat*, %struct.stat** %6
%39 = load i8*, i8** %7
%40 = call i32 @copy_file(i8* %37, %struct.stat* %38, i8* %39)
store i32 %40, i32* %4
br label %41
41: ; preds = %36, %29, %12
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@EXDEV = global i64 0
@EPERM = global i64 0
@EMLINK = global i64 0
@ENOSYS = global i64 0
@stderr = global i32 0
@.str = [38 x i8] c"Could not link file `%s' to `%s': %s\0A\00"
define i32 @link_or_copy_file(i8* %0, %struct.stat* %1, i8* %2) {
%4 = tail call i64 @link(i8* %0, i8* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @EXDEV
%9 = icmp eq i64 %7, %8
%10 = load i64, i64* @EPERM
%11 = icmp eq i64 %7, %10
%12 = select i1 %9, i1 true, i1 %11
%13 = load i64, i64* @EMLINK
%14 = icmp eq i64 %7, %13
%15 = select i1 %12, i1 true, i1 %14
%16 = load i64, i64* @ENOSYS
%17 = icmp eq i64 %7, %16
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %23, label %19
19: ; preds = %6
%20 = load i32, i32* @stderr
%21 = tail call i8* @strerror(i64 %7)
%22 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %2, i8* %21)
br label %25
23: ; preds = %6
%24 = tail call i32 @copy_file(i8* %0, %struct.stat* %1, i8* %2)
br label %25
25: ; preds = %3, %23, %19
%26 = phi i32 [ 1, %19 ], [ %24, %23 ], [ 0, %3 ]
ret i32 %26
}