#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 extractFileonly(char *filename, char *fileonly) {
  int i, nchar, nslash;
  nchar = strlen(filename);
  nslash = 0;
  for (i = 0; i < nchar; i++) {
    if (filename[nchar - i] == '/' || filename[nchar - i] == '\\') {
      nslash = nchar - i + 1;
      break;
    }
  }
  strcpy(fileonly, &filename[nslash]);
}


x86 assembly (clang, -O0):
<extractFileonly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ae <extractFileonly+0x8e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     118a <extractFileonly+0x6a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    119b <extractFileonly+0x7b>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ae <extractFileonly+0x8e>
jmp    11a0 <extractFileonly+0x80>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <extractFileonly+0x2a>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractFileonly>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
jle    1177 <extractFileonly+0x57>
mov    %eax,%ecx
mov    %rcx,%rdx
shl    $0x20,%rdx
movabs $0x100000000,%rax
add    %rdx,%rax
movabs $0xffffffff00000000,%rsi
ff ff ff
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx,%rcx,1),%edx
cmp    $0x5c,%dl
je     117b <extractFileonly+0x5b>
cmp    $0x2f,%dl
je     117b <extractFileonly+0x5b>
add    %rsi,%rax
add    $0xffffffffffffffff,%rcx
jne    1160 <extractFileonly+0x40>
xor    %eax,%eax
jmp    117f <extractFileonly+0x5f>
sar    $0x20,%rax
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

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

LLVM IR (-O2):
define void @extractFileonly(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = zext i32 %3 to i64
%7 = zext i32 %3 to i64
br label %8
8: ; preds = %5, %17
%9 = phi i64 [ 0, %5 ], [ %18, %17 ]
%10 = sub nsw i64 %6, %9
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %17 [
i8 47, label %13
i8 92, label %13
]
13: ; preds = %8, %8
%14 = shl i64 %10, 32
%15 = add i64 %14, 4294967296
%16 = ashr exact i64 %15, 32
br label %20
17: ; preds = %8
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %7
br i1 %19, label %20, label %8
20: ; preds = %17, %2, %13
%21 = phi i64 [ %16, %13 ], [ 0, %2 ], [ 0, %17 ]
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = tail call i32 @strcpy(i8* %1, i8* %22)
ret void
}