#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 const *);
scalar_t__ strcmp(char const *, char *);
int strlen(char *);
void pathcat(char *dest, const char *src) {
  if (strlen(dest) > 0) {
    if (dest[strlen(dest) - 1] != '/' && src[0] != '/')
      strcat(dest, "/");
    if (dest[strlen(dest) - 1] == '/' && src[0] == '/')
      dest[strlen(dest) - 1] = '\0';
  }
  if (strlen(dest) == 0) {
    if (strcmp(src, "/") == 0)
      return;
  }
  strcat(dest, src);
}


x86 assembly (clang, -O0):
<pathcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    11fc <pathcat+0xcc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     119c <pathcat+0x6c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     119c <pathcat+0x6c>
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11f7 <pathcat+0xc7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11f7 <pathcat+0xc7>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11fc <pathcat+0xcc>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    1232 <pathcat+0x102>
mov    -0x10(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    122d <pathcat+0xfd>
jmp    123f <pathcat+0x10f>
jmp    1232 <pathcat+0x102>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathcat>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    118f <pathcat+0x5f>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     1169 <pathcat+0x39>
cmpb   $0x2f,(%r14)
je     1169 <pathcat+0x39>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    118f <pathcat+0x5f>
cmpb   $0x2f,(%r14)
jne    118f <pathcat+0x5f>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jne    11af <pathcat+0x7f>
lea    0xe5e(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c1 <pathcat+0x91>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strcat@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @pathcat(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %32
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 47
br i1 %11, label %17, label %12
12: ; preds = %5
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 47
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12, %5
%18 = tail call i32 @strlen(i8* %0)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 47
br i1 %23, label %24, label %32
24: ; preds = %17
%25 = load i8, i8* %1
%26 = icmp eq i8 %25, 47
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = tail call i32 @strlen(i8* %0)
%29 = add nsw i32 %28, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %17, %24, %27, %2
%33 = tail call i32 @strlen(i8* %0)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %35, %32
%39 = tail call i32 @strcat(i8* %0, i8* %1)
br label %40
40: ; preds = %35, %38
ret void
}