#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 */
char *strrchr(char const *, char);
int zsnprintf(char *, size_t, char *, char const *);
int do_basename(char *bname, size_t bname_len, const char *fname) {
  char *base;
  base = strrchr(fname, '/');
  if (!base) {
    return zsnprintf(bname, bname_len, "%s", fname);
  }
  return zsnprintf(bname, bname_len, "%s", base + 1);
}


x86 assembly (clang, -O0):
<do_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1171 <do_basename+0x51>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xe9c(%rip),%rdx
call   1040 <zsnprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    1190 <do_basename+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
lea    0xe78(%rip),%rdx
call   1040 <zsnprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_basename>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1156 <do_basename+0x36>
add    $0x1,%rax
lea    0xeb5(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rcx
jmp    1166 <do_basename+0x46>
lea    0xea3(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <zsnprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @do_basename(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = call i8* @strrchr(i8* %9, i8 signext 47)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = load i8*, i8** %7
%17 = call i32 @zsnprintf(i8* %14, i64 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 %17, i32* %4
br label %24
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i32 @zsnprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 %23, i32* %4
br label %24
24: ; preds = %18, %13
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @do_basename(i8* %0, i64 %1, i8* %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @zsnprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %11
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 1
%10 = tail call i32 @zsnprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ %10, %8 ], [ %7, %6 ]
ret i32 %12
}