#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__ malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
char *make_basename(char *fullname) {
  char *cp;
  char *new_string;
  cp = strrchr(fullname, '/');
  if (!cp) {
    new_string = (char *)malloc(strlen(fullname) + 1);
    strcpy(new_string, fullname);
  } else {
    cp++;
    new_string = (char *)malloc(strlen(cp) + 1);
    strcpy(new_string, cp);
  }
  return new_string;
}


x86 assembly (clang, -O0):
<make_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <make_basename+0x54>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11c6 <make_basename+0x86>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_basename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     117a <make_basename+0x3a>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
jmp    1194 <make_basename+0x54>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @make_basename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strrchr(i8* %5, i8 signext 47)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %15, i8* %16)
br label %29
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %22, 1
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %4
%26 = load i8*, i8** %4
%27 = load i8*, i8** %3
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %29
29: ; preds = %18, %9
%30 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
define i8* @make_basename(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 1
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strcpy(i8* %8, i8* %0)
br label %17
10: ; preds = %1
%11 = getelementptr inbounds i8, i8* %2, i64 1
%12 = tail call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = tail call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @strcpy(i8* %15, i8* %11)
br label %17
17: ; preds = %10, %4
%18 = phi i8* [ %15, %10 ], [ %8, %4 ]
ret i8* %18
}