#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 Sfile_component_pointer(char *, char **, int, int /*<<< orphan*/);
int Sfile_count_components(char *, int /*<<< orphan*/);
scalar_t__ Sfile_str(char *, char *, int /*<<< orphan*/);
char *strchr(char *, char);
int Sfile_leafname(char *path, char leafname[4096], int flag) {
  int count, ret;
  char *lpt;
  leafname[0] = 0;
  count = Sfile_count_components(path, 0);
  if (count == 0)
    return (0);
  ret = Sfile_component_pointer(path, &lpt, count - 1, 0);
  if (ret <= 0)
    return (ret);
  if (Sfile_str(leafname, lpt, 0) <= 0)
    return (0);
  lpt = strchr(leafname, '/');
  if (lpt != NULL)
    *lpt = 0;
  return (1);
}


x86 assembly (clang, -O0):
<Sfile_leafname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <Sfile_count_components@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    117e <Sfile_leafname+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11fb <Sfile_leafname+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
lea    -0x30(%rbp),%rsi
xor    %ecx,%ecx
call   1040 <Sfile_component_pointer@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     11ab <Sfile_leafname+0x6b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <Sfile_leafname+0xbb>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1060 <Sfile_str@plt>
cmp    $0x0,%rax
jg     11d0 <Sfile_leafname+0x90>
movl   $0x0,-0x4(%rbp)
jmp    11fb <Sfile_leafname+0xbb>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11f4 <Sfile_leafname+0xb4>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sfile_leafname>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,(%rsi)
xor    %ebp,%ebp
xor    %esi,%esi
call   1050 <Sfile_count_components@plt>
test   %eax,%eax
je     11aa <Sfile_leafname+0x6a>
add    $0xffffffff,%eax
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <Sfile_component_pointer@plt>
test   %eax,%eax
jle    11a8 <Sfile_leafname+0x68>
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1060 <Sfile_str@plt>
test   %rax,%rax
jle    11aa <Sfile_leafname+0x6a>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11aa <Sfile_leafname+0x6a>
movb   $0x0,(%rax)
jmp    11aa <Sfile_leafname+0x6a>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Sfile_leafname(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 0, i8* %12
%13 = load i8*, i8** %5
%14 = call i32 @Sfile_count_components(i8* %13, i32 0)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %4
br label %41
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i32, i32* %8
%21 = sub nsw i32 %20, 1
%22 = call i32 @Sfile_component_pointer(i8* %19, i8** %10, i32 %21, i32 0)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = load i32, i32* %9
store i32 %26, i32* %4
br label %41
27: ; preds = %18
%28 = load i8*, i8** %6
%29 = load i8*, i8** %10
%30 = call i64 @Sfile_str(i8* %28, i8* %29, i32 0)
%31 = icmp sle i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 0, i32* %4
br label %41
33: ; preds = %27
%34 = load i8*, i8** %6
%35 = call i8* @strchr(i8* %34, i8 signext 47)
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i8*, i8** %10
store i8 0, i8* %39
br label %40
40: ; preds = %38, %33
store i32 1, i32* %4
br label %41
41: ; preds = %40, %32, %25, %17
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
define i32 @Sfile_leafname(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8 0, i8* %1
%6 = tail call i32 @Sfile_count_components(i8* %0, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %3
%9 = add nsw i32 %6, -1
%10 = call i32 @Sfile_component_pointer(i8* %0, i8** %4, i32 %9, i32 0)
%11 = icmp slt i32 %10, 1
br i1 %11, label %20, label %12
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = call i64 @Sfile_str(i8* %1, i8* %13, i32 0)
%15 = icmp slt i64 %14, 1
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = call i8* @strchr(i8* %1, i8 signext 47)
%18 = icmp eq i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %16
store i8 0, i8* %17
br label %20
20: ; preds = %16, %19, %12, %8, %3
%21 = phi i32 [ 0, %3 ], [ %10, %8 ], [ 0, %12 ], [ 1, %19 ], [ 1, %16 ]
ret i32 %21
}