#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*/ die(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *makepathname(char const *dir, char const *file) {
  char *path;
  int n;
  if (!dir || !*dir)
    dir = ".";
  n = strlen(dir);
  if (!(path = malloc(n + 1 + strlen(file) + 1)))
    (die("out of memory"));
  memcpy(path, dir, n);
  path[n++] = '/';
  strcpy(path + n, file);
  return path;
}


x86 assembly (clang, -O0):
<makepathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1178 <makepathname+0x28>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1183 <makepathname+0x33>
lea    0xe81(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c8 <makepathname+0x78>
lea    0xe3f(%rip),%rdi
call   1070 <die@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makepathname>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1168 <makepathname+0x18>
mov    %rdi,%r15
cmpb   $0x0,(%rdi)
jne    116f <makepathname+0x1f>
lea    0xe91(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    0x1(%r12),%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r12,1),%edi
add    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a7 <makepathname+0x57>
lea    0xe60(%rip),%rdi
call   1070 <die@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movslq %r12d,%rax
movb   $0x2f,(%rbx,%rax,1)
movslq %ebp,%rax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [14 x i8] c"out of memory\00"
define i8* @makepathname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9, %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
br label %14
14: ; preds = %13, %9
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 1
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %14
%26 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %14
%28 = load i8*, i8** %5
%29 = load i8*, i8** %3
%30 = load i32, i32* %6
%31 = call i32 @memcpy(i8* %28, i8* %29, i32 %30)
%32 = load i8*, i8** %5
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 47, i8* %36
%37 = load i8*, i8** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8*, i8** %4
%42 = call i32 @strcpy(i8* %40, i8* %41)
%43 = load i8*, i8** %5
ret i8* %43
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [14 x i8] c"out of memory\00"
define i8* @makepathname(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %4, %2
br label %8
8: ; preds = %7, %4
%9 = phi i8* [ %0, %4 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %7 ]
%10 = tail call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
%12 = tail call i32 @strlen(i8* %1)
%13 = add i32 %12, 1
%14 = add i32 %13, %11
%15 = tail call i8* @malloc(i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = tail call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %8
%20 = tail call i32 @memcpy(i8* %15, i8* %9, i32 %10)
%21 = sext i32 %10 to i64
%22 = getelementptr inbounds i8, i8* %15, i64 %21
store i8 47, i8* %22
%23 = sext i32 %11 to i64
%24 = getelementptr inbounds i8, i8* %15, i64 %23
%25 = tail call i32 @strcpy(i8* %24, i8* %1)
ret i8* %15
}