#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*/ strcpy(char *, char *);
int strlen(char *);
void get_filename(char *filename, char *filepath) {
  int i = strlen(filepath) - 1;
  for (; filepath[i] != '\\' && filepath[i] != '/' && i >= 0; i--)
    ;
  strcpy(filename, filepath + i + 1);
  filename[strlen(filepath) - i] = '\0';
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x5c,%ecx
mov    %al,-0x15(%rbp)
je     117d <get_filename+0x5d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x15(%rbp)
je     117d <get_filename+0x5d>
cmpl   $0x0,-0x14(%rbp)
setge  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    118d <get_filename+0x6d>
jmp    11a0 <get_filename+0x80>
jmp    1192 <get_filename+0x72>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <get_filename+0x1f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
cltq
lea    -0x1(%rax),%ecx
nopl   0x0(%rax,%rax,1)
mov    %rax,%rsi
mov    %ecx,%ebx
movzbl -0x1(%r15,%rax,1),%eax
cmp    $0x5c,%al
je     115f <get_filename+0x3f>
cmp    $0x2f,%al
je     115f <get_filename+0x3f>
lea    -0x1(%rbx),%ecx
lea    -0x1(%rsi),%rax
test   %rsi,%rsi
jg     1140 <get_filename+0x20>
add    %r15,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %ebx,%eax
cltq
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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