#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 /*<<< orphan*/ strncpy(char *, char const *, int);
char const *strrchr(char const *, char);
void getDirectory(const char *filename, char *directorySpec) {
  int lengthOfDirectory;
  if (strrchr(filename, '/') != 0) {
    lengthOfDirectory = strrchr(filename, '/') - filename;
    strncpy(directorySpec, filename, lengthOfDirectory);
    directorySpec[lengthOfDirectory] = '\0';
  } else {
    strcpy(directorySpec, ".");
  }
}


x86 assembly (clang, -O0):
<getDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
cmp    $0x0,%rax
je     1191 <getDirectory+0x61>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11a1 <getDirectory+0x71>
mov    -0x10(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1040 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDirectory>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     116b <getDirectory+0x3b>
mov    %rax,%rbx
sub    %r15,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe8e(%rip),%rsi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @getDirectory(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i8* @strrchr(i8* %6, i8 signext 47)
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
%12 = load i8*, i8** %3
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %5
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = call i32 @strncpy(i8* %17, i8* %18, i32 %19)
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
br label %28
25: ; preds = %2
%26 = load i8*, i8** %4
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %25, %9
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @getDirectory(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = ptrtoint i8* %3 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = trunc i64 %8 to i32
%10 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %9)
%11 = shl i64 %8, 32
%12 = ashr exact i64 %11, 32
%13 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 0, i8* %13
br label %16
14: ; preds = %2
%15 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %5
ret void
}