#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 *malloc(int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *get_parent_path(const char *path) {
  char *ret = malloc(strlen(path) * sizeof(char) + 1);
  strcpy(ret, path);
  if (ret[strlen(ret) - 1] == '/')
    ret[strlen(ret) - 1] = 0;
  int len = strlen(ret);
  while (ret[len] != '/' && len)
    len--;
  ret[len] = '/';
  ret[len + 1] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<get_parent_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11b2 <get_parent_path+0x82>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x29(%rbp)
je     11e2 <get_parent_path+0xb2>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11f2 <get_parent_path+0xc2>
jmp    1200 <get_parent_path+0xd0>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11be <get_parent_path+0x8e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_parent_path>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1172 <get_parent_path+0x42>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
mov    %rcx,%rdx
shl    $0x20,%rdx
movabs $0x200000000,%rax
add    %rdx,%rax
movabs $0xffffffff00000000,%rsi
ff ff ff
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rdi
add    $0xffffffffffffffff,%rcx
setb   %dl
add    %rsi,%rax
cmpb   $0x2f,(%rbx,%rdi,1)
je     11b7 <get_parent_path+0x87>
test   %dl,%dl
jne    11a0 <get_parent_path+0x70>
movb   $0x2f,0x1(%rbx,%rcx,1)
sar    $0x20,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @get_parent_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 1
%9 = add i64 %8, 1
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = load i8*, i8** %2
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, 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 %31
24: ; preds = %1
%25 = load i8*, i8** %3
%26 = load i8*, i8** %3
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %24, %1
%32 = load i8*, i8** %3
%33 = call i32 @strlen(i8* %32)
store i32 %33, i32* %4
br label %34
34: ; preds = %47, %31
%35 = load i8*, i8** %3
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 47
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = load i32, i32* %4
%44 = icmp ne i32 %43, 0
br label %45
45: ; preds = %42, %34
%46 = phi i1 [ false, %34 ], [ %44, %42 ]
br i1 %46, label %47, label %50
47: ; preds = %45
%48 = load i32, i32* %4
%49 = add nsw i32 %48, -1
store i32 %49, i32* %4
br label %34
50: ; preds = %45
%51 = load i8*, i8** %3
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 47, i8* %54
%55 = load i8*, i8** %3
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %55, i64 %58
store i8 0, i8* %59
%60 = load i8*, i8** %3
ret i8* %60
}

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