#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 check_tmp_dir(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ stderr;
int symlink(char const *, char const *);
int create_link(const char *file, const char *tmp_dir) {
  int result;
  result = check_tmp_dir(tmp_dir);
  if (result) {
    return result;
  }
  result = symlink(tmp_dir, file);
  if (result == -1) {
    fprintf(stderr, "Error: Can not create link from \"%s\" to \"%s\"\n", file,
            tmp_dir);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <check_tmp_dir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1161 <create_link+0x31>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <create_link+0x7b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <symlink@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a4 <create_link+0x74>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ab <create_link+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_link>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <check_tmp_dir@plt>
test   %eax,%eax
jne    117a <create_link+0x4a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <symlink@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    117a <create_link+0x4a>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"Error: Can not create link from \22%s\22 to \22%s\22\0A\00"
define i32 @create_link(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @check_tmp_dir(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %6
store i32 %12, i32* %3
br label %25
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = load i8*, i8** %4
%16 = call i32 @symlink(i8* %14, i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
store i32 1, i32* %3
br label %25
24: ; preds = %13
store i32 0, i32* %3
br label %25
25: ; preds = %24, %19, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"Error: Can not create link from \22%s\22 to \22%s\22\0A\00"
define i32 @create_link(i8* %0, i8* %1) {
%3 = tail call i32 @check_tmp_dir(i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i32 @symlink(i8* %1, i8* %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %11
11: ; preds = %5, %2, %8
%12 = phi i32 [ 1, %8 ], [ %3, %2 ], [ 0, %5 ]
ret i32 %12
}