#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 *);
scalar_t__ strchr(char *, char);
char *strend(char *);
char *add_slash(char *directory) {
  char *p;
  p = strend(directory);
  p--;
  if (*p != '/' && strchr(directory, '/'))
    strcat(directory, "/");
  if (*p != '\\' && strchr(directory, '\\'))
    strcat(directory, "\\");
  return directory;
}


x86 assembly (clang, -O0):
<add_slash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strend@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     118d <add_slash+0x5d>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     118d <add_slash+0x5d>
mov    -0x8(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     11c5 <add_slash+0x95>
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11c5 <add_slash+0x95>
mov    -0x8(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_slash>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strend@plt>
cmpb   $0x2f,-0x1(%rax)
je     116d <add_slash+0x3d>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1166 <add_slash+0x36>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
cmpb   $0x5c,-0x1(%r14)
je     118e <add_slash+0x5e>
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     118e <add_slash+0x5e>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c"\\\00"
define i8* @add_slash(i8* returned %0) {
%2 = tail call i8* @strend(i8* %0)
%3 = getelementptr inbounds i8, i8* %2, i64 -1
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 47
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = tail call i64 @strchr(i8* %0, i8 signext 47)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = load i8, i8* %3
%13 = icmp eq i8 %12, 92
br i1 %13, label %19, label %14
14: ; preds = %1, %11
%15 = tail call i64 @strchr(i8* %0, i8 signext 92)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14, %11
ret i8* %0
}