#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 *);
void ExtractFileBase(char *path, char *dest) {
  char *src;
  src = path + strlen(path) - 1;
  while (src != path && *(src - 1) != '/')
    src--;
  while (*src && *src != '.') {
    *dest++ = *src++;
  }
  *dest = 0;
}


x86 assembly (clang, -O0):
<ExtractFileBase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     1169 <ExtractFileBase+0x59>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1179 <ExtractFileBase+0x69>
jmp    118a <ExtractFileBase+0x7a>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1145 <ExtractFileBase+0x35>
jmp    118f <ExtractFileBase+0x7f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x22(%rbp)
je     11b4 <ExtractFileBase+0xa4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11c4 <ExtractFileBase+0xb4>
jmp    11eb <ExtractFileBase+0xdb>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    118f <ExtractFileBase+0x7f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
define void @ExtractFileBase(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
br label %6
6: ; preds = %10, %2
%7 = phi i8* [ %5, %2 ], [ %8, %10 ]
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp eq i8* %8, %0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 -2
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %6
14: ; preds = %6, %10
%15 = phi i8* [ %8, %10 ], [ %0, %6 ]
br label %16
16: ; preds = %14, %20
%17 = phi i8* [ %22, %20 ], [ %1, %14 ]
%18 = phi i8* [ %21, %20 ], [ %15, %14 ]
%19 = load i8, i8* %18
switch i8 %19, label %20 [
i8 0, label %23
i8 46, label %23
]
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %19, i8* %17
br label %16
23: ; preds = %16, %16
store i8 0, i8* %17
ret void
}