#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 *);
int /*<<< orphan*/ timlib_strcpy(char *, char *, int);
char *basename_get_directory(char *argv_0) {
  static char base_name[128];
  char local_buffer[512];
  char *base_name_ptr;
  timlib_strcpy(local_buffer, argv_0, 512);
  base_name_ptr = local_buffer + strlen(local_buffer);
  while (base_name_ptr != local_buffer) {
    if (*base_name_ptr == '\\' || *base_name_ptr == '/') {
      *base_name_ptr = '\0';
      strcpy(base_name, local_buffer);
      return base_name;
      break;
    } else {
      base_name_ptr--;
    }
  }
  return "";
}


x86 assembly (clang, -O0):
<basename_get_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1050 <timlib_strcpy@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x220(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rax
lea    -0x210(%rbp),%rcx
cmp    %rcx,%rax
je     1205 <basename_get_directory+0xd5>
mov    -0x218(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     11c1 <basename_get_directory+0x91>
mov    -0x218(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11ee <basename_get_directory+0xbe>
mov    -0x218(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rsi
lea    0x2e77(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e6b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1210 <basename_get_directory+0xe0>
mov    -0x218(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x218(%rbp)
jmp    1184 <basename_get_directory+0x54>
lea    0xdf4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename_get_directory>:
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%edx
call   1050 <timlib_strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xea6(%rip),%rbx
test   %eax,%eax
je     118c <basename_get_directory+0x5c>
cltq
movzbl (%rsp,%rax,1),%ecx
cmp    $0x5c,%cl
je     1176 <basename_get_directory+0x46>
cmp    $0x2f,%cl
je     1176 <basename_get_directory+0x46>
add    $0xffffffffffffffff,%rax
jne    1160 <basename_get_directory+0x30>
jmp    118c <basename_get_directory+0x5c>
movb   $0x0,(%rsp,%rax,1)
lea    0x2ecf(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x200,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@basename_get_directory.base_name = internal global [128 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @basename_get_directory(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @timlib_strcpy(i8* %3, i8* %0, i32 512)
%5 = call i32 @strlen(i8* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = sext i32 %5 to i64
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %8
br label %10
10: ; preds = %7, %15
%11 = phi i8* [ %16, %15 ], [ %9, %7 ]
%12 = load i8, i8* %11
switch i8 %12, label %15 [
i8 92, label %13
i8 47, label %13
]
13: ; preds = %10, %10
store i8 0, i8* %11
%14 = call i32 @strcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @basename_get_directory.base_name, i64 0, i64 0), i8* %3)
br label %18
15: ; preds = %10
%16 = getelementptr inbounds i8, i8* %11, i64 -1
%17 = icmp eq i8* %16, %3
br i1 %17, label %18, label %10
18: ; preds = %15, %1, %13
%19 = phi i8* [ getelementptr inbounds ([128 x i8], [128 x i8]* @basename_get_directory.base_name, i64 0, i64 0), %13 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %15 ]
ret i8* %19
}