#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 EINVAL;
scalar_t__ PATH_MAX;
int errno;
int get_current_exec_path(char *, scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
int get_absolute_path(char *full_abs_path, const char *orig_file_path) {
  int ret_error;
  if (orig_file_path == NULL || strlen(orig_file_path) > PATH_MAX)
    return (EINVAL);
  if (orig_file_path[0] != '/') {
    ret_error = get_current_exec_path(full_abs_path, PATH_MAX);
    if (ret_error == 0) {
      if (strlen(full_abs_path) + strlen(orig_file_path) <= PATH_MAX)
        strcat(full_abs_path, orig_file_path);
      else
        strcpy(full_abs_path, orig_file_path);
    } else {
      ret_error = errno;
      strcpy(full_abs_path, orig_file_path);
    }
  } else
    strcpy(full_abs_path, orig_file_path);
  return (ret_error);
}


x86 assembly (clang, -O0):
<get_absolute_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1174 <get_absolute_path+0x34>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%rax
jle    1185 <get_absolute_path+0x45>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123a <get_absolute_path+0xfa>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1227 <get_absolute_path+0xe7>
mov    -0x10(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%rsi
call   1060 <get_current_exec_path@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1209 <get_absolute_path+0xc9>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%rax
jg     11f7 <get_absolute_path+0xb7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
jmp    1204 <get_absolute_path+0xc4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1222 <get_absolute_path+0xe2>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1234 <get_absolute_path+0xf4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_absolute_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     116a <get_absolute_path+0x2a>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    0x2e8f(%rip),%rbp
mov    0x0(%rbp),%rsi
cmp    %rsi,%rax
jle    1180 <get_absolute_path+0x40>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmpb   $0x2f,(%rbx)
jne    1192 <get_absolute_path+0x52>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    1173 <get_absolute_path+0x33>
mov    %r14,%rdi
call   1060 <get_current_exec_path@plt>
test   %eax,%eax
je     11b4 <get_absolute_path+0x74>
mov    0x2e33(%rip),%rax
mov    (%rax),%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    1173 <get_absolute_path+0x33>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %r15,%rax
cmp    0x0(%rbp),%rax
jle    11df <get_absolute_path+0x9f>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %ebp,%ebp
jmp    1173 <get_absolute_path+0x33>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
xor    %ebp,%ebp
jmp    1173 <get_absolute_path+0x33>

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

LLVM IR (-O2):
@PATH_MAX = global i64 0
@EINVAL = global i32 0
@errno = global i32 0
define i32 @get_absolute_path(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %1)
%6 = load i64, i64* @PATH_MAX
%7 = icmp sgt i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %4, %2
%9 = load i32, i32* @EINVAL
br label %31
10: ; preds = %4
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 47
br i1 %12, label %29, label %13
13: ; preds = %10
%14 = tail call i32 @get_current_exec_path(i8* %0, i64 %6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%18 = tail call i64 @strlen(i8* %1)
%19 = add nsw i64 %18, %17
%20 = load i64, i64* @PATH_MAX
%21 = icmp sgt i64 %19, %20
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = tail call i32 @strcat(i8* %0, i8* %1)
br label %31
24: ; preds = %16
%25 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %31
26: ; preds = %13
%27 = load i32, i32* @errno
%28 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %31
29: ; preds = %10
%30 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %31
31: ; preds = %29, %22, %24, %26, %8
%32 = phi i32 [ %9, %8 ], [ 0, %22 ], [ 0, %24 ], [ %27, %26 ], [ undef, %29 ]
ret i32 %32
}