#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 */
char *alloc_getcwd(scalar_t__);
int /*<<< orphan*/ normpath(char *);
int /*<<< orphan*/ strcat(char *, char const *);
char *strdup(char const *);
scalar_t__ strlen(char const *);
char *abspath(const char *s) {
  char *path;
  if (s[0] != '/') {
    path = alloc_getcwd(strlen(s) + 1);
    strcat(path, "/");
    strcat(path, s);
  } else {
    path = strdup(s);
  }
  normpath(path);
  return path;
}


x86 assembly (clang, -O0):
<abspath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11a7 <abspath+0x57>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1030 <alloc_getcwd@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
jmp    11b4 <abspath+0x64>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <normpath@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abspath>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x2f,(%rdi)
jne    1169 <abspath+0x19>
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
jmp    1197 <abspath+0x47>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1030 <alloc_getcwd@plt>
mov    %rax,%rbx
lea    0xe7c(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1040 <normpath@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @abspath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 47
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = call i8* @alloc_getcwd(i64 %12)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = call i32 @strcat(i8* %16, i8* %17)
br label %22
19: ; preds = %1
%20 = load i8*, i8** %2
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %3
br label %22
22: ; preds = %19, %9
%23 = load i8*, i8** %3
%24 = call i32 @normpath(i8* %23)
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @abspath(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i64 @strlen(i8* %0)
%6 = add nsw i64 %5, 1
%7 = tail call i8* @alloc_getcwd(i64 %6)
%8 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strcat(i8* %7, i8* %0)
br label %12
10: ; preds = %1
%11 = tail call i8* @strdup(i8* %0)
br label %12
12: ; preds = %10, %4
%13 = phi i8* [ %7, %4 ], [ %11, %10 ]
%14 = tail call i32 @normpath(i8* %13)
ret i8* %13
}