#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ split_dir_and_file(char const *, char *, char *);
int strlen(char const *);
char *getPath(const char *in) {
  char *dir = malloc(sizeof(char) * (strlen(in) + 2));
  char *file = malloc(sizeof(char) * (strlen(in) + 2));
  split_dir_and_file(in, dir, file);
  free(file);
  if (strlen(dir) > 0) {
    if (dir[strlen(dir) - 1] == '/' || dir[strlen(dir) - 1] == '/')
      dir[strlen(dir) - 1] = '\0';
  }
  return dir;
}


x86 assembly (clang, -O0):
<getPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <split_dir_and_file@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    122c <getPath+0xec>
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
je     1206 <getPath+0xc6>
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
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1227 <getPath+0xe7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    122c <getPath+0xec>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPath>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1060 <split_dir_and_file@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c1 <getPath+0x81>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r15,1)
je     11b1 <getPath+0x71>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r15,1)
jne    11c1 <getPath+0x81>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @getPath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 2
%8 = sext i32 %7 to i64
%9 = mul i64 1, %8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 2
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %4
%19 = load i8*, i8** %2
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = call i32 @split_dir_and_file(i8* %19, i8* %20, i8* %21)
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @strlen(i8* %25)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %56
28: ; preds = %1
%29 = load i8*, i8** %3
%30 = load i8*, i8** %3
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 47
br i1 %37, label %48, label %38
38: ; preds = %28
%39 = load i8*, i8** %3
%40 = load i8*, i8** %3
%41 = call i32 @strlen(i8* %40)
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %39, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 47
br i1 %47, label %48, label %55
48: ; preds = %38, %28
%49 = load i8*, i8** %3
%50 = load i8*, i8** %3
%51 = call i32 @strlen(i8* %50)
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %49, i64 %53
store i8 0, i8* %54
br label %55
55: ; preds = %48, %38
br label %56
56: ; preds = %55, %1
%57 = load i8*, i8** %3
ret i8* %57
}

LLVM IR (-O2):
define i8* @getPath(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 2
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 2
%7 = tail call i8* @malloc(i32 %6)
%8 = tail call i32 @split_dir_and_file(i8* %0, i8* %4, i8* %7)
%9 = tail call i32 @free(i8* %7)
%10 = tail call i32 @strlen(i8* %4)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %31
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
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 47
br i1 %18, label %26, label %19
19: ; preds = %12
%20 = tail call i32 @strlen(i8* %4)
%21 = add nsw i32 %20, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %4, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 47
br i1 %25, label %26, label %31
26: ; preds = %19, %12
%27 = tail call i32 @strlen(i8* %4)
%28 = add nsw i32 %27, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %4, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %19, %26, %1
ret i8* %4
}