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

/* Variables and functions */
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void get_absolute_path(char directory[], char *arg) {
  char cwd[4096] = {
      0,
  };
  if (getcwd(cwd, sizeof(cwd)) == NULL)
    printf("some error in getting cwd\n");
  if (strcmp(arg, ".") != 0) {
    if (cwd[strlen(cwd)] != '/')
      cwd[strlen(cwd)] = '/';
    strcat(cwd, arg);
  }
  strcpy(directory, cwd);
}


x86 assembly (clang, -O0):
<get_absolute_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x1010(%rbp),%rdi
mov    $0x1000,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    11bd <get_absolute_path+0x4d>
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1218 <get_absolute_path+0xa8>
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
movsbl -0x1010(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     1208 <get_absolute_path+0x98>
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
movb   $0x2f,-0x1010(%rbp,%rax,1)
2f
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_absolute_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%rbx
mov    $0x1000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
jne    11b2 <get_absolute_path+0x42>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
lea    0xe47(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11e3 <get_absolute_path+0x73>
mov    %rsp,%rdi
call   1050 <strlen@plt>
cmpb   $0x2f,(%rsp,%rax,1)
je     11d8 <get_absolute_path+0x68>
movb   $0x2f,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"some error in getting cwd\0A\00"
@.str.1 = [2 x i8] c".\00"
define void @get_absolute_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4096 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = bitcast [4096 x i8]* %5 to i8*
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%8 = call i32* @getcwd(i8* %7, i32 4096)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i8*, i8** %4
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 47
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %25
store i8 47, i8* %26
br label %27
27: ; preds = %23, %16
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = call i32 @strcat(i8* %28, i8* %29)
br label %31
31: ; preds = %27, %12
%32 = load i8*, i8** %3
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%34 = call i32 @strcpy(i8* %32, i8* %33)
ret void
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c".\00"
@str = [26 x i8] c"some error in getting cwd\00"
define void @get_absolute_path(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32* @getcwd(i8* %4, i32 4096)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = call i64 @strlen(i8* %4)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 47
br i1 %16, label %18, label %17
17: ; preds = %12
store i8 47, i8* %14
br label %18
18: ; preds = %17, %12
%19 = call i32 @strcat(i8* %4, i8* %1)
br label %20
20: ; preds = %18, %9
%21 = call i32 @strcpy(i8* %0, i8* %4)
ret void
}