#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 */
scalar_t__ cwk_path_is_absolute(char const *);
size_t cwk_path_join_and_normalize_multiple(char const **, char *, size_t);
size_t cwk_path_get_absolute(const char *base, const char *path, char *buffer,
                             size_t buffer_size) {
  size_t i;
  const char *paths[4];
  if (cwk_path_is_absolute(base)) {
    i = 0;
  } else {
    paths[0] = "/";
    i = 1;
  }
  if (cwk_path_is_absolute(path)) {
    paths[i++] = path;
    paths[i] = NULL;
  } else {
    paths[i++] = base;
    paths[i++] = path;
    paths[i] = NULL;
  }
  return cwk_path_join_and_normalize_multiple(paths, buffer, buffer_size);
}


x86 assembly (clang, -O0):
<cwk_path_get_absolute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <cwk_path_is_absolute@plt>
cmp    $0x0,%rax
je     1158 <cwk_path_get_absolute+0x38>
movq   $0x0,-0x28(%rbp)
jmp    116b <cwk_path_get_absolute+0x4b>
lea    0xea1(%rip),%rax
mov    %rax,-0x50(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <cwk_path_is_absolute@plt>
cmp    $0x0,%rax
je     11a8 <cwk_path_get_absolute+0x88>
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x50(%rbp,%rax,8)
mov    -0x28(%rbp),%rax
movq   $0x0,-0x50(%rbp,%rax,8)
jmp    11e5 <cwk_path_get_absolute+0xc5>
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x50(%rbp,%rax,8)
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x50(%rbp,%rax,8)
mov    -0x28(%rbp),%rax
movq   $0x0,-0x50(%rbp,%rax,8)
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <cwk_path_join_and_normalize_multiple@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cwk_path_get_absolute>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
call   1030 <cwk_path_is_absolute@plt>
test   %rax,%rax
je     1147 <cwk_path_get_absolute+0x27>
xor    %ebx,%ebx
jmp    1157 <cwk_path_get_absolute+0x37>
lea    0xeb2(%rip),%rax
mov    %rax,(%rsp)
mov    $0x1,%ebx
mov    %r12,%rdi
call   1030 <cwk_path_is_absolute@plt>
lea    0x1(%rbx),%rcx
test   %rax,%rax
je     116e <cwk_path_get_absolute+0x4e>
lea    (%rsp,%rbx,8),%rax
jmp    117d <cwk_path_get_absolute+0x5d>
mov    %r13,(%rsp,%rbx,8)
or     $0x2,%rbx
lea    (%rsp,%rcx,8),%rax
mov    %rbx,%rcx
mov    %r12,(%rax)
movq   $0x0,(%rsp,%rcx,8)
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <cwk_path_join_and_normalize_multiple@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i64 @cwk_path_get_absolute(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca [4 x i8*]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = load i8*, i8** %5
%12 = call i64 @cwk_path_is_absolute(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %4
store i64 0, i64* %9
br label %17
15: ; preds = %4
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %16
store i64 1, i64* %9
br label %17
17: ; preds = %15, %14
%18 = load i8*, i8** %6
%19 = call i64 @cwk_path_is_absolute(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = load i64, i64* %9
%24 = add i64 %23, 1
store i64 %24, i64* %9
%25 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 %23
store i8* %22, i8** %25
%26 = load i64, i64* %9
%27 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 %26
store i8* null, i8** %27
br label %39
28: ; preds = %17
%29 = load i8*, i8** %5
%30 = load i64, i64* %9
%31 = add i64 %30, 1
store i64 %31, i64* %9
%32 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 %30
store i8* %29, i8** %32
%33 = load i8*, i8** %6
%34 = load i64, i64* %9
%35 = add i64 %34, 1
store i64 %35, i64* %9
%36 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 %34
store i8* %33, i8** %36
%37 = load i64, i64* %9
%38 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 %37
store i8* null, i8** %38
br label %39
39: ; preds = %28, %21
%40 = getelementptr inbounds [4 x i8*], [4 x i8*]* %10, i64 0, i64 0
%41 = load i8*, i8** %7
%42 = load i64, i64* %8
%43 = call i64 @cwk_path_join_and_normalize_multiple(i8** %40, i8* %41, i64 %42)
ret i64 %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i64 @cwk_path_get_absolute(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca [4 x i8*]
%6 = bitcast [4 x i8*]* %5 to i8*
%7 = tail call i64 @cwk_path_is_absolute(i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10
br label %11
11: ; preds = %4, %9
%12 = phi i64 [ 1, %9 ], [ 0, %4 ]
%13 = tail call i64 @cwk_path_is_absolute(i8* %1)
%14 = icmp eq i64 %13, 0
%15 = add nuw nsw i64 %12, 1
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 %12
br i1 %14, label %17, label %20
17: ; preds = %11
store i8* %0, i8** %16
%18 = or i64 %12, 2
%19 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 %15
br label %20
20: ; preds = %11, %17
%21 = phi i8** [ %19, %17 ], [ %16, %11 ]
%22 = phi i64 [ %18, %17 ], [ %15, %11 ]
store i8* %1, i8** %21
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 %22
store i8* null, i8** %23
%24 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 0
%25 = call i64 @cwk_path_join_and_normalize_multiple(i8** %24, i8* %2, i64 %3)
ret i64 %25
}