#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 *, size_t);
int /*<<< orphan*/ qfile_correct_path(char *);
int /*<<< orphan*/ qstrcpy(char *, size_t, char const *);
int /*<<< orphan*/ strcat(char *, char const *);
char *qfile_abspath(char *buf, size_t bufsize, const char *path) {
  if (bufsize == 0)
    return NULL;
  if (path[0] == '/') {
    qstrcpy(buf, bufsize, path);
  } else {
    if (getcwd(buf, bufsize) == NULL)
      return NULL;
    strcat(buf, "/");
    strcat(buf, path);
  }
  qfile_correct_path(buf);
  return buf;
}


x86 assembly (clang, -O0):
<qfile_abspath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116c <qfile_abspath+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <qfile_abspath+0xa4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1192 <qfile_abspath+0x52>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <qstrcpy@plt>
jmp    11d3 <qfile_abspath+0x93>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <getcwd@plt>
cmp    $0x0,%rax
jne    11b6 <qfile_abspath+0x76>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <qfile_abspath+0xa4>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1050 <qfile_correct_path@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qfile_abspath>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1192 <qfile_abspath+0x52>
mov    %rdx,%r14
mov    %rdi,%rbx
cmpb   $0x2f,(%rdx)
jne    1161 <qfile_abspath+0x21>
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <qstrcpy@plt>
jmp    1188 <qfile_abspath+0x48>
mov    %rbx,%rdi
call   1030 <getcwd@plt>
test   %rax,%rax
je     1192 <qfile_abspath+0x52>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1050 <qfile_correct_path@plt>
jmp    1194 <qfile_abspath+0x54>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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