#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*/ str_translate(char *, char, char);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *str_cats(char *dest, char *src) {
  int l = strlen(dest);
  str_translate(src, '\\', '/');
  if (src[0] == '/') {
    if (l > 0 && dest[l - 1] == '/')
      dest[l - 1] = '\0';
  } else {
    if (l > 0 && dest[l - 1] != '/')
      strcat(dest, "/");
  }
  strcat(dest, src);
  return dest;
}


x86 assembly (clang, -O0):
<str_cats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
mov    $0x2f,%edx
call   1040 <str_translate@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11a9 <str_cats+0x79>
cmpl   $0x0,-0x14(%rbp)
jle    11a4 <str_cats+0x74>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11a4 <str_cats+0x74>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e2 <str_cats+0xb2>
cmpl   $0x0,-0x14(%rbp)
jle    11dd <str_cats+0xad>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11dd <str_cats+0xad>
mov    -0x8(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1050 <strcat@plt>
jmp    11e2 <str_cats+0xb2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cats>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x5c,%esi
mov    $0x2f,%edx
call   1040 <str_translate@plt>
cmpb   $0x2f,(%r14)
jne    116f <str_cats+0x3f>
test   %ebx,%ebx
jle    118c <str_cats+0x5c>
add    $0xffffffff,%ebx
cmpb   $0x2f,(%r15,%rbx,1)
jne    118c <str_cats+0x5c>
movb   $0x0,(%r15,%rbx,1)
jmp    118c <str_cats+0x5c>
test   %ebx,%ebx
jle    118c <str_cats+0x5c>
add    $0xffffffff,%ebx
cmpb   $0x2f,(%r15,%rbx,1)
je     118c <str_cats+0x5c>
lea    0xe7c(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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