#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*/ snprintf(char *, int, char *, char *);
int extract_basename(char *filepath, char *basenamebuf, int basenamebufsize) {
  int i;
  for (i = 0; filepath[i]; i++)
    ;
  while ((i > 0) && (filepath[i] != '/') && (filepath[i - 1] != '/'))
    i--;
  snprintf(basenamebuf, basenamebufsize, "%s", &filepath[i]);
  return 0;
}


x86 assembly (clang, -O0):
<extract_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     114f <extract_basename+0x3f>
jmp    1141 <extract_basename+0x31>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <extract_basename+0x1a>
jmp    1154 <extract_basename+0x44>
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jle    1197 <extract_basename+0x87>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x19(%rbp)
je     1197 <extract_basename+0x87>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a7 <extract_basename+0x97>
jmp    11b5 <extract_basename+0xa5>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1154 <extract_basename+0x44>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rax
add    %rax,%rcx
lea    0xe32(%rip),%rdx
call   1030 <snprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_basename>:
push   %rax
mov    %rsi,%r8
mov    %rdi,%rcx
mov    $0xffffffff,%eax
mov    %rdi,%rsi
nop
add    $0x1,%eax
cmpb   $0x0,(%rsi)
lea    0x1(%rsi),%rsi
jne    1120 <extract_basename+0x10>
xor    %r9d,%r9d
test   %eax,%eax
cmovs  %eax,%r9d
mov    %eax,%esi
add    %rcx,%rsi
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
jle    115a <extract_basename+0x4a>
mov    %eax,%edi
cmpb   $0x2f,(%rsi)
je     115d <extract_basename+0x4d>
lea    -0x1(%rdi),%eax
add    $0xffffffffffffffff,%rsi
cmpb   $0x2f,(%rcx,%rax,1)
jne    1140 <extract_basename+0x30>
jmp    115d <extract_basename+0x4d>
mov    %r9d,%edi
movslq %edi,%rax
add    %rax,%rcx
lea    0xe96(%rip),%rax
mov    %r8,%rdi
mov    %edx,%esi
mov    %rax,%rdx
call   1030 <snprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @extract_basename(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %16, %3
%9 = load i8*, i8** %4
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %8
br label %16
16: ; preds = %15
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
store i32 %18, i32* %7
br label %8
19: ; preds = %8
br label %20
20: ; preds = %42, %19
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 47
br i1 %30, label %31, label %40
31: ; preds = %23
%32 = load i8*, i8** %4
%33 = load i32, i32* %7
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 47
br label %40
40: ; preds = %31, %23, %20
%41 = phi i1 [ false, %23 ], [ false, %20 ], [ %39, %31 ]
br i1 %41, label %42, label %45
42: ; preds = %40
%43 = load i32, i32* %7
%44 = add nsw i32 %43, -1
store i32 %44, i32* %7
br label %20
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = load i32, i32* %6
%48 = load i8*, i8** %4
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = call i32 @snprintf(i8* %46, i32 %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @extract_basename(i8* %0, i8* %1, i32 %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ %9, %4 ], [ 0, %3 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = add nuw i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = trunc i64 %5 to i32
%12 = call i32 @llvm.smin.i32(i32 %11, i32 0)
br label %13
13: ; preds = %10, %21
%14 = phi i32 [ %22, %21 ], [ %11, %10 ]
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = zext i32 %14 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 47
br i1 %20, label %27, label %21
21: ; preds = %16
%22 = add nsw i32 %14, -1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 47
br i1 %26, label %27, label %13
27: ; preds = %13, %16, %21
%28 = phi i32 [ %12, %13 ], [ %14, %16 ], [ %14, %21 ]
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %30)
ret i32 0
}