#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 */
char *BgYa62023779576436_br_strcat(char const *, char const *);
int /*<<< orphan*/ free(char *);
size_t strlen(char const *);
char *BgYa62023779576436_br_build_path(const char *dir, const char *file) {
  char *dir2, *result;
  size_t len;
  int must_free = 0;
  len = strlen(dir);
  if (len > 0 && dir[len - 1] != '/') {
    dir2 = BgYa62023779576436_br_strcat(dir, "/");
    must_free = 1;
  } else
    dir2 = (char *)dir;
  result = BgYa62023779576436_br_strcat(dir2, file);
  if (must_free)
    free(dir2);
  return result;
}


x86 assembly (clang, -O0):
<BgYa62023779576436_br_build_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    1198 <BgYa62023779576436_br_build_path+0x68>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1198 <BgYa62023779576436_br_build_path+0x68>
mov    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <BgYa62023779576436_br_strcat@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11a0 <BgYa62023779576436_br_build_path+0x70>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <BgYa62023779576436_br_strcat@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11c4 <BgYa62023779576436_br_build_path+0x94>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BgYa62023779576436_br_build_path>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %rax,%rax
je     114b <BgYa62023779576436_br_build_path+0x1b>
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    115d <BgYa62023779576436_br_build_path+0x2d>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <BgYa62023779576436_br_strcat@plt>
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <BgYa62023779576436_br_strcat@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <BgYa62023779576436_br_strcat@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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