#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 *);
int strlen(char *);
void append_slash(char *s, int size) {
  int c = strlen(s) - 1;
  if (s[c] != '/' && s[c] != '\\') {
    if (c < size - 2)
      strcat(s, "/");
    else
      s[c] = '/';
  }
}


x86 assembly (clang, -O0):
<append_slash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     119f <append_slash+0x7f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     119f <append_slash+0x7f>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    118e <append_slash+0x6e>
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1040 <strcat@plt>
jmp    119a <append_slash+0x7a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
jmp    119f <append_slash+0x7f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_slash>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
mov    -0x1(%rcx,%rbx,1),%dl
cmp    $0x2f,%dl
je     114a <append_slash+0x2a>
cmp    $0x5c,%dl
je     114a <append_slash+0x2a>
add    $0xfffffffe,%ebp
cmp    %ebp,%eax
jle    1151 <append_slash+0x31>
movb   $0x2f,-0x1(%rbx,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <strcat@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @append_slash(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %8 [
i8 47, label %14
i8 92, label %14
]
8: ; preds = %2
%9 = add nsw i32 %1, -2
%10 = icmp sgt i32 %3, %9
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %14
13: ; preds = %8
store i8 47, i8* %6
br label %14
14: ; preds = %2, %2, %11, %13
ret void
}