#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*/ O_RDWR;
scalar_t__ close(int);
int creat(char *, int /*<<< orphan*/);
int /*<<< orphan*/ die(char *, char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int symlink(char *, char *);
void setup_symlink(void) {
  int data, err;
  data = creat("/tmp/data", O_RDWR);
  if (data < 0)
    die("creat failed: %s\n", strerror(errno));
  err = symlink("/tmp/data", "/tmp/symlink");
  if (err < 0)
    die("symlink failed: %s\n", strerror(errno));
  if (close(data) != 0)
    die("close of %s failed: %s\n", "/tmp/data", strerror(errno));
}


x86 assembly (clang, -O0):
<setup_symlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1199 <setup_symlink+0x49>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
movslq %eax,%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <die@plt>
lea    0xe60(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1030 <symlink@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11d8 <setup_symlink+0x88>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
movslq %eax,%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <die@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     120f <setup_symlink+0xbf>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edx
lea    0xe3c(%rip),%rdi
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1050 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_symlink>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    118b <setup_symlink+0x3b>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
movslq %eax,%rsi
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <die@plt>
lea    0xe6e(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1030 <symlink@plt>
test   %eax,%eax
jns    11c1 <setup_symlink+0x71>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
movslq %eax,%rsi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1050 <die@plt>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
je     11f3 <setup_symlink+0xa3>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe5b(%rip),%rdi
lea    0xe17(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
pop    %rbx
jmp    1050 <die@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/tmp/data\00"
@O_RDWR = global i32 0
@.str.1 = [18 x i8] c"creat failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"/tmp/symlink\00"
@.str.3 = [20 x i8] c"symlink failed: %s\0A\00"
@.str.4 = [24 x i8] c"close of %s failed: %s\0A\00"
define void @setup_symlink() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_RDWR
%4 = call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = call i32 @strerror(i32 %8)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
%12 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %7, %0
%14 = call i32 @symlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %17, %13
%24 = load i32, i32* %1
%25 = call i64 @close(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %27, %23
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/tmp/data\00"
@O_RDWR = global i32 0
@.str.1 = [18 x i8] c"creat failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"/tmp/symlink\00"
@.str.3 = [20 x i8] c"symlink failed: %s\0A\00"
@.str.4 = [24 x i8] c"close of %s failed: %s\0A\00"
define void @setup_symlink() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %10
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = tail call i32 @strerror(i32 %5)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %4, %0
%11 = tail call i32 @symlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* @errno
%15 = tail call i32 @strerror(i32 %14)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %13, %10
%20 = tail call i64 @close(i32 %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = load i32, i32* @errno
%24 = tail call i32 @strerror(i32 %23)
%25 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %19
ret void
}