#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*/ tmp;

/* Variables and functions */
int /*<<< orphan*/ assert(char const *);
int /*<<< orphan*/ is_url(char const *);
int /*<<< orphan*/ resolve_path(char *, int, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
scalar_t__ xmalloc(int);
char *absolute_path(const char *path, const char *cwd) {
  char tmp[2 * 4096];
  char *result;
  assert(path);
  assert(cwd);
  if (path[0] != '/' && !is_url(path)) {
    strncpy(tmp, cwd, sizeof(tmp));
    tmp[sizeof(tmp) - 1] = 0;
    resolve_path(tmp, sizeof(tmp), path);
    result = (char *)xmalloc(sizeof(char) * (strlen(tmp) + 1));
    strcpy(result, tmp);
  } else {
    result = (char *)xmalloc(sizeof(char) * (strlen(path) + 1));
    strcpy(result, path);
  }
  return result;
}


x86 assembly (clang, -O0):
<absolute_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1220 <absolute_path+0xb0>
mov    -0x8(%rbp),%rdi
call   1030 <is_url@plt>
cmp    $0x0,%eax
jne    1220 <absolute_path+0xb0>
lea    -0x2010(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2000,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x2010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x2000,%esi
call   1090 <resolve_path@plt>
lea    -0x2010(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <xmalloc@plt>
mov    %rax,-0x2018(%rbp)
mov    -0x2018(%rbp),%rdi
lea    -0x2010(%rbp),%rsi
call   1050 <strcpy@plt>
jmp    1250 <absolute_path+0xe0>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <xmalloc@plt>
mov    %rax,-0x2018(%rbp)
mov    -0x2018(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x2018(%rbp),%rax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<absolute_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1080 <assert@plt>
mov    %r14,%rdi
call   1080 <assert@plt>
cmpb   $0x2f,(%rbx)
je     11a0 <absolute_path+0x30>
mov    %rbx,%rdi
call   1030 <is_url@plt>
test   %eax,%eax
je     11bb <absolute_path+0x4b>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <xmalloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
jmp    11ff <absolute_path+0x8f>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x2000,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x1fff(%rsp)
mov    %r15,%rdi
mov    $0x2000,%esi
mov    %rbx,%rdx
call   1090 <resolve_path@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <xmalloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
mov    %r14,%rax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @absolute_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [8192 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @assert(i8* %7)
%9 = load i8*, i8** %4
%10 = call i32 @assert(i8* %9)
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 47
br i1 %15, label %16, label %39
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i32 @is_url(i8* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %39, label %20
20: ; preds = %16
%21 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = call i32 @strncpy(i8* %21, i8* %22, i32 8192)
%24 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 8191
store i8 0, i8* %24
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%26 = load i8*, i8** %3
%27 = call i32 @resolve_path(i8* %25, i32 8192, i8* %26)
%28 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = mul i64 1, %31
%33 = trunc i64 %32 to i32
%34 = call i64 @xmalloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%38 = call i32 @strcpy(i8* %36, i8* %37)
br label %51
39: ; preds = %16, %2
%40 = load i8*, i8** %3
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = mul i64 1, %43
%45 = trunc i64 %44 to i32
%46 = call i64 @xmalloc(i32 %45)
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %6
%48 = load i8*, i8** %6
%49 = load i8*, i8** %3
%50 = call i32 @strcpy(i8* %48, i8* %49)
br label %51
51: ; preds = %39, %20
%52 = load i8*, i8** %6
ret i8* %52
}

LLVM IR (-O2):
define i8* @absolute_path(i8* %0, i8* %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @assert(i8* %0)
%6 = tail call i32 @assert(i8* %1)
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 47
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = tail call i32 @is_url(i8* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = call i32 @strncpy(i8* %4, i8* %1, i32 8192)
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 8191
store i8 0, i8* %14
%15 = call i32 @resolve_path(i8* %4, i32 8192, i8* %0)
%16 = call i32 @strlen(i8* %4)
%17 = add nsw i32 %16, 1
%18 = call i64 @xmalloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = call i32 @strcpy(i8* %19, i8* %4)
br label %27
21: ; preds = %9, %2
%22 = tail call i32 @strlen(i8* %0)
%23 = add nsw i32 %22, 1
%24 = tail call i64 @xmalloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = tail call i32 @strcpy(i8* %25, i8* %0)
br label %27
27: ; preds = %21, %12
%28 = phi i8* [ %25, %21 ], [ %19, %12 ]
ret i8* %28
}