#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 */
typedef int /*<<< orphan*/ tmp_path;

/* Variables and functions */
int EINVAL;
int ENOBUFS;
int PATH_MAX;
char const *basename(char *);
int dot_to_absolute(char *, size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int get_basename(char *base_name, size_t base_name_size, const char *path) {
  char tmp_path[PATH_MAX];
  int ret;
  if (!path)
    return EINVAL;
  if (!base_name || base_name_size < 1)
    return ENOBUFS;
  strncpy(tmp_path, path, sizeof(tmp_path));
  if (tmp_path[sizeof(tmp_path) - 1] != '\0')
    return ENOBUFS;
  strncpy(base_name, basename(tmp_path), base_name_size);
  if (base_name[base_name_size - 1] != '\0')
    return ENOBUFS;
  ret = dot_to_absolute(base_name, base_name_size);
  if (ret != 0) {
    return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1197 <get_basename+0x67>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1293 <get_basename+0x163>
cmpq   $0x0,-0x10(%rbp)
je     11ad <get_basename+0x7d>
cmpq   $0x1,-0x18(%rbp)
jae    11c5 <get_basename+0x95>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1293 <get_basename+0x163>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x20(%rbp),%rsi
call   1030 <strncpy@plt>
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%rax
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1207 <get_basename+0xd7>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1293 <get_basename+0x163>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
call   1040 <basename@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1259 <get_basename+0x129>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1293 <get_basename+0x163>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <dot_to_absolute@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1285 <get_basename+0x155>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1293 <get_basename+0x163>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_basename>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2ea6(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%rbx
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %rdx,%rdx
je     11a9 <get_basename+0x79>
mov    %rdi,%r15
test   %rdi,%rdi
je     11a0 <get_basename+0x70>
mov    %rsi,%r14
test   %rsi,%rsi
je     11a0 <get_basename+0x70>
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
cmpb   $0x0,-0x1(%r12,%rbx,1)
jne    11a0 <get_basename+0x70>
mov    %rbx,%rdi
call   1040 <basename@plt>
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
cmpb   $0x0,-0x1(%r14,%r15,1)
je     11bf <get_basename+0x8f>
mov    0x2e51(%rip),%rax
jmp    11b0 <get_basename+0x80>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <dot_to_absolute@plt>
jmp    11b2 <get_basename+0x82>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@EINVAL = global i32 0
@ENOBUFS = global i32 0
define i32 @get_basename(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %3
%19 = load i32, i32* @EINVAL
store i32 %19, i32* %4
store i32 1, i32* %11
br label %61
20: ; preds = %3
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i64, i64* %6
%25 = icmp ult i64 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %23, %20
%27 = load i32, i32* @ENOBUFS
store i32 %27, i32* %4
store i32 1, i32* %11
br label %61
28: ; preds = %23
%29 = load i8*, i8** %7
%30 = call i32 @strncpy(i8* %15, i8* %29, i64 %13)
%31 = sub i64 %13, 1
%32 = getelementptr inbounds i8, i8* %15, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %28
%37 = load i32, i32* @ENOBUFS
store i32 %37, i32* %4
store i32 1, i32* %11
br label %61
38: ; preds = %28
%39 = load i8*, i8** %5
%40 = call i8* @basename(i8* %15)
%41 = load i64, i64* %6
%42 = call i32 @strncpy(i8* %39, i8* %40, i64 %41)
%43 = load i8*, i8** %5
%44 = load i64, i64* %6
%45 = sub i64 %44, 1
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = load i32, i32* @ENOBUFS
store i32 %51, i32* %4
store i32 1, i32* %11
br label %61
52: ; preds = %38
%53 = load i8*, i8** %5
%54 = load i64, i64* %6
%55 = call i32 @dot_to_absolute(i8* %53, i64 %54)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = load i32, i32* %10
store i32 %59, i32* %4
store i32 1, i32* %11
br label %61
60: ; preds = %52
store i32 0, i32* %4
store i32 1, i32* %11
br label %61
61: ; preds = %60, %58, %50, %36, %26, %18
%62 = load i8*, i8** %8
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@EINVAL = global i32 0
@ENOBUFS = global i32 0
define i32 @get_basename(i8* %0, i64 %1, i8* %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp eq i8* %2, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = load i32, i32* @EINVAL
br label %35
10: ; preds = %3
%11 = icmp eq i8* %0, null
%12 = icmp eq i64 %1, 0
%13 = or i1 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = load i32, i32* @ENOBUFS
br label %35
16: ; preds = %10
%17 = call i32 @strncpy(i8* %6, i8* %2, i64 %5)
%18 = add nsw i64 %5, -1
%19 = getelementptr inbounds i8, i8* %6, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = load i32, i32* @ENOBUFS
br label %35
24: ; preds = %16
%25 = call i8* @basename(i8* %6)
%26 = call i32 @strncpy(i8* %0, i8* %25, i64 %1)
%27 = add i64 %1, -1
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %24
%32 = load i32, i32* @ENOBUFS
br label %35
33: ; preds = %24
%34 = call i32 @dot_to_absolute(i8* %0, i64 %1)
br label %35
35: ; preds = %33, %31, %22, %14, %8
%36 = phi i32 [ %15, %14 ], [ %23, %22 ], [ %32, %31 ], [ %9, %8 ], [ %34, %33 ]
ret i32 %36
}