#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 */
char *secGetStringPart(char const *, int, int);
int strlen(char const *);
char *parseFilename(const char *cp_filename) {
  char *cp_name = NULL;
  int i_str_end = strlen(cp_filename) - 1;
  int i_str_begin = strlen(cp_filename) - 1;
  for (; i_str_begin >= 0 && cp_filename[i_str_begin] != '/'; i_str_begin--)
    ;
  cp_name = secGetStringPart(cp_filename, i_str_begin + 1, i_str_end);
  return cp_name;
}


x86 assembly (clang, -O0):
<parseFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jl     1176 <parseFilename+0x56>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1186 <parseFilename+0x66>
jmp    1199 <parseFilename+0x79>
jmp    118b <parseFilename+0x6b>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1152 <parseFilename+0x32>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x14(%rbp),%edx
call   1040 <secGetStringPart@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseFilename>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %esi,%esi
test   %eax,%eax
cmovs  %eax,%esi
xchg   %ax,%ax
test   %ecx,%ecx
jle    1157 <parseFilename+0x37>
lea    -0x1(%rcx),%rax
cmpb   $0x2f,-0x1(%rbx,%rcx,1)
mov    %rax,%rcx
jne    1140 <parseFilename+0x20>
add    $0x1,%eax
mov    %eax,%esi
add    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <secGetStringPart@plt>

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

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