#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 */
char *strdup(char *);
char *strrchr(char *, char);
char *getDirectory(char *path) {
  char *result = strdup(path);
  char *fdir = strrchr(result, '/');
  if (fdir)
    *fdir = 0;
  else {
    fdir = strrchr(result, '\\');
    if (fdir)
      *fdir = 0;
    else {
      fdir = strrchr(result, ':');
      if (fdir)
        fdir[1] = 0;
      else
        return strdup("");
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<getDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1162 <getDirectory+0x42>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d4 <getDirectory+0xb4>
mov    -0x18(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118b <getDirectory+0x6b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11cf <getDirectory+0xaf>
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b5 <getDirectory+0x95>
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11ca <getDirectory+0xaa>
lea    0xe44(%rip),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11dc <getDirectory+0xbc>
jmp    11cf <getDirectory+0xaf>
jmp    11d4 <getDirectory+0xb4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDirectory>:
push   %rbx
call   1040 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
jne    114d <getDirectory+0x2d>
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1155 <getDirectory+0x35>
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     116d <getDirectory+0x4d>
movb   $0x0,0x1(%rax)
jmp    1150 <getDirectory+0x30>
lea    0xe8c(%rip),%rdi
pop    %rbx
jmp    1040 <strdup@plt>

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @getDirectory(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %6, label %5
5: ; preds = %1
store i8 0, i8* %3
br label %17
6: ; preds = %1
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 92)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %6
store i8 0, i8* %7
br label %17
10: ; preds = %6
%11 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 58)
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 0, i8* %14
br label %17
15: ; preds = %10
%16 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %5, %13, %9, %15
%18 = phi i8* [ %16, %15 ], [ %2, %9 ], [ %2, %13 ], [ %2, %5 ]
ret i8* %18
}