#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 */
typedef int /*<<< orphan*/ cwd;

/* Variables and functions */
int /*<<< orphan*/ MAXPATHLEN;
scalar_t__ asprintf(char **, char *, char *, char *);
int /*<<< orphan*/ assert(char **);
int /*<<< orphan*/ *getcwd(char *, int);
char *strdup(char *);
int _qualify_path(char *path, char **fqpath) {
  char *s;
  int res = 0;
  char cwd[MAXPATHLEN + 1];
  if (*path == '/') {
    if (!(s = strdup(path)))
      res = 14;
  } else {
    if (getcwd(cwd, sizeof(cwd)) == NULL)
      res = 31;
    else if (asprintf(&s, "%s/%s", cwd, path) < 0)
      res = 14;
  }
  assert(fqpath);
  if (fqpath && res == 0)
    *fqpath = s;
  return res;
}


x86 assembly (clang, -O0):
<_qualify_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11bd <_qualify_path+0x7d>
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b8 <_qualify_path+0x78>
movl   $0xe,-0x1c(%rbp)
jmp    1215 <_qualify_path+0xd5>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
call   1030 <getcwd@plt>
cmp    $0x0,%rax
jne    11e2 <_qualify_path+0xa2>
movl   $0x1f,-0x1c(%rbp)
jmp    1210 <_qualify_path+0xd0>
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1050 <asprintf@plt>
cmp    $0x0,%rax
jge    120b <_qualify_path+0xcb>
movl   $0xe,-0x1c(%rbp)
jmp    1210 <_qualify_path+0xd0>
jmp    1215 <_qualify_path+0xd5>
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
je     123e <_qualify_path+0xfe>
cmpl   $0x0,-0x1c(%rbp)
jne    123e <_qualify_path+0xfe>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_qualify_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%r12
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
add    $0x1,%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmpb   $0x2f,(%rdi)
jne    118f <_qualify_path+0x4f>
mov    %r15,%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
test   %rax,%rax
sete   %r15b
jmp    11b9 <_qualify_path+0x79>
mov    %rbx,%rdi
call   1030 <getcwd@plt>
test   %rax,%rax
je     11e1 <_qualify_path+0xa1>
lea    0xe5d(%rip),%rsi
lea    -0x28(%rbp),%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1050 <asprintf@plt>
mov    %rax,%r15
shr    $0x3f,%r15
xor    %eax,%eax
test   %r15b,%r15b
mov    $0xe,%ebx
cmove  %eax,%ebx
mov    %r14,%rdi
call   1040 <assert@plt>
test   %r14,%r14
je     11ee <_qualify_path+0xae>
test   %r15b,%r15b
jne    11ee <_qualify_path+0xae>
mov    -0x28(%rbp),%rax
mov    %rax,(%r14)
jmp    11ee <_qualify_path+0xae>
mov    %r14,%rdi
call   1040 <assert@plt>
mov    $0x1f,%ebx
mov    %r12,%rsp
mov    %ebx,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [6 x i8] c"%s/%s\00"
define i32 @_qualify_path(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %6
%9 = load i32, i32* @MAXPATHLEN
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %18
store i32 14, i32* %6
br label %23
23: ; preds = %22, %18
br label %36
24: ; preds = %2
%25 = trunc i64 %11 to i32
%26 = call i32* @getcwd(i8* %13, i32 %25)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 31, i32* %6
br label %35
29: ; preds = %24
%30 = load i8*, i8** %3
%31 = call i64 @asprintf(i8** %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 14, i32* %6
br label %34
34: ; preds = %33, %29
br label %35
35: ; preds = %34, %28
br label %36
36: ; preds = %35, %23
%37 = load i8**, i8*** %4
%38 = call i32 @assert(i8** %37)
%39 = load i8**, i8*** %4
%40 = icmp ne i8** %39, null
br i1 %40, label %41, label %47
41: ; preds = %36
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i8*, i8** %5
%46 = load i8**, i8*** %4
store i8* %45, i8** %46
br label %47
47: ; preds = %44, %41, %36
%48 = load i32, i32* %6
%49 = load i8*, i8** %7
ret i32 %48
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [6 x i8] c"%s/%s\00"
define i32 @_qualify_path(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i32, i32* @MAXPATHLEN
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 47
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i8* @strdup(i8* %0)
store i8* %13, i8** %3
%14 = icmp eq i8* %13, null
br label %23
15: ; preds = %2
%16 = call i32* @getcwd(i8* %9, i32 %6)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @assert(i8** %1)
br label %31
20: ; preds = %15
%21 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %0)
%22 = icmp slt i64 %21, 0
br label %23
23: ; preds = %20, %12
%24 = phi i1 [ %22, %20 ], [ %14, %12 ]
%25 = select i1 %24, i32 14, i32 0
%26 = call i32 @assert(i8** %1)
%27 = icmp eq i8** %1, null
%28 = or i1 %27, %24
br i1 %28, label %31, label %29
29: ; preds = %23
%30 = load i8*, i8** %3
store i8* %30, i8** %1
br label %31
31: ; preds = %18, %29, %23
%32 = phi i32 [ 31, %18 ], [ %25, %29 ], [ %25, %23 ]
ret i32 %32
}