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

/* Variables and functions */
int /*<<< orphan*/ canonize_path(char *, int, char *);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ is_abs_path(char const *);
int /*<<< orphan*/ pstrcat(char *, int, char const *);
int /*<<< orphan*/ pstrcpy(char *, int, char const *);
void canonize_absolute_path(char *buf, int buf_size, const char *path1) {
  char path[1024];
  if (!is_abs_path(path1)) {
    getcwd(path, sizeof(path));
    pstrcat(path, sizeof(path), "/");
    pstrcat(path, sizeof(path), path1);
  } else {
    pstrcpy(path, sizeof(path), path1);
  }
  canonize_path(buf, buf_size, path);
}


x86 assembly (clang, -O0):
<canonize_absolute_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <is_abs_path@plt>
cmp    $0x0,%eax
jne    11bb <canonize_absolute_path+0x6b>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
lea    0xe64(%rip),%rdx
call   1050 <pstrcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <pstrcat@plt>
jmp    11d0 <canonize_absolute_path+0x80>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1030 <pstrcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x420(%rbp),%rdx
call   1070 <canonize_path@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonize_absolute_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1060 <is_abs_path@plt>
test   %eax,%eax
je     1184 <canonize_absolute_path+0x34>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1030 <pstrcpy@plt>
jmp    11b8 <canonize_absolute_path+0x68>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
lea    0xe65(%rip),%rdx
mov    %r15,%rdi
mov    $0x400,%esi
call   1050 <pstrcat@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1050 <pstrcat@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <canonize_path@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define void @canonize_absolute_path(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [1024 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @is_abs_path(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %3
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = call i32 @getcwd(i8* %12, i32 1024)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i32 @pstrcat(i8* %14, i32 1024, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = call i32 @pstrcat(i8* %16, i32 1024, i8* %17)
br label %23
19: ; preds = %3
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %6
%22 = call i32 @pstrcpy(i8* %20, i32 1024, i8* %21)
br label %23
23: ; preds = %19, %11
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i32 @canonize_path(i8* %24, i32 %25, i8* %26)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @canonize_absolute_path(i8* %0, i32 %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @is_abs_path(i8* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = call i32 @getcwd(i8* %5, i32 1024)
%10 = call i32 @pstrcat(i8* %5, i32 1024, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @pstrcat(i8* %5, i32 1024, i8* %2)
br label %14
12: ; preds = %3
%13 = call i32 @pstrcpy(i8* %5, i32 1024, i8* %2)
br label %14
14: ; preds = %12, %8
%15 = call i32 @canonize_path(i8* %0, i32 %1, i8* %5)
ret void
}