#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int split(char const *, int *, int /*<<< orphan*/ *, int *);
char *basename_a(const char *path) {
  int blen, slash;
  char *b;
  int rc;
  rc = split(path, &slash, NULL, &blen);
  if (rc < 0 || blen == 0)
    return NULL;
  b = malloc(blen + 1);
  if (b == NULL)
    return NULL;
  memcpy(b, path + slash + 1, blen);
  b[blen] = '\0';
  return b;
}


x86 assembly (clang, -O0):
<basename_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x14(%rbp),%rcx
call   1030 <split@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1168 <basename_a+0x38>
cmpl   $0x0,-0x14(%rbp)
jne    1175 <basename_a+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11cb <basename_a+0x9b>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119c <basename_a+0x6c>
movq   $0x0,-0x8(%rbp)
jmp    11cb <basename_a+0x9b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename_a>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1030 <split@plt>
test   %eax,%eax
js     1193 <basename_a+0x63>
mov    0x8(%rsp),%r15d
test   %r15d,%r15d
je     1193 <basename_a+0x63>
lea    0x1(%r15),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1191 <basename_a+0x61>
mov    %rax,%rbx
movslq 0xc(%rsp),%rax
lea    (%r14,%rax,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
call   1040 <memcpy@plt>
movslq 0x8(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1193 <basename_a+0x63>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @basename_a(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @split(i8* %8, i32* %5, i32* null, i32* %4)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12, %1
store i8* null, i8** %2
br label %37
16: ; preds = %12
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %16
store i8* null, i8** %2
br label %37
23: ; preds = %16
%24 = load i8*, i8** %6
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i32, i32* %4
%31 = call i32 @memcpy(i8* %24, i8* %29, i32 %30)
%32 = load i8*, i8** %6
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %6
store i8* %36, i8** %2
br label %37
37: ; preds = %23, %22, %15
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
define i8* @basename_a(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @split(i8* %0, i32* %3, i32* null, i32* %2)
%7 = icmp slt i32 %6, 0
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %24, label %11
11: ; preds = %1
%12 = add nsw i32 %8, 1
%13 = call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %24, label %15
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @memcpy(i8* %13, i8* %19, i32 %8)
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %13, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %11, %1, %15
%25 = phi i8* [ %13, %15 ], [ null, %1 ], [ null, %11 ]
ret i8* %25
}