#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 */
typedef size_t uint32_t;
typedef int /*<<< orphan*/ path;
typedef size_t int32_t;

/* Variables and functions */
char *dirname(char *name) {
  static char path[100];
  uint32_t i = 0;
  int32_t pos = 0;
  while ((name[i] != 0) && (i < sizeof(path))) {
    if (name[i] == '/') {
      pos = i;
    }
    path[i] = name[i];
    i++;
  }
  path[i] = 0;
  path[pos] = 0;
  return path;
}


x86 assembly (clang, -O0):
<dirname>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     113d <dirname+0x3d>
cmpq   $0x64,-0x10(%rbp)
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    114d <dirname+0x4d>
jmp    1194 <dirname+0x94>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    116a <dirname+0x6a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rcx
lea    0x2eb0(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1118 <dirname+0x18>
mov    -0x10(%rbp),%rcx
lea    0x2e91(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
lea    0x2e82(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e77(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirname>:
mov    (%rdi),%al
test   %al,%al
je     1142 <dirname+0x42>
xor    %ecx,%ecx
lea    0x2f21(%rip),%r8
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x2f,%al
cmove  %rdx,%rcx
mov    %al,(%rdx,%r8,1)
lea    0x1(%rdx),%rsi
movzbl 0x1(%rdi,%rdx,1),%eax
test   %al,%al
je     1146 <dirname+0x46>
cmp    $0x63,%rdx
mov    %rsi,%rdx
jb     1120 <dirname+0x20>
jmp    1146 <dirname+0x46>
xor    %esi,%esi
xor    %ecx,%ecx
lea    0x2ee3(%rip),%rax
movb   $0x0,(%rsi,%rax,1)
movb   $0x0,(%rcx,%rax,1)
ret

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

LLVM IR (-O2):
@dirname.path = internal global [100 x i8] zeroinitializer
define i8* @dirname(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %13, %4 ], [ %2, %1 ]
%6 = phi i64 [ %9, %4 ], [ 0, %1 ]
%7 = phi i64 [ %11, %4 ], [ 0, %1 ]
%8 = icmp eq i8 %5, 47
%9 = select i1 %8, i64 %7, i64 %6
%10 = getelementptr inbounds [100 x i8], [100 x i8]* @dirname.path, i64 0, i64 %7
store i8 %5, i8* %10
%11 = add nuw nsw i64 %7, 1
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
%15 = icmp ult i64 %7, 99
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %4, label %17
17: ; preds = %4, %1
%18 = phi i64 [ 0, %1 ], [ %11, %4 ]
%19 = phi i64 [ 0, %1 ], [ %9, %4 ]
%20 = getelementptr inbounds [100 x i8], [100 x i8]* @dirname.path, i64 0, i64 %18
store i8 0, i8* %20
%21 = getelementptr inbounds [100 x i8], [100 x i8]* @dirname.path, i64 0, i64 %19
store i8 0, i8* %21
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @dirname.path, i64 0, i64 0)
}