#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);
char *findExt(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ split_dir_and_file(char const *, char *, char *);
int strlen(char const *);
char *get_basename(const char *in) {
  char *dir = MALLOC(sizeof(char) * (strlen(in) + 2));
  char *file = MALLOC(sizeof(char) * (strlen(in) + 2));
  split_dir_and_file(in, dir, file);
  free(dir);
  char *ext = findExt(file);
  if (ext)
    *ext = '\0';
  return file;
}


x86 assembly (clang, -O0):
<get_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <MALLOC@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <MALLOC@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <split_dir_and_file@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <findExt@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11cf <get_basename+0x7f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_basename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1050 <MALLOC@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1050 <MALLOC@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1070 <split_dir_and_file@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <findExt@plt>
test   %rax,%rax
je     11a1 <get_basename+0x51>
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_basename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 2
%9 = sext i32 %8 to i64
%10 = mul i64 1, %9
%11 = trunc i64 %10 to i32
%12 = call i8* @MALLOC(i32 %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 2
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = trunc i64 %17 to i32
%19 = call i8* @MALLOC(i32 %18)
store i8* %19, i8** %4
%20 = load i8*, i8** %2
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = call i32 @split_dir_and_file(i8* %20, i8* %21, i8* %22)
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %4
%27 = call i8* @findExt(i8* %26)
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %1
%31 = load i8*, i8** %5
store i8 0, i8* %31
br label %32
32: ; preds = %30, %1
%33 = load i8*, i8** %4
ret i8* %33
}

LLVM IR (-O2):
define i8* @get_basename(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 2
%4 = tail call i8* @MALLOC(i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 2
%7 = tail call i8* @MALLOC(i32 %6)
%8 = tail call i32 @split_dir_and_file(i8* %0, i8* %4, i8* %7)
%9 = tail call i32 @free(i8* %4)
%10 = tail call i8* @findExt(i8* %7)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i8 0, i8* %10
br label %13
13: ; preds = %12, %1
ret i8* %7
}