#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 *concat_path(char *, char const *);
int /*<<< orphan*/ free(char *);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ memcmp(char const *, char *, int);
char *strdup(char const *);
char *absolute_path(const char *filename) {
  if (!memcmp(filename, "http://", 7) || filename[0] == '/')
    return strdup(filename);
  char *cwd = getcwd(NULL, 0);
  if (cwd == NULL)
    return NULL;
  char *name = concat_path(cwd, filename);
  free(cwd);
  return name;
}


x86 assembly (clang, -O0):
<absolute_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x7,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
je     118a <absolute_path+0x3a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    119c <absolute_path+0x4c>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11e5 <absolute_path+0x95>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <absolute_path+0x73>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <absolute_path+0x95>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <concat_path@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<absolute_path>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea2(%rip),%rsi
mov    $0x7,%edx
call   1060 <memcmp@plt>
test   %eax,%eax
je     1171 <absolute_path+0x21>
cmpb   $0x2f,(%rbx)
jne    1180 <absolute_path+0x30>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <strdup@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
test   %rax,%rax
je     11ac <absolute_path+0x5c>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <concat_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    11ae <absolute_path+0x5e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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