#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*/ die(char *, ...);
char *get_pwd_cwd();
scalar_t__ is_absolute_path(char const *);
int snprintf(char *, int, char *, char const *, char const *);
int strlcpy(char *, char const *, int);
const char *make_nonrelative_path(const char *path) {
  static char buf[4096 + 1];
  if (is_absolute_path(path)) {
    if (strlcpy(buf, path, 4096) >= 4096)
      die("Too long path: %.*s", 60, path);
  } else {
    const char *cwd = get_pwd_cwd();
    if (!cwd)
      die("Cannot determine the current working directory");
    if (snprintf(buf, 4096, "%s/%s", cwd, path) >= 4096)
      die("Too long path: %.*s", 60, path);
  }
  return buf;
}


x86 assembly (clang, -O0):
<make_nonrelative_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <is_absolute_path@plt>
cmp    $0x0,%rax
je     11ab <make_nonrelative_path+0x5b>
mov    -0x8(%rbp),%rsi
lea    0x2ee6(%rip),%rdi
mov    $0x1000,%edx
call   1050 <strlcpy@plt>
cmp    $0x1000,%eax
jl     11a6 <make_nonrelative_path+0x56>
mov    -0x8(%rbp),%rdx
lea    0xe66(%rip),%rdi
mov    $0x3c,%esi
mov    $0x0,%al
call   1070 <die@plt>
jmp    1216 <make_nonrelative_path+0xc6>
mov    $0x0,%al
call   1060 <get_pwd_cwd@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <make_nonrelative_path+0x7f>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1070 <die@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0x2e82(%rip),%rdi
mov    $0x1000,%esi
lea    0xe59(%rip),%rdx
call   1030 <snprintf@plt>
cmp    $0x1000,%eax
jl     1211 <make_nonrelative_path+0xc1>
mov    -0x8(%rbp),%rdx
lea    0xdfb(%rip),%rdi
mov    $0x3c,%esi
mov    $0x0,%al
call   1070 <die@plt>
jmp    1216 <make_nonrelative_path+0xc6>
lea    0x2e43(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_nonrelative_path>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <is_absolute_path@plt>
test   %rax,%rax
je     11a1 <make_nonrelative_path+0x51>
lea    0x2ef8(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1050 <strlcpy@plt>
cmp    $0xfff,%eax
jle    1192 <make_nonrelative_path+0x42>
lea    0xe7d(%rip),%rdi
mov    $0x3c,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <die@plt>
lea    0x2ec7(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1060 <get_pwd_cwd@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11be <make_nonrelative_path+0x6e>
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1070 <die@plt>
lea    0x2e9b(%rip),%rdi
lea    0xe77(%rip),%rdx
mov    $0x1000,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <snprintf@plt>
cmp    $0x1000,%eax
jge    117c <make_nonrelative_path+0x2c>
jmp    1192 <make_nonrelative_path+0x42>

LLVM IR (-O0):
@make_nonrelative_path.buf = internal global [4097 x i8] zeroinitializer
@.str = [20 x i8] c"Too long path: %.*s\00"
@.str.1 = [47 x i8] c"Cannot determine the current working directory\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i8* @make_nonrelative_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @is_absolute_path(i8* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @strlcpy(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @make_nonrelative_path.buf, i64 0, i64 0), i8* %8, i32 4096)
%10 = icmp sge i32 %9, 4096
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 60, i8* %12)
br label %14
14: ; preds = %11, %7
br label %30
15: ; preds = %1
%16 = call i8* (...) @get_pwd_cwd()
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i8*, i8** %3
%23 = load i8*, i8** %2
%24 = call i32 @snprintf(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @make_nonrelative_path.buf, i64 0, i64 0), i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %22, i8* %23)
%25 = icmp sge i32 %24, 4096
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %2
%28 = call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 60, i8* %27)
br label %29
29: ; preds = %26, %21
br label %30
30: ; preds = %29, %14
ret i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @make_nonrelative_path.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@make_nonrelative_path.buf = internal global [4097 x i8] zeroinitializer
@.str = [20 x i8] c"Too long path: %.*s\00"
@.str.1 = [47 x i8] c"Cannot determine the current working directory\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i8* @make_nonrelative_path(i8* %0) {
%2 = tail call i64 @is_absolute_path(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @strlcpy(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @make_nonrelative_path.buf, i64 0, i64 0), i8* %0, i32 4096)
%6 = icmp sgt i32 %5, 4095
br i1 %6, label %15, label %17
7: ; preds = %1
%8 = tail call i8* (...) @get_pwd_cwd()
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @snprintf(i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @make_nonrelative_path.buf, i64 0, i64 0), i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %0)
%14 = icmp sgt i32 %13, 4095
br i1 %14, label %15, label %17
15: ; preds = %12, %4
%16 = tail call i32 (i8*, ...) @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 60, i8* %0)
br label %17
17: ; preds = %15, %12, %4
ret i8* getelementptr inbounds ([4097 x i8], [4097 x i8]* @make_nonrelative_path.buf, i64 0, i64 0)
}