#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*/ strcpy(char *, char *);
int strlen(char *);
char *dir_up(char *dirpath) {
  static char Path[150];
  int len;
  strcpy(Path, dirpath);
  len = strlen(Path);
  if (len > 1 && Path[len - 1] == '/')
    len--;
  while (Path[len - 1] != '/' && len > 1)
    len--;
  Path[len] = 0;
  return Path;
}


x86 assembly (clang, -O0):
<dir_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0x2f09(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2efd(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    117b <dir_up+0x5b>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2edb(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    117b <dir_up+0x5b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1180 <dir_up+0x60>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2eb0(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0xd(%rbp)
je     11ac <dir_up+0x8c>
cmpl   $0x1,-0xc(%rbp)
setg   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11bc <dir_up+0x9c>
jmp    11ca <dir_up+0xaa>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1180 <dir_up+0x60>
movslq -0xc(%rbp),%rcx
lea    0x2e6b(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e60(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_up>:
push   %rbx
mov    %rdi,%rsi
lea    0x2f15(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     114a <dir_up+0x2a>
lea    -0x1(%rax),%ecx
cmpb   $0x2f,(%rcx,%rbx,1)
cmove  %ecx,%eax
movslq %eax,%rcx
mov    %rcx,%rdx
shl    $0x20,%rdx
movabs $0x100000000,%rax
add    %rdx,%rax
movabs $0xffffffff00000000,%rdx
ff ff ff
nopl   0x0(%rax,%rax,1)
add    %rdx,%rax
cmpb   $0x2f,-0x1(%rcx,%rbx,1)
je     1187 <dir_up+0x67>
lea    -0x1(%rcx),%rsi
cmp    $0x1,%rcx
mov    %rsi,%rcx
jg     1170 <dir_up+0x50>
sar    $0x20,%rax
movb   $0x0,(%rax,%rbx,1)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@dir_up.Path = internal global [150 x i8] zeroinitializer
define i8* @dir_up(i8* %0) {
%2 = tail call i32 @strcpy(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @dir_up.Path, i64 0, i64 0), i8* %0)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([150 x i8], [150 x i8]* @dir_up.Path, i64 0, i64 0))
%4 = icmp sgt i32 %3, 1
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = add nsw i32 %3, -1
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds [150 x i8], [150 x i8]* @dir_up.Path, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
%11 = select i1 %10, i32 %6, i32 %3
br label %12
12: ; preds = %5, %1
%13 = phi i32 [ %3, %1 ], [ %11, %5 ]
%14 = sext i32 %13 to i64
br label %15
15: ; preds = %15, %12
%16 = phi i64 [ %17, %15 ], [ %14, %12 ]
%17 = add nsw i64 %16, -1
%18 = getelementptr inbounds [150 x i8], [150 x i8]* @dir_up.Path, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 47
%21 = icmp sgt i64 %16, 1
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %15, label %23
23: ; preds = %15
%24 = shl i64 %16, 32
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds [150 x i8], [150 x i8]* @dir_up.Path, i64 0, i64 %25
store i8 0, i8* %26
ret i8* getelementptr inbounds ([150 x i8], [150 x i8]* @dir_up.Path, i64 0, i64 0)
}