#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 *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void MakePrevDir(char *preDir, char *Dir) {
  int i;
  char tmpDir[256];
  strcpy(tmpDir, Dir);
  for (i = strlen(tmpDir) - 2; i >= 0; i--) {
    if (tmpDir[i] == '/')
      break;
  }
  if (i < 0) {
    strcpy(preDir, "/");
    return;
  } else {
    strncpy(preDir, tmpDir, i + 1);
    preDir[i + 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<MakePrevDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     119c <MakePrevDir+0x6c>
movslq -0x14(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1189 <MakePrevDir+0x59>
jmp    119c <MakePrevDir+0x6c>
jmp    118e <MakePrevDir+0x5e>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <MakePrevDir+0x35>
cmpl   $0x0,-0x14(%rbp)
jge    11bb <MakePrevDir+0x8b>
mov    -0x8(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11e2 <MakePrevDir+0xb2>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakePrevDir>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     1173 <MakePrevDir+0x43>
mov    %eax,%ebx
lea    -0x2(%rbx),%eax
add    $0xffffffff,%ebx
nopl   (%rax)
mov    %eax,%ecx
cmpb   $0x2f,(%rsp,%rcx,1)
je     1184 <MakePrevDir+0x54>
add    $0xffffffff,%eax
add    $0xffffffffffffffff,%rbx
test   %ebx,%ebx
jg     1160 <MakePrevDir+0x30>
lea    0xe86(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
jmp    1196 <MakePrevDir+0x66>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

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