#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*/ getcwd(char *, int);
int /*<<< orphan*/ sqlite3FreeX(char *);
char *sqlite3Malloc(int, int);
int /*<<< orphan*/ sqlite3SetString(char **, char const *, char *, ...);
char *sqlite3UnixFullPathname(const char *zRelative) {
  char *zFull = 0;
  if (zRelative[0] == '/') {
    sqlite3SetString(&zFull, zRelative, (char *)0);
  } else {
    char *zBuf = sqlite3Malloc(5000, 1);
    if (zBuf == 0) {
      return 0;
    }
    zBuf[0] = 0;
    sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative, (char *)0);
    sqlite3FreeX(zBuf);
  }
  return zFull;
}


x86 assembly (clang, -O0):
<sqlite3UnixFullPathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    117c <sqlite3UnixFullPathname+0x3c>
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1050 <sqlite3SetString@plt>
jmp    11e3 <sqlite3UnixFullPathname+0xa3>
mov    $0x1388,%edi
mov    $0x1,%esi
call   1060 <sqlite3Malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <sqlite3UnixFullPathname+0x67>
movq   $0x0,-0x8(%rbp)
jmp    11eb <sqlite3UnixFullPathname+0xab>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x1388,%esi
call   1030 <getcwd@plt>
movslq %eax,%rsi
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    0xe32(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1050 <sqlite3SetString@plt>
mov    -0x20(%rbp),%rdi
call   1040 <sqlite3FreeX@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3UnixFullPathname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movq   $0x0,(%rsp)
cmpb   $0x2f,(%rdi)
jne    1165 <sqlite3UnixFullPathname+0x25>
mov    %rsp,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <sqlite3SetString@plt>
jmp    11ae <sqlite3UnixFullPathname+0x6e>
mov    $0x1388,%edi
mov    $0x1,%esi
call   1060 <sqlite3Malloc@plt>
test   %rax,%rax
je     11b4 <sqlite3UnixFullPathname+0x74>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    $0x1388,%esi
call   1030 <getcwd@plt>
movslq %eax,%rsi
lea    0xe6a(%rip),%rdx
mov    %rsp,%rdi
mov    %rbx,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1050 <sqlite3SetString@plt>
mov    %r14,%rdi
call   1040 <sqlite3FreeX@plt>
mov    (%rsp),%rax
jmp    11b6 <sqlite3UnixFullPathname+0x76>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @sqlite3UnixFullPathname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 47
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 (i8**, i8*, i8*, ...) @sqlite3SetString(i8** %4, i8* %12, i8* null)
br label %30
14: ; preds = %1
%15 = call i8* @sqlite3Malloc(i32 5000, i32 1)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %14
store i8* null, i8** %2
br label %32
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
%22 = load i8*, i8** %5
%23 = call i32 @getcwd(i8* %22, i32 5000)
%24 = sext i32 %23 to i64
%25 = inttoptr i64 %24 to i8*
%26 = load i8*, i8** %3
%27 = call i32 (i8**, i8*, i8*, ...) @sqlite3SetString(i8** %4, i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %26, i8* null)
%28 = load i8*, i8** %5
%29 = call i32 @sqlite3FreeX(i8* %28)
br label %30
30: ; preds = %19, %11
%31 = load i8*, i8** %4
store i8* %31, i8** %2
br label %32
32: ; preds = %30, %18
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @sqlite3UnixFullPathname(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 47
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8**, i8*, i8*, ...) @sqlite3SetString(i8** %2, i8* %0, i8* null)
br label %17
8: ; preds = %1
%9 = tail call i8* @sqlite3Malloc(i32 5000, i32 1)
%10 = icmp eq i8* %9, null
br i1 %10, label %19, label %11
11: ; preds = %8
store i8 0, i8* %9
%12 = tail call i32 @getcwd(i8* %9, i32 5000)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = call i32 (i8**, i8*, i8*, ...) @sqlite3SetString(i8** %2, i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0, i8* null)
%16 = call i32 @sqlite3FreeX(i8* %9)
br label %17
17: ; preds = %11, %6
%18 = load i8*, i8** %2
br label %19
19: ; preds = %8, %17
%20 = phi i8* [ %18, %17 ], [ null, %8 ]
ret i8* %20
}