#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 open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int symlink(char *, char *);
int main() {
  int fd;
  int link_result;
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  char *filename = "./symlink_org.txt";
  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
  link_result = symlink("symlink_org.txt", "symlink.txt");
  if (link_result == -1) {
    printf("error\n");
    return link_result;
  }
  printf("success\n");
  return link_result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    0x2e89(%rip),%rcx
or     (%rcx),%eax
mov    0x2e70(%rip),%rcx
or     (%rcx),%eax
mov    0x2e5f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    0x2e73(%rip),%rax
or     (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
mov    -0x10(%rbp),%edx
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe60(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1040 <symlink@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11d2 <main+0xa2>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <main+0xb4>
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e7e(%rip),%rax
or     (%rax),%edx
mov    0x2e6d(%rip),%rax
or     (%rax),%edx
mov    0x2e4c(%rip),%rax
mov    0x2e95(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e82(%rip),%rax
or     (%rax),%esi
lea    0xe89(%rip),%rdi
call   1050 <open@plt>
lea    0xe7f(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1040 <symlink@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
lea    0xe8b(%rip),%rax
lea    0xe7c(%rip),%rdi
cmove  %rax,%rdi
call   1030 <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 = [18 x i8] c"./symlink_org.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [16 x i8] c"symlink_org.txt\00"
@.str.2 = [12 x i8] c"symlink.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 i8*
store i32 0, i32* %1
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IROTH
%12 = or i32 %10, %11
store i32 %12, i32* %4
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %5
%13 = load i8*, i8** %5
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
%19 = load i32, i32* %4
%20 = call i32 @open(i8* %13, i32 %18, i32 %19)
store i32 %20, i32* %2
%21 = call i32 @symlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %0
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* %3
store i32 %26, i32* %1
br label %30
27: ; preds = %0
%28 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32, i32* %3
store i32 %29, i32* %1
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [18 x i8] c"./symlink_org.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [16 x i8] c"symlink_org.txt\00"
@.str.2 = [12 x i8] c"symlink.txt\00"
@str = [8 x i8] c"success\00"
@str.5 = [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 ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %7)
%14 = tail call i32 @symlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %14, -1
%16 = select i1 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
ret i32 %14
}