#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*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void get_parent_path(char *path, char *parent) {
  char tmp[256];
  int i = 0;
  int len = strlen(path);
  int first = 0;
  strcpy(tmp, path);
  if (!strcmp(path, ".") || !strcmp(path, "..")) {
    strcpy(parent, path);
    return;
  }
  for (i = 0; i < len; i++) {
    if (tmp[i] == '/') {
      first = i;
      break;
    }
  }
  for (i = len - 1; i >= 0; i--) {
    if (tmp[i] == '/' && i != first) {
      tmp[i] = '\0';
      strcpy(parent, tmp);
      break;
    } else if (tmp[i] == '/' && i == first) {
      strcpy(parent, "/");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<get_parent_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x114(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11a8 <get_parent_path+0x78>
mov    -0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ba <get_parent_path+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12df <get_parent_path+0x1af>
movl   $0x0,-0x114(%rbp)
mov    -0x114(%rbp),%eax
cmp    -0x118(%rbp),%eax
jge    1218 <get_parent_path+0xe8>
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11ff <get_parent_path+0xcf>
mov    -0x114(%rbp),%eax
mov    %eax,-0x11c(%rbp)
jmp    1218 <get_parent_path+0xe8>
jmp    1204 <get_parent_path+0xd4>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    11c4 <get_parent_path+0x94>
mov    -0x118(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jl     12df <get_parent_path+0x1af>
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1282 <get_parent_path+0x152>
mov    -0x114(%rbp),%eax
cmp    -0x11c(%rbp),%eax
je     1282 <get_parent_path+0x152>
movslq -0x114(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12df <get_parent_path+0x1af>
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    12c1 <get_parent_path+0x191>
mov    -0x114(%rbp),%eax
cmp    -0x11c(%rbp),%eax
jne    12c1 <get_parent_path+0x191>
mov    -0x10(%rbp),%rdi
lea    0xd4c(%rip),%rsi
call   1030 <strcpy@plt>
jmp    12df <get_parent_path+0x1af>
jmp    12c6 <get_parent_path+0x196>
jmp    12cb <get_parent_path+0x19b>
mov    -0x114(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x114(%rbp)
jmp    1227 <get_parent_path+0xf7>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_parent_path>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11df <get_parent_path+0xaf>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11df <get_parent_path+0xaf>
mov    %ebp,%ecx
test   %ebp,%ebp
jle    119f <get_parent_path+0x6f>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x2f,(%rsp,%rax,1)
je     11a1 <get_parent_path+0x71>
add    $0x1,%rax
cmp    %rax,%rcx
jne    1190 <get_parent_path+0x60>
xor    %eax,%eax
add    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rcx,%rdx
add    $0x1,%ecx
test   %ecx,%ecx
jle    11f8 <get_parent_path+0xc8>
movzbl (%rsp,%rdx,1),%ebx
cmp    $0x2f,%bl
jne    11c8 <get_parent_path+0x98>
cmp    %rdx,%rax
jne    11e7 <get_parent_path+0xb7>
lea    -0x1(%rdx),%rcx
cmp    $0x2f,%bl
jne    11b0 <get_parent_path+0x80>
cmp    %rdx,%rax
jne    11b0 <get_parent_path+0x80>
lea    0xe26(%rip),%rsi
jmp    11f0 <get_parent_path+0xc0>
mov    %r14,%rdi
mov    %rbx,%rsi
jmp    11f3 <get_parent_path+0xc3>
mov    %edx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
define void @get_parent_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
store i32 0, i32* %8
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = load i8*, i8** %3
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17, %2
%22 = load i8*, i8** %4
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
br label %86
25: ; preds = %17
store i32 0, i32* %6
br label %26
26: ; preds = %40, %25
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %43
30: ; preds = %26
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = load i32, i32* %6
store i32 %38, i32* %8
br label %43
39: ; preds = %30
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %26
43: ; preds = %37, %26
%44 = load i32, i32* %7
%45 = sub nsw i32 %44, 1
store i32 %45, i32* %6
br label %46
46: ; preds = %83, %43
%47 = load i32, i32* %6
%48 = icmp sge i32 %47, 0
br i1 %48, label %49, label %86
49: ; preds = %46
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 47
br i1 %55, label %56, label %67
56: ; preds = %49
%57 = load i32, i32* %6
%58 = load i32, i32* %8
%59 = icmp ne i32 %57, %58
br i1 %59, label %60, label %67
60: ; preds = %56
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %62
store i8 0, i8* %63
%64 = load i8*, i8** %4
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%66 = call i32 @strcpy(i8* %64, i8* %65)
br label %86
67: ; preds = %56, %49
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 47
br i1 %73, label %74, label %81
74: ; preds = %67
%75 = load i32, i32* %6
%76 = load i32, i32* %8
%77 = icmp eq i32 %75, %76
br i1 %77, label %78, label %81
78: ; preds = %74
%79 = load i8*, i8** %4
%80 = call i32 @strcpy(i8* %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %86
81: ; preds = %74, %67
br label %82
82: ; preds = %81
br label %83
83: ; preds = %82
%84 = load i32, i32* %6
%85 = add nsw i32 %84, -1
store i32 %85, i32* %6
br label %46
86: ; preds = %21, %78, %60, %46
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
define void @get_parent_path(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %0)
%6 = call i32 @strcpy(i8* %4, i8* %0)
%7 = call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = icmp sgt i32 %5, 0
%14 = zext i32 %5 to i64
br i1 %13, label %17, label %25
15: ; preds = %9, %2
%16 = call i32 @strcpy(i8* %1, i8* %0)
br label %48
17: ; preds = %12, %22
%18 = phi i64 [ %23, %22 ], [ 0, %12 ]
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 47
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = add nuw nsw i64 %18, 1
%24 = icmp eq i64 %23, %14
br i1 %24, label %25, label %17
25: ; preds = %22, %17, %12
%26 = phi i64 [ 0, %12 ], [ %18, %17 ], [ 0, %22 ]
%27 = and i64 %26, 4294967295
br label %28
28: ; preds = %43, %25
%29 = phi i64 [ %30, %43 ], [ %14, %25 ]
%30 = add nsw i64 %29, -1
%31 = trunc i64 %29 to i32
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %48
33: ; preds = %28
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %30
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 47
%37 = icmp eq i64 %30, %27
%38 = select i1 %36, i1 true, i1 %37
br i1 %38, label %43, label %39
39: ; preds = %33
%40 = and i64 %30, 4294967295
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @strcpy(i8* %1, i8* %4)
br label %48
43: ; preds = %33
%44 = icmp eq i8 %35, 47
%45 = select i1 %44, i1 %37, i1 false
br i1 %45, label %46, label %28
46: ; preds = %43
%47 = call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %28, %39, %46, %15
ret void
}