#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 *);
int strlen(char *);
char *dir_name(char *path) {
  char *x;
  int l;
  x = strdup(path);
  if (!x)
    return NULL;
  l = strlen(x);
  while (l > 0 && x[l - 1] != '/') {
    x[l - 1] = '\0';
    l--;
  }
  return x;
}


x86 assembly (clang, -O0):
<dir_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1151 <dir_name+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11bd <dir_name+0x9d>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jle    1186 <dir_name+0x66>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1196 <dir_name+0x76>
jmp    11b5 <dir_name+0x95>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <dir_name+0x3d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_name>:
push   %rbx
call   1040 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1157 <dir_name+0x37>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1157 <dir_name+0x37>
mov    %eax,%eax
add    $0x1,%rax
lea    -0x2(%rax),%ecx
cmpb   $0x2f,(%rbx,%rcx,1)
je     1157 <dir_name+0x37>
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1140 <dir_name+0x20>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @dir_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
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 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i8* null, i8** %2
br label %38
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %5
br label %14
14: ; preds = %28, %11
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 47
br label %26
26: ; preds = %17, %14
%27 = phi i1 [ false, %14 ], [ %25, %17 ]
br i1 %27, label %28, label %36
28: ; preds = %26
%29 = load i8*, i8** %4
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 0, i8* %33
%34 = load i32, i32* %5
%35 = add nsw i32 %34, -1
store i32 %35, i32* %5
br label %14
36: ; preds = %26
%37 = load i8*, i8** %4
store i8* %37, i8** %2
br label %38
38: ; preds = %36, %10
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
define i8* @dir_name(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %2)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %16
%10 = phi i64 [ %8, %7 ], [ %11, %16 ]
%11 = add nsw i64 %10, -1
%12 = and i64 %11, 4294967295
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %18, label %16
16: ; preds = %9
store i8 0, i8* %13
%17 = icmp ugt i64 %10, 1
br i1 %17, label %9, label %18
18: ; preds = %16, %9, %4, %1
ret i8* %2
}