#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 errno;
int /*<<< orphan*/ free(char *);
char *relpath(char const *, char const *);
scalar_t__ symlink(char *, char const *);
int symlfile(const char *src, const char *dest) {
  char *target = NULL;
  int saved_errno;
  target = relpath(src, dest);
  do {
    if (target == NULL)
      goto fail;
  } while (0);
  do {
    if (symlink(target, dest))
      goto fail;
  } while (0);
  free(target);
  return 0;
fail:
  saved_errno = errno;
  free(target);
  errno = saved_errno;
  return -1;
}


x86 assembly (clang, -O0):
<symlfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <relpath@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1169 <symlfile+0x39>
jmp    11a9 <symlfile+0x79>
jmp    116e <symlfile+0x3e>
jmp    1173 <symlfile+0x43>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <symlink@plt>
cmp    $0x0,%rax
je     118f <symlfile+0x5f>
jmp    11a9 <symlfile+0x79>
jmp    1194 <symlfile+0x64>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <symlfile+0xa1>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%ecx
mov    0x2e18(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<symlfile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
call   1050 <relpath@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1154 <symlfile+0x24>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <symlink@plt>
test   %rax,%rax
je     1170 <symlfile+0x40>
mov    0x2e85(%rip),%r14
mov    (%r14),%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,(%r14)
mov    $0xffffffff,%eax
jmp    117a <symlfile+0x4a>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @symlfile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i8* @relpath(i8* %8, i8* %9)
store i8* %10, i8** %6
br label %11
11: ; preds = %2
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11
br label %27
15: ; preds = %11
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16
%18 = load i8*, i8** %6
%19 = load i8*, i8** %5
%20 = call i64 @symlink(i8* %18, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %27
23: ; preds = %17
br label %24
24: ; preds = %23
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
store i32 0, i32* %3
br label %32
27: ; preds = %22, %14
%28 = load i32, i32* @errno
store i32 %28, i32* %7
%29 = load i8*, i8** %6
%30 = call i32 @free(i8* %29)
%31 = load i32, i32* %7
store i32 %31, i32* @errno
store i32 -1, i32* %3
br label %32
32: ; preds = %27, %24
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @symlfile(i8* %0, i8* %1) {
%3 = tail call i8* @relpath(i8* %0, i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i64 @symlink(i8* %3, i8* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @free(i8* %3)
br label %13
10: ; preds = %5, %2
%11 = load i32, i32* @errno
%12 = tail call i32 @free(i8* %3)
store i32 %11, i32* @errno
br label %13
13: ; preds = %10, %8
%14 = phi i32 [ -1, %10 ], [ 0, %8 ]
ret i32 %14
}