#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*/ path_process(char *, size_t, size_t *, char const *);
scalar_t__ prefix(char const *, char *);
int /*<<< orphan*/ strnfcat(char *, size_t, size_t *, char *, char *);
size_t path_build(char *buf, size_t len, const char *base, const char *leaf) {
  size_t cur_len = 0;
  buf[0] = '\0';
  if (!leaf || !leaf[0]) {
    if (base && base[0])
      path_process(buf, len, &cur_len, base);
    return cur_len;
  }
  if ((!base || !base[0]) || prefix(leaf, "/") || leaf[0] == '~') {
    path_process(buf, len, &cur_len, leaf);
    return cur_len;
  }
  path_process(buf, len, &cur_len, base);
  strnfcat(buf, len, &cur_len, "%s", "/");
  path_process(buf, len, &cur_len, leaf);
  return cur_len;
}


x86 assembly (clang, -O0):
<path_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     116f <path_build+0x3f>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11ac <path_build+0x7c>
cmpq   $0x0,-0x20(%rbp)
je     119f <path_build+0x6f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119f <path_build+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdx
call   1030 <path_process@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1261 <path_build+0x131>
cmpq   $0x0,-0x20(%rbp)
je     11ee <path_build+0xbe>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ee <path_build+0xbe>
mov    -0x28(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1050 <prefix@plt>
cmp    $0x0,%rax
jne    11ee <path_build+0xbe>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    1210 <path_build+0xe0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdx
call   1030 <path_process@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1261 <path_build+0x131>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdx
call   1030 <path_process@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    0xdca(%rip),%rcx
lea    0xdc1(%rip),%r8
call   1040 <strnfcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdx
call   1030 <path_process@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_build>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,0x8(%rsp)
movb   $0x0,(%rdi)
test   %rcx,%rcx
je     11bb <path_build+0x8b>
mov    %rcx,%r12
cmpb   $0x0,(%rcx)
je     11bb <path_build+0x8b>
test   %rbx,%rbx
je     11b6 <path_build+0x86>
cmpb   $0x0,(%rbx)
je     11b6 <path_build+0x86>
lea    0xe90(%rip),%rsi
mov    %r12,%rdi
call   1050 <prefix@plt>
test   %rax,%rax
jne    11b6 <path_build+0x86>
cmpb   $0x7e,(%r12)
je     11b6 <path_build+0x86>
lea    0x8(%rsp),%r13
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1030 <path_process@plt>
lea    0xe61(%rip),%rcx
lea    0xe58(%rip),%r8
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1040 <strnfcat@plt>
mov    %r12,%rbx
jmp    11c5 <path_build+0x95>
test   %rbx,%rbx
je     11d8 <path_build+0xa8>
cmpb   $0x0,(%rbx)
je     11d8 <path_build+0xa8>
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1030 <path_process@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [3 x i8] c"%s\00"
define i64 @path_build(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i64 0, i64* %10
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 0, i8* %12
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i8*, i8** %9
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %36, label %20
20: ; preds = %15, %4
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %34
23: ; preds = %20
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = load i8*, i8** %8
%33 = call i32 @path_process(i8* %30, i64 %31, i64* %10, i8* %32)
br label %34
34: ; preds = %29, %23, %20
%35 = load i64, i64* %10
store i64 %35, i64* %5
br label %73
36: ; preds = %15
%37 = load i8*, i8** %8
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %54
39: ; preds = %36
%40 = load i8*, i8** %8
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %54
44: ; preds = %39
%45 = load i8*, i8** %9
%46 = call i64 @prefix(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%47 = icmp ne i64 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %44
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 126
br i1 %53, label %54, label %60
54: ; preds = %48, %44, %39, %36
%55 = load i8*, i8** %6
%56 = load i64, i64* %7
%57 = load i8*, i8** %9
%58 = call i32 @path_process(i8* %55, i64 %56, i64* %10, i8* %57)
%59 = load i64, i64* %10
store i64 %59, i64* %5
br label %73
60: ; preds = %48
%61 = load i8*, i8** %6
%62 = load i64, i64* %7
%63 = load i8*, i8** %8
%64 = call i32 @path_process(i8* %61, i64 %62, i64* %10, i8* %63)
%65 = load i8*, i8** %6
%66 = load i64, i64* %7
%67 = call i32 @strnfcat(i8* %65, i64 %66, i64* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%68 = load i8*, i8** %6
%69 = load i64, i64* %7
%70 = load i8*, i8** %9
%71 = call i32 @path_process(i8* %68, i64 %69, i64* %10, i8* %70)
%72 = load i64, i64* %10
store i64 %72, i64* %5
br label %73
73: ; preds = %60, %54, %34
%74 = load i64, i64* %5
ret i64 %74
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [3 x i8] c"%s\00"
define i64 @path_build(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
store i64 0, i64* %5
store i8 0, i8* %0
%7 = icmp eq i8* %3, null
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8, %4
%12 = icmp eq i8* %2, null
br i1 %12, label %33, label %13
13: ; preds = %11
%14 = load i8, i8* %2
%15 = icmp eq i8 %14, 0
br i1 %15, label %33, label %30
16: ; preds = %8
%17 = icmp eq i8* %2, null
br i1 %17, label %30, label %18
18: ; preds = %16
%19 = load i8, i8* %2
%20 = icmp eq i8 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %18
%22 = tail call i64 @prefix(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i8, i8* %3
%26 = icmp eq i8 %25, 126
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i32 @path_process(i8* %0, i64 %1, i64* %5, i8* %2)
%29 = call i32 @strnfcat(i8* %0, i64 %1, i64* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %16, %18, %21, %24, %13, %27
%31 = phi i8* [ %3, %27 ], [ %2, %13 ], [ %3, %24 ], [ %3, %21 ], [ %3, %18 ], [ %3, %16 ]
%32 = call i32 @path_process(i8* %0, i64 %1, i64* %5, i8* %31)
br label %33
33: ; preds = %30, %11, %13
%34 = load i64, i64* %5
ret i64 %34
}