#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 int mode_t;

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int link(char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int unlink(char *);
int main() {
  int fd;
  int link_result;
  int unlink_result;
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  char *filename = "./link_org.txt";
  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
  link_result = link("link_org.txt", "link.txt");
  if (link_result == -1) {
    printf("error\n");
    return link_result;
  }
  unlink_result = unlink("link.txt");
  if (unlink_result == -1) {
    printf("error\n");
    return link_result;
  }
  printf("success\n");
  return unlink_result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    0x2e79(%rip),%rcx
or     (%rcx),%eax
mov    0x2e60(%rip),%rcx
or     (%rcx),%eax
mov    0x2e4f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
mov    0x2e63(%rip),%rax
or     (%rax),%esi
mov    0x2e52(%rip),%rax
or     (%rax),%esi
mov    -0x14(%rbp),%edx
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1060 <link@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11e2 <main+0xa2>
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <main+0xe4>
lea    0xe26(%rip),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1212 <main+0xd2>
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <main+0xe4>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e70(%rip),%rax
mov    0x2e89(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e6e(%rip),%rax
or     (%rax),%edx
mov    0x2e5d(%rip),%rax
or     (%rax),%edx
mov    0x2e3c(%rip),%rax
mov    0x2e85(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e72(%rip),%rax
or     (%rax),%esi
lea    0xe79(%rip),%rdi
call   1050 <open@plt>
lea    0xe6f(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1060 <link@plt>
cmp    $0xffffffff,%eax
je     11cc <main+0x8c>
mov    %eax,%ebx
lea    0xe62(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
lea    0xe64(%rip),%rcx
lea    0xe55(%rip),%rdi
cmove  %rcx,%rdi
cmovne %eax,%ebx
jmp    11d8 <main+0x98>
mov    $0xffffffff,%ebx
lea    0xe48(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [15 x i8] c"./link_org.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [13 x i8] c"link_org.txt\00"
@.str.2 = [9 x i8] c"link.txt\00"
@.str.3 = [7 x i8] c"error\0A\00"
@.str.4 = [9 x i8] c"success\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
store i32 %13, i32* %5
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %6
%14 = load i8*, i8** %6
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %17, %18
%20 = load i32, i32* %5
%21 = call i32 @open(i8* %14, i32 %19, i32 %20)
store i32 %21, i32* %2
%22 = call i32 @link(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %0
%26 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* %3
store i32 %27, i32* %1
br label %38
28: ; preds = %0
%29 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* %3
store i32 %34, i32* %1
br label %38
35: ; preds = %28
%36 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* %4
store i32 %37, i32* %1
br label %38
38: ; preds = %35, %32, %25
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [15 x i8] c"./link_org.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [13 x i8] c"link_org.txt\00"
@.str.2 = [9 x i8] c"link.txt\00"
@str = [8 x i8] c"success\00"
@str.6 = [6 x i8] c"error\00"
define i32 @main() {
%1 = load i32, i32* @S_IRUSR
%2 = load i32, i32* @S_IWUSR
%3 = or i32 %2, %1
%4 = load i32, i32* @S_IRGRP
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IROTH
%7 = or i32 %5, %6
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %7)
%14 = tail call i32 @link(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %14, -1
br i1 %15, label %21, label %16
16: ; preds = %0
%17 = tail call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32 %17, -1
%19 = select i1 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0)
%20 = select i1 %18, i32 %14, i32 %17
br label %21
21: ; preds = %16, %0
%22 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.6, i64 0, i64 0), %0 ], [ %19, %16 ]
%23 = phi i32 [ -1, %0 ], [ %20, %16 ]
%24 = tail call i32 @puts(i8* dereferenceable(1) %22)
ret i32 %23
}