#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*/ free(char *);
char *strdup(char *);
int /*<<< orphan*/ stripTrailingSlashes(char *);
char *strrchr(char *, char);
char *ourDirName(char *origname) {
  char *slash;
  char *name;
  name = strdup(origname);
  stripTrailingSlashes(name);
  slash = strrchr(name, '/');
  if (!slash) {
    free(name);
    return strdup(".");
  } else {
    while (slash > name && *slash == '/')
      --slash;
    slash[1] = '\0';
    return name;
  }
}


x86 assembly (clang, -O0):
<ourDirName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <stripTrailingSlashes@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119d <ourDirName+0x5d>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xe71(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11f6 <ourDirName+0xb6>
jmp    11a2 <ourDirName+0x62>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x21(%rbp)
jbe    11c5 <ourDirName+0x85>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11d5 <ourDirName+0x95>
jmp    11e6 <ourDirName+0xa6>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11a2 <ourDirName+0x62>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ourDirName>:
push   %rbx
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <stripTrailingSlashes@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     118a <ourDirName+0x4a>
cmp    %rbx,%rax
jbe    1181 <ourDirName+0x41>
nopl   0x0(%rax,%rax,1)
cmpb   $0x2f,(%rax)
jne    1181 <ourDirName+0x41>
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
ja     1170 <ourDirName+0x30>
mov    %rbx,%rax
movb   $0x0,0x1(%rax)
mov    %rbx,%rax
pop    %rbx
ret
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe67(%rip),%rdi
pop    %rbx
jmp    1060 <strdup@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @ourDirName(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** %5
%8 = load i8*, i8** %5
%9 = call i32 @stripTrailingSlashes(i8* %8)
%10 = load i8*, i8** %5
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load i8*, i8** %5
%16 = call i32 @free(i8* %15)
%17 = call i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %2
br label %37
18: ; preds = %1
br label %19
19: ; preds = %30, %18
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = icmp ugt i8* %20, %21
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br label %28
28: ; preds = %23, %19
%29 = phi i1 [ false, %19 ], [ %27, %23 ]
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %4
br label %19
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8 0, i8* %35
%36 = load i8*, i8** %5
store i8* %36, i8** %2
br label %37
37: ; preds = %33, %14
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @ourDirName(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = ptrtoint i8* %2 to i64
%4 = tail call i32 @stripTrailingSlashes(i8* %2)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%6 = ptrtoint i8* %5 to i64
%7 = icmp eq i8* %5, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = icmp ugt i8* %5, %2
br i1 %9, label %10, label %23
10: ; preds = %8
%11 = sub i64 %3, %6
%12 = getelementptr i8, i8* %5, i64 %11
br label %16
13: ; preds = %1
%14 = tail call i32 @free(i8* %2)
%15 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %26
16: ; preds = %10, %20
%17 = phi i8* [ %21, %20 ], [ %5, %10 ]
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 47
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %17, i64 -1
%22 = icmp ugt i8* %21, %2
br i1 %22, label %16, label %23
23: ; preds = %16, %20, %8
%24 = phi i8* [ %5, %8 ], [ %12, %20 ], [ %17, %16 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 0, i8* %25
br label %26
26: ; preds = %23, %13
%27 = phi i8* [ %2, %23 ], [ %15, %13 ]
ret i8* %27
}