#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*/ create_file(char *);
int /*<<< orphan*/ create_hardlink(char *, char *);
scalar_t__ get_inode(char *);
int /*<<< orphan*/ mkdir(char *, int);
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();
    mkdir("dir1", 0755);
    mkdir("dir1/subdir", 0755);
    mkdir("dir2", 0755);
    create_hardlink("dir1/subdir", "dir2/subdir");
    create_file("dir1/subdir/file1");
    chdir_parent();
  }
  system("/bin/cp -Rp source target");
  {
    ino_t i1 = get_inode("target/dir1/subdir");
    ino_t i2 = get_inode("target/dir2/subdir");
    if (i1 != i2) {
      printf("TEST FAILED: hardlinked dirs are not copied correct, inodes "
             "differs: %lli %lli\n",
             i1, i2);
    } else {
      printf(
          "TEST SUCCESS: hardlinked dirs are copied correct, inodes the same");
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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   1080 <mkdir_source@plt>
mov    $0x0,%al
call   1090 <chdir_source@plt>
lea    0xe2e(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
lea    0xe5a(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
lea    0xe11(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
lea    0xe38(%rip),%rdi
lea    0xe44(%rip),%rsi
call   10c0 <create_hardlink@plt>
lea    0xdf2(%rip),%rdi
call   10a0 <create_file@plt>
mov    $0x0,%al
call   1040 <chdir_parent@plt>
lea    0xdf1(%rip),%rdi
call   1060 <system@plt>
lea    0xdff(%rip),%rdi
call   1050 <get_inode@plt>
mov    %rax,-0x18(%rbp)
lea    0xe02(%rip),%rdi
call   1050 <get_inode@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1279 <main+0xd9>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1287 <main+0xe7>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   10b0 <print_cwd@plt>
xor    %eax,%eax
call   1080 <mkdir_source@plt>
xor    %eax,%eax
call   1090 <chdir_source@plt>
lea    0xe43(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
lea    0xe6f(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
lea    0xe23(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <create_hardlink@plt>
lea    0xe08(%rip),%rdi
call   10a0 <create_file@plt>
xor    %eax,%eax
call   1040 <chdir_parent@plt>
lea    0xe07(%rip),%rdi
call   1060 <system@plt>
lea    0xe15(%rip),%rdi
call   1050 <get_inode@plt>
mov    %rax,%rbx
lea    0xe19(%rip),%rdi
call   1050 <get_inode@plt>
cmp    %rax,%rbx
jne    124a <main+0xaa>
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    125e <main+0xbe>
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"dir1\00"
@.str.1 = [12 x i8] c"dir1/subdir\00"
@.str.2 = [5 x i8] c"dir2\00"
@.str.3 = [12 x i8] c"dir2/subdir\00"
@.str.4 = [18 x i8] c"dir1/subdir/file1\00"
@.str.5 = [26 x i8] c"/bin/cp -Rp source target\00"
@.str.6 = [19 x i8] c"target/dir1/subdir\00"
@.str.7 = [19 x i8] c"target/dir2/subdir\00"
@.str.8 = [80 x i8] c"TEST FAILED: hardlinked dirs are not copied correct, inodes differs: %lli %lli\0A\00"
@.str.9 = [66 x i8] c"TEST SUCCESS: hardlinked dirs 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @print_cwd()
%9 = call i32 (...) @mkdir_source()
%10 = call i32 (...) @chdir_source()
%11 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 493)
%12 = call i32 @mkdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 493)
%13 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 493)
%14 = call i32 @create_hardlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @create_file(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (...) @chdir_parent()
%17 = call i32 @system(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%18 = call i64 @get_inode(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
store i64 %18, i64* %6
%19 = call i64 @get_inode(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
store i64 %19, i64* %7
%20 = load i64, i64* %6
%21 = load i64, i64* %7
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %2
%24 = load i64, i64* %6
%25 = load i64, i64* %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.8, i64 0, i64 0), i64 %24, i64 %25)
br label %29
27: ; preds = %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.9, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"dir1\00"
@.str.1 = [12 x i8] c"dir1/subdir\00"
@.str.2 = [5 x i8] c"dir2\00"
@.str.3 = [12 x i8] c"dir2/subdir\00"
@.str.4 = [18 x i8] c"dir1/subdir/file1\00"
@.str.5 = [26 x i8] c"/bin/cp -Rp source target\00"
@.str.6 = [19 x i8] c"target/dir1/subdir\00"
@.str.7 = [19 x i8] c"target/dir2/subdir\00"
@.str.8 = [80 x i8] c"TEST FAILED: hardlinked dirs are not copied correct, inodes differs: %lli %lli\0A\00"
@.str.9 = [66 x i8] c"TEST SUCCESS: hardlinked dirs 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 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 493)
%7 = tail call i32 @mkdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 493)
%8 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 493)
%9 = tail call i32 @create_hardlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @create_file(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%11 = tail call i32 (...) @chdir_parent()
%12 = tail call i32 @system(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%13 = tail call i64 @get_inode(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%14 = tail call i64 @get_inode(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%15 = icmp eq i64 %13, %14
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @.str.8, i64 0, i64 0), i64 %13, i64 %14)
br label %20
18: ; preds = %2
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.9, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}