#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*/ LogError(char *, char *, int, int /*<<< orphan*/);
int MAXPATHLEN;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ getcwd(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
char *AbsolutePath(char *dirname) {
  char *path;
  if (!dirname)
    return NULL;
  if (dirname[0] == '/')
    return dirname;
  path = (char *)malloc(MAXPATHLEN);
  if (!path) {
    LogError("malloc() error in %s line %d: %s\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/beave/nfdump-1.6.10p1-sagan/refs/heads/"
             "master/bin/nfexpire.c",
             113, strerror(errno));
    return NULL;
  }
  memset((void *)path, 0, MAXPATHLEN);
  getcwd(path, MAXPATHLEN - strlen(dirname) - 2);
  strncat(path, "/", 1);
  strncat(path, dirname, strlen(dirname));
  path[MAXPATHLEN - 1] = '\0';
  return path;
}


x86 assembly (clang, -O0):
<AbsolutePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <AbsolutePath+0x24>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <AbsolutePath+0x131>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11b1 <AbsolutePath+0x41>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12a1 <AbsolutePath+0x131>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1203 <AbsolutePath+0x93>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%ecx
lea    0xe1b(%rip),%rdi
lea    0xe36(%rip),%rsi
mov    $0x71,%edx
call   1070 <LogError@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <AbsolutePath+0x131>
mov    -0x18(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdi
sub    %eax,%esi
sub    $0x2,%esi
call   1050 <getcwd@plt>
mov    -0x18(%rbp),%rdi
lea    0xe69(%rip),%rsi
mov    $0x1,%edx
call   1060 <strncat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    -0x18(%rbp),%rax
mov    0x2d5b(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AbsolutePath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1229 <AbsolutePath+0xb9>
mov    %rdi,%rbx
cmpb   $0x2f,(%rdi)
je     122b <AbsolutePath+0xbb>
mov    0x2e55(%rip),%r15
mov    (%r15),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1201 <AbsolutePath+0x91>
mov    %rax,%r14
mov    (%r15),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    (%r15),%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
add    $0xfffffffe,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <getcwd@plt>
lea    0xee8(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
movslq (%r15),%rax
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rbx
jmp    122b <AbsolutePath+0xbb>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdea(%rip),%rdi
lea    0xe05(%rip),%rsi
mov    $0x71,%edx
mov    %eax,%ecx
call   1070 <LogError@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [34 x i8] c"malloc() error in %s line %d: %s\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/beave/nfdump-1.6.10p1-sagan/refs/heads/master/bin/nfexpire.c\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"/\00"
define i8* @AbsolutePath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* null, i8** %2
br label %50
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 47
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = load i8*, i8** %3
store i8* %15, i8** %2
br label %50
16: ; preds = %8
%17 = load i32, i32* @MAXPATHLEN
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @LogError(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 113, i32 %24)
store i8* null, i8** %2
br label %50
26: ; preds = %16
%27 = load i8*, i8** %4
%28 = load i32, i32* @MAXPATHLEN
%29 = call i32 @memset(i8* %27, i32 0, i32 %28)
%30 = load i8*, i8** %4
%31 = load i32, i32* @MAXPATHLEN
%32 = load i8*, i8** %3
%33 = call i32 @strlen(i8* %32)
%34 = sub nsw i32 %31, %33
%35 = sub nsw i32 %34, 2
%36 = call i32 @getcwd(i8* %30, i32 %35)
%37 = load i8*, i8** %4
%38 = call i32 @strncat(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%39 = load i8*, i8** %4
%40 = load i8*, i8** %3
%41 = load i8*, i8** %3
%42 = call i32 @strlen(i8* %41)
%43 = call i32 @strncat(i8* %39, i8* %40, i32 %42)
%44 = load i8*, i8** %4
%45 = load i32, i32* @MAXPATHLEN
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %4
store i8* %49, i8** %2
br label %50
50: ; preds = %26, %22, %14, %7
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [34 x i8] c"malloc() error in %s line %d: %s\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/beave/nfdump-1.6.10p1-sagan/refs/heads/master/bin/nfexpire.c\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"/\00"
define i8* @AbsolutePath(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %30, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 47
br i1 %5, label %30, label %6
6: ; preds = %3
%7 = load i32, i32* @MAXPATHLEN
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i32, i32* @errno
%13 = tail call i32 @strerror(i32 %12)
%14 = tail call i32 @LogError(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 113, i32 %13)
br label %30
15: ; preds = %6
%16 = load i32, i32* @MAXPATHLEN
%17 = tail call i32 @memset(i8* %9, i32 0, i32 %16)
%18 = load i32, i32* @MAXPATHLEN
%19 = tail call i32 @strlen(i8* %0)
%20 = add i32 %18, -2
%21 = sub i32 %20, %19
%22 = tail call i32 @getcwd(i8* %9, i32 %21)
%23 = tail call i32 @strncat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%24 = tail call i32 @strlen(i8* %0)
%25 = tail call i32 @strncat(i8* %9, i8* %0, i32 %24)
%26 = load i32, i32* @MAXPATHLEN
%27 = add nsw i32 %26, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %9, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %3, %1, %15, %11
%31 = phi i8* [ %9, %15 ], [ null, %11 ], [ null, %1 ], [ %0, %3 ]
ret i8* %31
}