#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 const *);
void myopt_ExtractFileName(const char *szPathName, char *szFileName) {
  int k, i, x;
  char c;
  k = strlen(szPathName);
  c = '/';
  i = k - 1;
  while (i >= 0) {
    if (szPathName[i] == c)
      break;
    i--;
  }
  i++;
  x = 0;
  for (;;) {
    szFileName[x] = szPathName[i];
    if (szFileName[x] == '\0' || szFileName[x] == '.')
      break;
    x++;
    i++;
  }
  szFileName[x] = '\0';
}


x86 assembly (clang, -O0):
<myopt_ExtractFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movb   $0x2f,-0x1d(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     116e <myopt_ExtractFileName+0x5e>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x1d(%rbp),%ecx
cmp    %ecx,%eax
jne    1160 <myopt_ExtractFileName+0x50>
jmp    116e <myopt_ExtractFileName+0x5e>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <myopt_ExtractFileName+0x29>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11be <myopt_ExtractFileName+0xae>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11c3 <myopt_ExtractFileName+0xb3>
jmp    11da <myopt_ExtractFileName+0xca>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117e <myopt_ExtractFileName+0x6e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myopt_ExtractFileName>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%edx
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %eax,%ecx
nopl   0x0(%rax,%rax,1)
test   %edx,%edx
jle    1147 <myopt_ExtractFileName+0x37>
lea    -0x1(%rdx),%rax
cmpb   $0x2f,-0x1(%rbx,%rdx,1)
mov    %rax,%rdx
jne    1130 <myopt_ExtractFileName+0x20>
add    $0x1,%eax
mov    %eax,%ecx
movslq %ecx,%rax
add    %rax,%rbx
xor    %eax,%eax
nop
movzbl (%rbx,%rax,1),%ecx
mov    %cl,(%r14,%rax,1)
test   %cl,%cl
je     1167 <myopt_ExtractFileName+0x57>
cmp    $0x2e,%cl
je     1167 <myopt_ExtractFileName+0x57>
add    $0x1,%rax
jmp    1150 <myopt_ExtractFileName+0x40>
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @myopt_ExtractFileName(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
store i8 47, i8* %8
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %6
br label %13
13: ; preds = %27, %2
%14 = load i32, i32* %6
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8, i8* %8
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %16
br label %30
27: ; preds = %16
%28 = load i32, i32* %6
%29 = add nsw i32 %28, -1
store i32 %29, i32* %6
br label %13
30: ; preds = %26, %13
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
store i32 0, i32* %7
br label %33
33: ; preds = %59, %30
%34 = load i8*, i8** %3
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
%43 = load i8*, i8** %4
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %58, label %50
50: ; preds = %33
%51 = load i8*, i8** %4
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 46
br i1 %57, label %58, label %59
58: ; preds = %50, %33
br label %64
59: ; preds = %50
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %33
64: ; preds = %58
%65 = load i8*, i8** %4
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 0, i8* %68
ret void
}

LLVM IR (-O2):
define void @myopt_ExtractFileName(i8* %0, i8* nocapture writeonly %1) {
%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, %2
%7 = phi i64 [ %8, %11 ], [ %4, %2 ]
%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 = sext i32 %18 to i64
br label %20
20: ; preds = %26, %17
%21 = phi i64 [ %28, %26 ], [ %19, %17 ]
%22 = phi i64 [ %27, %26 ], [ 0, %17 ]
%23 = getelementptr inbounds i8, i8* %0, i64 %21
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 %24, i8* %25
switch i8 %24, label %26 [
i8 0, label %29
i8 46, label %29
]
26: ; preds = %20
%27 = add nuw i64 %22, 1
%28 = add i64 %21, 1
br label %20
29: ; preds = %20, %20
%30 = and i64 %22, 4294967295
%31 = getelementptr inbounds i8, i8* %1, i64 %30
store i8 0, i8* %31
ret void
}