#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*/ strcpy(char *, char *);
int strlen(char *);
int stb_fullpath(char *abs, int abs_size, char *rel) {
  if (rel[0] == '/' || rel[0] == '~') {
    if ((int)strlen(rel) >= abs_size)
      return 0;
    strcpy(abs, rel);
    return 1;
  } else {
    int n;
    getcwd(abs, abs_size);
    n = strlen(abs);
    if (n + (int)strlen(rel) + 2 <= abs_size) {
      abs[n] = '/';
      strcpy(abs + n + 1, rel);
      return 1;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<stb_fullpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1163 <stb_fullpath+0x33>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    119a <stb_fullpath+0x6a>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x14(%rbp),%eax
jl     1181 <stb_fullpath+0x51>
movl   $0x0,-0x4(%rbp)
jmp    120b <stb_fullpath+0xdb>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    120b <stb_fullpath+0xdb>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <getcwd@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cmp    -0x14(%rbp),%eax
jg     1204 <stb_fullpath+0xd4>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    120b <stb_fullpath+0xdb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stb_fullpath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    (%rdx),%al
cmp    $0x7e,%al
je     1149 <stb_fullpath+0x19>
cmp    $0x2f,%al
jne    115e <stb_fullpath+0x2e>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
jge    11a5 <stb_fullpath+0x75>
mov    %r14,%rdi
jmp    1198 <stb_fullpath+0x68>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <getcwd@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%ecx
add    $0x2,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
jg     11a5 <stb_fullpath+0x75>
movslq %r15d,%rax
movb   $0x2f,(%r14,%rax,1)
lea    (%r14,%rax,1),%rdi
add    $0x1,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @stb_fullpath(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 47
br i1 %13, label %20, label %14
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 126
br i1 %19, label %20, label %30
20: ; preds = %14, %3
%21 = load i8*, i8** %7
%22 = call i32 @strlen(i8* %21)
%23 = load i32, i32* %6
%24 = icmp sge i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 0, i32* %4
br label %56
26: ; preds = %20
%27 = load i8*, i8** %5
%28 = load i8*, i8** %7
%29 = call i32 @strcpy(i8* %27, i8* %28)
store i32 1, i32* %4
br label %56
30: ; preds = %14
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = call i32 @getcwd(i8* %31, i32 %32)
%34 = load i8*, i8** %5
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = load i8*, i8** %7
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %36, %38
%40 = add nsw i32 %39, 2
%41 = load i32, i32* %6
%42 = icmp sle i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %30
%44 = load i8*, i8** %5
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 47, i8* %47
%48 = load i8*, i8** %5
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8*, i8** %7
%54 = call i32 @strcpy(i8* %52, i8* %53)
store i32 1, i32* %4
br label %56
55: ; preds = %30
store i32 0, i32* %4
br label %56
56: ; preds = %55, %43, %26, %25
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
define i32 @stb_fullpath(i8* %0, i32 %1, i8* %2) {
%4 = load i8, i8* %2
switch i8 %4, label %10 [
i8 47, label %5
i8 126, label %5
]
5: ; preds = %3, %3
%6 = tail call i32 @strlen(i8* %2)
%7 = icmp slt i32 %6, %1
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = tail call i32 @strcpy(i8* %0, i8* %2)
br label %22
10: ; preds = %3
%11 = tail call i32 @getcwd(i8* %0, i32 %1)
%12 = tail call i32 @strlen(i8* %0)
%13 = tail call i32 @strlen(i8* %2)
%14 = add i32 %12, 2
%15 = add i32 %14, %13
%16 = icmp sgt i32 %15, %1
br i1 %16, label %22, label %17
17: ; preds = %10
%18 = sext i32 %12 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 47, i8* %19
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = tail call i32 @strcpy(i8* %20, i8* %2)
br label %22
22: ; preds = %17, %10, %5, %8
%23 = phi i32 [ 1, %8 ], [ 0, %5 ], [ 1, %17 ], [ 0, %10 ]
ret i32 %23
}