#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 scalar_t__ ino_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ chdir_parent();
int /*<<< orphan*/ chdir_source();
int /*<<< orphan*/ chdir_target();
int /*<<< orphan*/ create_file(char *);
int /*<<< orphan*/ create_hardlink(char *, char *);
scalar_t__ get_inode(char *);
int /*<<< orphan*/ mkdir_source();
int /*<<< orphan*/ print_cwd();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main(int argc, const char *argv[]) {
  print_cwd();
  {
    mkdir_source();
    chdir_source();
    create_file("file1");
    create_hardlink("file1", "file2");
    create_hardlink("file2", "file3");
    chdir_parent();
  }
  system("/bin/cp -Rp source target");
  {
    chdir_target();
    ino_t i1 = get_inode("file1");
    ino_t i2 = get_inode("file2");
    ino_t i3 = get_inode("file3");
    if ((i1 != i2) || (i1 != i3)) {
      printf("TEST FAILED: hardlinked files are not copied correct, inodes "
             "differs: %lli %lli %lli\n",
             i1, i2, i3);
    } else {
      printf(
          "TEST SUCCESS: hardlinked files are copied correct, inodes the same");
    }
    chdir_parent();
  }
  return EXIT_SUCCESS;
}


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    $0x0,%al
call   10b0 <print_cwd@plt>
mov    $0x0,%al
call   1070 <mkdir_source@plt>
mov    $0x0,%al
call   1080 <chdir_source@plt>
lea    0xe2e(%rip),%rdi
call   10a0 <create_file@plt>
lea    0xe22(%rip),%rdi
lea    0xe21(%rip),%rsi
call   10c0 <create_hardlink@plt>
lea    0xe15(%rip),%rdi
lea    0xe14(%rip),%rsi
call   10c0 <create_hardlink@plt>
mov    $0x0,%al
call   1030 <chdir_parent@plt>
lea    0xe07(%rip),%rdi
call   1050 <system@plt>
mov    $0x0,%al
call   1090 <chdir_target@plt>
lea    0xde2(%rip),%rdi
call   1040 <get_inode@plt>
mov    %rax,-0x18(%rbp)
lea    0xdd8(%rip),%rdi
call   1040 <get_inode@plt>
mov    %rax,-0x20(%rbp)
lea    0xdce(%rip),%rdi
call   1040 <get_inode@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1263 <main+0xc3>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1282 <main+0xe2>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1290 <main+0xf0>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <chdir_parent@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   10b0 <print_cwd@plt>
xor    %eax,%eax
call   1070 <mkdir_source@plt>
xor    %eax,%eax
call   1080 <chdir_source@plt>
lea    0xe3f(%rip),%rbx
mov    %rbx,%rdi
call   10a0 <create_file@plt>
lea    0xe36(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <create_hardlink@plt>
lea    0xe2a(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   10c0 <create_hardlink@plt>
xor    %eax,%eax
call   1030 <chdir_parent@plt>
lea    0xe17(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
call   1090 <chdir_target@plt>
mov    %rbx,%rdi
call   1040 <get_inode@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <get_inode@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <get_inode@plt>
cmp    %r14,%rbx
jne    123f <main+0x9f>
cmp    %rax,%rbx
jne    123f <main+0x9f>
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1256 <main+0xb6>
lea    0xde6(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1030 <chdir_parent@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"file1\00"
@.str.1 = [6 x i8] c"file2\00"
@.str.2 = [6 x i8] c"file3\00"
@.str.3 = [26 x i8] c"/bin/cp -Rp source target\00"
@.str.4 = [86 x i8] c"TEST FAILED: hardlinked files are not copied correct, inodes differs: %lli %lli %lli\0A\00"
@.str.5 = [67 x i8] c"TEST SUCCESS: hardlinked files are copied correct, inodes the same\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @print_cwd()
%10 = call i32 (...) @mkdir_source()
%11 = call i32 (...) @chdir_source()
%12 = call i32 @create_file(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @create_hardlink(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @create_hardlink(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (...) @chdir_parent()
%16 = call i32 @system(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (...) @chdir_target()
%18 = call i64 @get_inode(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i64 %18, i64* %6
%19 = call i64 @get_inode(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i64 %19, i64* %7
%20 = call i64 @get_inode(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i64 %20, i64* %8
%21 = load i64, i64* %6
%22 = load i64, i64* %7
%23 = icmp ne i64 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %2
%25 = load i64, i64* %6
%26 = load i64, i64* %8
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %24, %2
%29 = load i64, i64* %6
%30 = load i64, i64* %7
%31 = load i64, i64* %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.4, i64 0, i64 0), i64 %29, i64 %30, i64 %31)
br label %35
33: ; preds = %24
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = call i32 (...) @chdir_parent()
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}

LLVM IR (-O2):
@.str = [6 x i8] c"file1\00"
@.str.1 = [6 x i8] c"file2\00"
@.str.2 = [6 x i8] c"file3\00"
@.str.3 = [26 x i8] c"/bin/cp -Rp source target\00"
@.str.4 = [86 x i8] c"TEST FAILED: hardlinked files are not copied correct, inodes differs: %lli %lli %lli\0A\00"
@.str.5 = [67 x i8] c"TEST SUCCESS: hardlinked files are copied correct, inodes the same\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @print_cwd()
%4 = tail call i32 (...) @mkdir_source()
%5 = tail call i32 (...) @chdir_source()
%6 = tail call i32 @create_file(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @create_hardlink(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @create_hardlink(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 (...) @chdir_parent()
%10 = tail call i32 @system(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 (...) @chdir_target()
%12 = tail call i64 @get_inode(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = tail call i64 @get_inode(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i64 @get_inode(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %12, %13
%16 = icmp eq i64 %12, %14
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %20, label %18
18: ; preds = %2
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @.str.4, i64 0, i64 0), i64 %12, i64 %13, i64 %14)
br label %22
20: ; preds = %2
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = tail call i32 (...) @chdir_parent()
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}