#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*/ asprintf(char **, char *, char *, char *);
int strlen(char *);
char *dirs_makefullpath(char *directory, char *file) {
  if (directory == NULL)
    return file;
  if (file == NULL)
    return NULL;
  char *result;
  if (directory[strlen(directory) - 1] == '/') {
    if (file[0] == '/') {
      asprintf(&result, "%s%s", directory, file + 1);
    } else {
      asprintf(&result, "%s%s", directory, file);
    }
  } else {
    if (file[0] == '/') {
      asprintf(&result, "%s%s", directory, file);
    } else {
      asprintf(&result, "%s/%s", directory, file);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<dirs_makefullpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1148 <dirs_makefullpath+0x28>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122a <dirs_makefullpath+0x10a>
cmpq   $0x0,-0x18(%rbp)
jne    1160 <dirs_makefullpath+0x40>
movq   $0x0,-0x8(%rbp)
jmp    122a <dirs_makefullpath+0x10a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11d8 <dirs_makefullpath+0xb8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11bb <dirs_makefullpath+0x9b>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
lea    -0x20(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <asprintf@plt>
jmp    11d3 <dirs_makefullpath+0xb3>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1040 <asprintf@plt>
jmp    1222 <dirs_makefullpath+0x102>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1205 <dirs_makefullpath+0xe5>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1040 <asprintf@plt>
jmp    121d <dirs_makefullpath+0xfd>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1040 <asprintf@plt>
jmp    1222 <dirs_makefullpath+0x102>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirs_makefullpath>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %rdi,%rdi
je     1179 <dirs_makefullpath+0x59>
test   %rbx,%rbx
je     114f <dirs_makefullpath+0x2f>
mov    %rdi,%r14
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r14,1)
mov    (%rbx),%al
jne    1153 <dirs_makefullpath+0x33>
cmp    $0x2f,%al
jne    1157 <dirs_makefullpath+0x37>
add    $0x1,%rbx
jmp    1157 <dirs_makefullpath+0x37>
xor    %ebx,%ebx
jmp    1179 <dirs_makefullpath+0x59>
cmp    $0x2f,%al
jne    1160 <dirs_makefullpath+0x40>
lea    0xea2(%rip),%rsi
jmp    1167 <dirs_makefullpath+0x47>
lea    0xe9e(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <asprintf@plt>
mov    (%rsp),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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