#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*/ AT_FDCWD;
int linkat(int /*<<< orphan*/, char *, int /*<<< orphan*/, char *,
           int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main() {
  int ret;
  printf("hello\n");
  ret = linkat(AT_FDCWD, "boot.log", AT_FDCWD, "juan.log", 0);
  if (ret != 0)
    perror("linkat");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
lea    0xea3(%rip),%rsi
lea    0xea5(%rip),%rcx
xor    %r8d,%r8d
call   1040 <linkat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118c <main+0x5c>
lea    0xe92(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0xeb3(%rip),%rsi
lea    0xeb5(%rip),%rcx
mov    %edi,%edx
xor    %r8d,%r8d
call   1040 <linkat@plt>
test   %eax,%eax
jne    1166 <main+0x36>
xor    %eax,%eax
pop    %rcx
ret
lea    0xea5(%rip),%rdi
call   1050 <perror@plt>
jmp    1162 <main+0x32>

LLVM IR (-O0):
@.str = [7 x i8] c"hello\0A\00"
@AT_FDCWD = global i32 0
@.str.1 = [9 x i8] c"boot.log\00"
@.str.2 = [9 x i8] c"juan.log\00"
@.str.3 = [7 x i8] c"linkat\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @AT_FDCWD
%5 = load i32, i32* @AT_FDCWD
%6 = call i32 @linkat(i32 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
ret i32 0
}

LLVM IR (-O2):
@AT_FDCWD = global i32 0
@.str.1 = [9 x i8] c"boot.log\00"
@.str.2 = [9 x i8] c"juan.log\00"
@.str.3 = [7 x i8] c"linkat\00"
@str = [6 x i8] c"hello\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%2 = load i32, i32* @AT_FDCWD
%3 = tail call i32 @linkat(i32 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
ret i32 0
}