#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 strlen(char *);
void AppendPathSeperator(char *path, int length) {
  int pathlen = strlen(path);
  if (strlen(path) && length - pathlen > 1 && path[pathlen - 1] != '/' &&
      path[pathlen - 1] != '\\') {
    path[pathlen] = '/';
    path[pathlen + 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<AppendPathSeperator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
je     119d <AppendPathSeperator+0x8d>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    $0x1,%eax
jle    119d <AppendPathSeperator+0x8d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     119d <AppendPathSeperator+0x8d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     119d <AppendPathSeperator+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AppendPathSeperator>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     114c <AppendPathSeperator+0x3c>
sub    %r14d,%ebp
cmp    $0x2,%ebp
jl     114c <AppendPathSeperator+0x3c>
movslq %r14d,%rax
mov    -0x1(%rax,%rbx,1),%cl
cmp    $0x2f,%cl
je     114c <AppendPathSeperator+0x3c>
cmp    $0x5c,%cl
je     114c <AppendPathSeperator+0x3c>
movw   $0x2f,(%rbx,%rax,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @AppendPathSeperator(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)
store i32 %7, i32* %5
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %44
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = sub nsw i32 %12, %13
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %44
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 47
br i1 %24, label %25, label %44
25: ; preds = %16
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 92
br i1 %33, label %34, label %44
34: ; preds = %25
%35 = load i8*, i8** %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 47, i8* %38
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %34, %25, %16, %11, %2
ret void
}

LLVM IR (-O2):
define void @AppendPathSeperator(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp ne i32 %4, 0
%6 = sub nsw i32 %1, %3
%7 = icmp sgt i32 %6, 1
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = add nsw i32 %3, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
switch i8 %13, label %14 [
i8 47, label %20
i8 92, label %20
]
14: ; preds = %9
%15 = sext i32 %3 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 47, i8* %16
%17 = add nsw i32 %3, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %9, %9, %14, %2
ret void
}