#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 *);
char *get_filename(char *s) {
  int c = strlen(s) - 1;
  while (c > 0) {
    if (s[c] == '/' || s[c] == '\\')
      return &s[c + 1];
    c--;
  }
  return s;
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1186 <get_filename+0x76>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     115f <get_filename+0x4f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    1178 <get_filename+0x68>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    118e <get_filename+0x7e>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    112b <get_filename+0x1b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %eax,%eax
add    %r14,%rax
add    $0x1,%rax
mov    %ecx,%edx
add    $0xffffffff,%edx
add    %r14,%rdx
nop
cmp    $0x2,%ecx
jl     114f <get_filename+0x3f>
movzbl (%rdx),%ebx
add    $0xffffffffffffffff,%rax
cmp    $0x5c,%bl
je     1152 <get_filename+0x42>
add    $0xffffffff,%ecx
add    $0xffffffffffffffff,%rdx
cmp    $0x2f,%bl
jne    1130 <get_filename+0x20>
jmp    1152 <get_filename+0x42>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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