#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 rb_enc_mbclen(char const *, char const *);
char *find_dirsep(const char *p, const char *pend, int flags) {
  register char c;
  while ((c = *p++) != 0) {
    switch (c) {
    case '\\':
    case '/':
      return (char *)p - 1;
    }
    p = ((p - 1) + rb_enc_mbclen((p - 1), (pend)));
  }
  return (char *)p - 1;
}


x86 assembly (clang, -O0):
<find_dirsep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11ac <find_dirsep+0x9c>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x2f,%eax
je     1169 <find_dirsep+0x59>
jmp    1158 <find_dirsep+0x48>
mov    -0x24(%rbp),%eax
sub    $0x5c,%eax
jne    117a <find_dirsep+0x6a>
jmp    1169 <find_dirsep+0x59>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <find_dirsep+0xa8>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <rb_enc_mbclen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1123 <find_dirsep+0x13>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_dirsep>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%cl
test   %cl,%cl
je     114c <find_dirsep+0x3c>
mov    %rsi,%r14
movsbl %cl,%eax
cmp    $0x2f,%eax
je     114c <find_dirsep+0x3c>
cmp    $0x5c,%eax
je     114c <find_dirsep+0x3c>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <rb_enc_mbclen@plt>
movslq %eax,%rcx
lea    (%rbx,%rcx,1),%rax
movzbl (%rbx,%rcx,1),%ecx
mov    %rax,%rbx
test   %cl,%cl
jne    1120 <find_dirsep+0x10>
jmp    114f <find_dirsep+0x3f>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @find_dirsep(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
br label %9
9: ; preds = %21, %3
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %5
%12 = load i8, i8* %10
store i8 %12, i8* %8
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %9
%16 = load i8, i8* %8
%17 = sext i8 %16 to i32
switch i32 %17, label %21 [
i32 92, label %18
i32 47, label %18
]
18: ; preds = %15, %15
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8* %20, i8** %4
br label %33
21: ; preds = %15
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8*, i8** %6
%27 = call i32 @rb_enc_mbclen(i8* %25, i8* %26)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %23, i64 %28
store i8* %29, i8** %5
br label %9
30: ; preds = %9
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 -1
store i8* %32, i8** %4
br label %33
33: ; preds = %30, %18
%34 = load i8*, i8** %4
ret i8* %34
}

LLVM IR (-O2):
define i8* @find_dirsep(i8* %0, i8* %1, i32 %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3, %10
%7 = phi i8 [ %14, %10 ], [ %4, %3 ]
%8 = phi i8* [ %13, %10 ], [ %0, %3 ]
%9 = sext i8 %7 to i32
switch i32 %9, label %10 [
i32 92, label %16
i32 47, label %16
]
10: ; preds = %6
%11 = tail call i32 @rb_enc_mbclen(i8* %8, i8* %1)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %6
16: ; preds = %6, %6, %10, %3
%17 = phi i8* [ %0, %3 ], [ %13, %10 ], [ %8, %6 ], [ %8, %6 ]
ret i8* %17
}