#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 *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *cc_fullname(char *dir, char *file) {
  char *new;
  int dlen = strlen(dir);
  int flen = strlen(file);
  int slen = 0;
  if (dir[dlen - 1] != '/')
    slen = 1;
  new = malloc(dlen + slen + flen + 1);
  if (!new)
    return 0;
  strcpy(new, dir);
  if (slen)
    strcat(new, "/");
  strcat(new, file);
  return new;
}


x86 assembly (clang, -O0):
<cc_fullname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1190 <cc_fullname+0x50>
movl   $0x1,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
add    -0x2c(%rbp),%edi
add    -0x28(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bd <cc_fullname+0x7d>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <cc_fullname+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x2c(%rbp)
je     11e4 <cc_fullname+0xa4>
mov    -0x20(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_fullname>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %ebx,%rcx
mov    -0x1(%rcx,%r15,1),%bpl
xor    %edx,%edx
cmp    $0x2f,%bpl
setne  %dl
add    %eax,%ecx
lea    (%rdx,%rcx,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ad <cc_fullname+0x6d>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
cmp    $0x2f,%bpl
je     11a2 <cc_fullname+0x62>
lea    0xe66(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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