#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*/ strcat(char *, char *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *xmalloc(int);
char *pathjoin(const char *a, const char *b) {
  char *result;
  result = xmalloc(256 * 2 + 1);
  if (b[0] == '/') {
    strncpy(result, b, 256);
  } else {
    strncpy(result, a, 256);
    strcat(result, "/");
    strncat(result, b, 256);
  }
  return result;
}


x86 assembly (clang, -O0):
<pathjoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x201,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1185 <pathjoin+0x45>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    11b9 <pathjoin+0x79>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1050 <strncat@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathjoin>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x201,%edi
call   1040 <xmalloc@plt>
mov    %rax,%rbx
cmpb   $0x2f,(%r14)
jne    1170 <pathjoin+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    119f <pathjoin+0x5f>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   1050 <strncat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @pathjoin(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i8* @xmalloc(i32 513)
store i8* %6, i8** %5
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 47
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 256)
br label %25
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = load i8*, i8** %3
%19 = call i32 @strncpy(i8* %17, i8* %18, i32 256)
%20 = load i8*, i8** %5
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %5
%23 = load i8*, i8** %4
%24 = call i32 @strncat(i8* %22, i8* %23, i32 256)
br label %25
25: ; preds = %16, %12
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @pathjoin(i8* %0, i8* %1) {
%3 = tail call i8* @xmalloc(i32 513)
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 47
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @strncpy(i8* %3, i8* %1, i32 256)
br label %12
8: ; preds = %2
%9 = tail call i32 @strncpy(i8* %3, i8* %0, i32 256)
%10 = tail call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @strncat(i8* %3, i8* %1, i32 256)
br label %12
12: ; preds = %8, %6
ret i8* %3
}