#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*/ assert(char const *);
char *strrchr(char const *, char);
const char *slash(const char *path_so_far) {
  size_t len;
  const char *last_char;
  assert(path_so_far);
  last_char = strrchr(path_so_far, '\0');
  if (last_char != path_so_far)
    --last_char;
  if (*last_char == '/')
    return "";
  else
    return "/";
}


x86 assembly (clang, -O0):
<slash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     115e <slash+0x3e>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    117e <slash+0x5e>
lea    0xe8c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1189 <slash+0x69>
lea    0xe7b(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slash>:
push   %rbx
mov    %rdi,%rbx
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %rax,%rbx
cmp    $0x1,%rax
adc    $0xffffffffffffffff,%rbx
cmpb   $0x2f,(%rbx)
lea    0xebb(%rip),%rcx
lea    0xeb3(%rip),%rax
cmove  %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"/\00"
define i8* @slash(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @assert(i8* %6)
%8 = load i8*, i8** %3
%9 = call i8* @strrchr(i8* %8, i8 signext 0)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = load i8*, i8** %3
%12 = icmp ne i8* %10, %11
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i32 -1
store i8* %15, i8** %5
br label %16
16: ; preds = %13, %1
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 47
br i1 %20, label %21, label %22
21: ; preds = %16
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %23
22: ; preds = %16
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %23
23: ; preds = %22, %21
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"/\00"
define i8* @slash(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = getelementptr i8, i8* %0, i64 %3
%5 = icmp ne i8* %4, %0
%6 = sext i1 %5 to i64
%7 = getelementptr i8, i8* %4, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
%10 = select i1 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
ret i8* %10
}