#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
char *filenopath(char *filepath) {
  static char filename[1500];
  char *bar;
  if ((bar = strrchr(filepath, '/')))
    bar++;
  else {
    printf("Filename %s must be an absolute path.\n", filepath);
    exit(EXIT_FAILURE);
  }
  strcpy(filename, bar);
  return filename;
}


x86 assembly (clang, -O0):
<filenopath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1179 <filenopath+0x39>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1197 <filenopath+0x57>
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0x2eae(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ea2(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filenopath>:
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     116e <filenopath+0x2e>
add    $0x1,%rax
lea    0x2ef2(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe8b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@filenopath.filename = internal global [1500 x i8] zeroinitializer
@.str = [39 x i8] c"Filename %s must be an absolute path.\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @filenopath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @strrchr(i8* %4, i8 signext 47)
store i8* %5, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %3
br label %15
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %7
%16 = load i8*, i8** %3
%17 = call i32 @strcpy(i8* getelementptr inbounds ([1500 x i8], [1500 x i8]* @filenopath.filename, i64 0, i64 0), i8* %16)
ret i8* getelementptr inbounds ([1500 x i8], [1500 x i8]* @filenopath.filename, i64 0, i64 0)
}

LLVM IR (-O2):
@filenopath.filename = internal global [1500 x i8] zeroinitializer
@.str = [39 x i8] c"Filename %s must be an absolute path.\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @filenopath(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = tail call i32 @strcpy(i8* getelementptr inbounds ([1500 x i8], [1500 x i8]* @filenopath.filename, i64 0, i64 0), i8* %5)
ret i8* getelementptr inbounds ([1500 x i8], [1500 x i8]* @filenopath.filename, i64 0, i64 0)
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
}