#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*/ strcpy(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
int get_short_filename(char *filename, char *short_filename) {
  char *pchr = NULL;
  if (filename == NULL || short_filename == NULL)
    return -1;
  if (strlen(filename) == 0)
    return -1;
  pchr = strrchr(filename, '/');
  if (pchr != NULL && strlen(pchr) <= 1) {
    strcpy(short_filename, "");
    return -1;
  } else {
    strcpy(short_filename, pchr + 1);
    return 0;
  }
}


x86 assembly (clang, -O0):
<get_short_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115e <get_short_filename+0x2e>
cmpq   $0x0,-0x18(%rbp)
jne    116a <get_short_filename+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <get_short_filename+0xbb>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    1188 <get_short_filename+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <get_short_filename+0xbb>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d3 <get_short_filename+0xa3>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jg     11d3 <get_short_filename+0xa3>
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <get_short_filename+0xbb>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_short_filename>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     1198 <get_short_filename+0x68>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1198 <get_short_filename+0x68>
mov    %rdi,%rbp
call   1040 <strlen@plt>
test   %eax,%eax
je     1198 <get_short_filename+0x68>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1186 <get_short_filename+0x56>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jg     1186 <get_short_filename+0x56>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    1198 <get_short_filename+0x68>
add    $0x1,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @get_short_filename(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i32 -1, i32* %3
br label %35
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %3
br label %35
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = call i8* @strrchr(i8* %19, i8 signext 47)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
%26 = icmp sle i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %35
30: ; preds = %23, %18
%31 = load i8*, i8** %5
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = call i32 @strcpy(i8* %31, i8* %33)
store i32 0, i32* %3
br label %35
35: ; preds = %30, %27, %17, %12
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @get_short_filename(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %6
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i32 @strlen(i8* %10)
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %20
17: ; preds = %12, %9
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = tail call i32 @strcpy(i8* %1, i8* %18)
br label %20
20: ; preds = %6, %2, %17, %15
%21 = phi i32 [ -1, %15 ], [ 0, %17 ], [ -1, %2 ], [ -1, %6 ]
ret i32 %21
}