#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 */
scalar_t__ csc_isdelim(char *, char);
int /*<<< orphan*/ csc_strlcpy(char *, char *, int);
int strlen(char *);
char *csc_path_basename(char *path, char *buffer, int blen) {
  char *p;
  for (p = path + strlen(path) - 1; p >= path; p--) {
    if (csc_isdelim("/", *p)) {
      break;
    }
  }
  p++;
  if (buffer) {
    csc_strlcpy(buffer, p, blen);
  }
  return p;
}


x86 assembly (clang, -O0):
<csc_path_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11ae <csc_path_basename+0x7e>
mov    -0x20(%rbp),%rax
lea    0xe7f(%rip),%rdi
movsbl (%rax),%esi
call   1050 <csc_isdelim@plt>
cmp    $0x0,%rax
je     1198 <csc_path_basename+0x68>
jmp    11ae <csc_path_basename+0x7e>
jmp    119d <csc_path_basename+0x6d>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1168 <csc_path_basename+0x38>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d5 <csc_path_basename+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <csc_strlcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csc_path_basename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
lea    0xea9(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rbp
cmp    %rbx,%rcx
jb     117d <csc_path_basename+0x4d>
movsbl 0x0(%rbp),%esi
mov    %r12,%rdi
call   1050 <csc_isdelim@plt>
lea    -0x1(%rbp),%rcx
test   %rax,%rax
je     1160 <csc_path_basename+0x30>
add    $0x1,%rbp
test   %r15,%r15
je     1194 <csc_path_basename+0x64>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <csc_strlcpy@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @csc_path_basename(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %7
br label %14
14: ; preds = %25, %3
%15 = load i8*, i8** %7
%16 = load i8*, i8** %4
%17 = icmp uge i8* %15, %16
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = load i8, i8* %19
%21 = call i64 @csc_isdelim(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
br label %28
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %7
br label %14
28: ; preds = %23, %14
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %7
%31 = load i8*, i8** %5
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = load i8*, i8** %7
%36 = load i32, i32* %6
%37 = call i32 @csc_strlcpy(i8* %34, i8* %35, i32 %36)
br label %38
38: ; preds = %33, %28
%39 = load i8*, i8** %7
ret i8* %39
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @csc_path_basename(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %11, %3
%8 = phi i8* [ %6, %3 ], [ %9, %11 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = icmp ult i8* %9, %0
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = load i8, i8* %9
%13 = tail call i64 @csc_isdelim(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %7, label %15
15: ; preds = %11, %7
%16 = icmp eq i8* %1, null
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = tail call i32 @csc_strlcpy(i8* %1, i8* %8, i32 %2)
br label %19
19: ; preds = %17, %15
ret i8* %8
}