#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 MAXPATHLEN;
char *substring_copy(char *, int /*<<< orphan*/, int);
char *directory_path(char *s) {
  char *t, *tail = NULL;
  char path[MAXPATHLEN];
  for (t = s; *t; t++) {
    if (((*t) == '/'))
      tail = t;
  }
  if (tail == NULL) {
    return NULL;
  } else {
    return substring_copy(s, 0, tail - s);
  }
}


x86 assembly (clang, -O0):
<directory_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     117b <directory_path+0x6b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1165 <directory_path+0x55>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    116a <directory_path+0x5a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1140 <directory_path+0x30>
cmpq   $0x0,-0x20(%rbp)
jne    119a <directory_path+0x8a>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11bd <directory_path+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <substring_copy@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<directory_path>:
xor    %edx,%edx
mov    %rdi,%rax
jmp    1127 <directory_path+0x17>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdx
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x2f,%cl
je     1120 <directory_path+0x10>
test   %cl,%cl
jne    1123 <directory_path+0x13>
test   %rdx,%rdx
je     1141 <directory_path+0x31>
sub    %edi,%edx
xor    %esi,%esi
jmp    1030 <substring_copy@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
define i8* @directory_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %5
%9 = load i32, i32* @MAXPATHLEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8*, i8** %3
store i8* %13, i8** %4
br label %14
14: ; preds = %26, %1
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i8*, i8** %4
store i8* %24, i8** %5
br label %25
25: ; preds = %23, %18
br label %26
26: ; preds = %25
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
br label %14
29: ; preds = %14
%30 = load i8*, i8** %5
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %29
store i8* null, i8** %2
store i32 1, i32* %8
br label %42
33: ; preds = %29
%34 = load i8*, i8** %3
%35 = load i8*, i8** %5
%36 = load i8*, i8** %3
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = trunc i64 %39 to i32
%41 = call i8* @substring_copy(i8* %34, i32 0, i32 %40)
store i8* %41, i8** %2
store i32 1, i32* %8
br label %42
42: ; preds = %33, %32
%43 = load i8*, i8** %6
%44 = load i8*, i8** %2
ret i8* %44
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
define i8* @directory_path(i8* %0) {
br label %2
2: ; preds = %7, %1
%3 = phi i8* [ null, %1 ], [ %8, %7 ]
%4 = phi i8* [ %0, %1 ], [ %9, %7 ]
%5 = load i8, i8* %4
switch i8 %5, label %7 [
i8 0, label %10
i8 47, label %6
]
6: ; preds = %2
br label %7
7: ; preds = %2, %6
%8 = phi i8* [ %4, %6 ], [ %3, %2 ]
%9 = getelementptr inbounds i8, i8* %4, i64 1
br label %2
10: ; preds = %2
%11 = icmp eq i8* %3, null
br i1 %11, label %18, label %12
12: ; preds = %10
%13 = ptrtoint i8* %3 to i64
%14 = ptrtoint i8* %0 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = tail call i8* @substring_copy(i8* %0, i32 0, i32 %16)
br label %18
18: ; preds = %10, %12
%19 = phi i8* [ %17, %12 ], [ null, %10 ]
ret i8* %19
}