#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(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
char *getFileName(char *file) {
  if (strstr(file, "/") != NULL) {
    char *tmp = (char *)malloc(sizeof(char *));
    strcpy(tmp, file);
    char *dir;
    int l = 0;
    dir = strstr(tmp, "/");
    do {
      l = strlen(dir) + 1;
      tmp = &tmp[strlen(tmp) - l + 2];
      dir = strstr(tmp, "/");
    } while (dir);
    return tmp;
  }
  return file;
}


x86 assembly (clang, -O0):
<getFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11fe <getFileName+0xbe>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    -0x24(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119c <getFileName+0x5c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1206 <getFileName+0xc6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileName>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ae <getFileName+0x6e>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %r14,%rbx
xchg   %ax,%ax
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %ebp,%eax
add    $0x1,%eax
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1180 <getFileName+0x40>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @getFileName(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %37
10: ; preds = %1
%11 = call i64 @malloc(i32 8)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %13, i8* %14)
store i32 0, i32* %6
%16 = load i8*, i8** %4
%17 = call i8* @strstr(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %5
br label %18
18: ; preds = %32, %10
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
%22 = load i8*, i8** %4
%23 = load i8*, i8** %4
%24 = call i32 @strlen(i8* %23)
%25 = load i32, i32* %6
%26 = sub nsw i32 %24, %25
%27 = add nsw i32 %26, 2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %22, i64 %28
store i8* %29, i8** %4
%30 = load i8*, i8** %4
%31 = call i8* @strstr(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %31, i8** %5
br label %32
32: ; preds = %18
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %18, label %35
35: ; preds = %32
%36 = load i8*, i8** %4
store i8* %36, i8** %2
br label %39
37: ; preds = %1
%38 = load i8*, i8** %3
store i8* %38, i8** %2
br label %39
39: ; preds = %37, %35
%40 = load i8*, i8** %2
ret i8* %40
}

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