#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 */
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void move_up_directory(char *abs_path) {
  if (strcmp(abs_path, "/") == 0) {
    abs_path[0] = '\0';
    return;
  }
  int i;
  for (i = strlen(abs_path); i >= 0; i--) {
    if (i == 0) {
      strcpy(abs_path, "/");
      return;
    } else if (abs_path[i] == '/') {
      abs_path[i] = '\0';
      return;
    }
  }
}


x86 assembly (clang, -O0):
<move_up_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1162 <move_up_directory+0x32>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d5 <move_up_directory+0xa5>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11d5 <move_up_directory+0xa5>
cmpl   $0x0,-0xc(%rbp)
jne    1197 <move_up_directory+0x67>
mov    -0x8(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d5 <move_up_directory+0xa5>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11bd <move_up_directory+0x8d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11d5 <move_up_directory+0xa5>
jmp    11c2 <move_up_directory+0x92>
jmp    11c7 <move_up_directory+0x97>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    116e <move_up_directory+0x3e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<move_up_directory>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1181 <move_up_directory+0x51>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     1189 <move_up_directory+0x59>
je     1171 <move_up_directory+0x41>
mov    %eax,%ecx
add    %rbx,%rcx
nopl   0x0(%rax,%rax,1)
mov    %eax,%edx
cmpb   $0x2f,(%rbx,%rdx,1)
je     1186 <move_up_directory+0x56>
add    $0xffffffffffffffff,%rcx
add    $0xffffffff,%eax
jne    1160 <move_up_directory+0x30>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <strcpy@plt>
movb   $0x0,(%rbx)
pop    %rbx
ret
movb   $0x0,(%rcx)
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define void @move_up_directory(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %5
4: ; preds = %1
store i8 0, i8* %0
br label %24
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = icmp eq i32 %6, 0
br i1 %9, label %10, label %12
10: ; preds = %21, %8
%11 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %24
12: ; preds = %8, %21
%13 = phi i32 [ %22, %21 ], [ %6, %8 ]
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = zext i32 %13 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %20
br label %24
21: ; preds = %12
%22 = add nsw i32 %13, -1
%23 = icmp eq i32 %22, 0
br i1 %23, label %10, label %12
24: ; preds = %5, %10, %18, %4
ret void
}