#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*/ chosp(char *);
scalar_t__ is_path_absolute(char const *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *);
size_t strlen(char *);
int apply_p_mod(const char *path, const char *parent, char *buf,
                size_t buf_len) {
  size_t len;
  if (is_path_absolute(path)) {
    snprintf(buf, buf_len, "%s", path);
    return 0;
  }
  snprintf(buf, buf_len, "%s", parent);
  chosp(buf);
  len = strlen(buf);
  snprintf(buf + len, buf_len - len, "/%s", path);
  return 0;
}


x86 assembly (clang, -O0):
<apply_p_mod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <is_path_absolute@plt>
cmp    $0x0,%rax
je     118f <apply_p_mod+0x4f>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    0xe83(%rip),%rdx
call   1040 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <apply_p_mod+0xa4>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe5f(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <chosp@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
sub    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    0xe28(%rip),%rdx
call   1040 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_p_mod>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r14
call   1060 <is_path_absolute@plt>
lea    0xea1(%rip),%rdx
test   %rax,%rax
jne    1190 <apply_p_mod+0x50>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <chosp@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %rax,%rbx
sub    %rax,%r15
lea    0xe70(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
call   1040 <snprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"/%s\00"
define i32 @apply_p_mod(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i64 @is_path_absolute(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @snprintf(i8* %2, i64 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
9: ; preds = %4
%10 = tail call i32 @snprintf(i8* %2, i64 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%11 = tail call i32 @chosp(i8* %2)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = sub i64 %3, %12
%15 = tail call i32 @snprintf(i8* %13, i64 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %9, %7
ret i32 0
}