#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ die_errno(char *, char const *, char const *);
scalar_t__ errno;
scalar_t__ rename(char const *, char const *);
scalar_t__ symlink(char const *, char const *);
scalar_t__ unlink(char const *);
void force_symlink(const char *target, const char *link, const char *temp) {
  if ((unlink(temp) && errno != ENOENT) || symlink(target, temp) ||
      rename(temp, link))
    die_errno("cannot create symlink %s -> %s", link, target);
}


x86 assembly (clang, -O0):
<force_symlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     1181 <force_symlink+0x41>
mov    0x2e72(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    11af <force_symlink+0x6f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <symlink@plt>
cmp    $0x0,%rax
jne    11af <force_symlink+0x6f>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <rename@plt>
cmp    $0x0,%rax
je     11c3 <force_symlink+0x83>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe42(%rip),%rdi
call   1050 <die_errno@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<force_symlink>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     1171 <force_symlink+0x31>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
jne    1191 <force_symlink+0x51>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <symlink@plt>
test   %rax,%rax
jne    1191 <force_symlink+0x51>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <rename@plt>
test   %rax,%rax
je     11a8 <force_symlink+0x68>
lea    0xe68(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <die_errno@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ENOENT = global i64 0
@.str = [31 x i8] c"cannot create symlink %s -> %s\00"
define void @force_symlink(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%7 = load i8*, i8** %6
%8 = call i64 @unlink(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp ne i64 %11, %12
br i1 %13, label %24, label %14
14: ; preds = %10, %3
%15 = load i8*, i8** %4
%16 = load i8*, i8** %6
%17 = call i64 @symlink(i8* %15, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = load i8*, i8** %5
%22 = call i64 @rename(i8* %20, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19, %14, %10
%25 = load i8*, i8** %5
%26 = load i8*, i8** %4
%27 = call i32 @die_errno(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %26)
br label %28
28: ; preds = %24, %19
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@ENOENT = global i64 0
@.str = [31 x i8] c"cannot create symlink %s -> %s\00"
define void @force_symlink(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @unlink(i8* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOENT
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %6, %3
%11 = tail call i64 @symlink(i8* %0, i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i64 @rename(i8* %2, i8* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13, %10, %6
%17 = tail call i32 @die_errno(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
br label %18
18: ; preds = %16, %13
ret void
}