#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__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
char *fromURIPath(const char *path) {
  int len = strlen(path);
  if (len > 1 && path[len - 1] == '/') {
    char *str = (char *)malloc(len);
    if (str != NULL) {
      memcpy(str, path, len - 1);
      str[len - 1] = '\0';
    }
    return str;
  } else {
    return (char *)path;
  }
}


x86 assembly (clang, -O0):
<fromURIPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11b4 <fromURIPath+0x84>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11b4 <fromURIPath+0x84>
mov    -0x14(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a7 <fromURIPath+0x77>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <fromURIPath+0x8c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fromURIPath>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1172 <fromURIPath+0x42>
lea    -0x1(%rax),%r14d
cmpb   $0x2f,(%rbx,%r14,1)
jne    1172 <fromURIPath+0x42>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     116f <fromURIPath+0x3f>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @fromURIPath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %38
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 47
br i1 %18, label %19, label %38
19: ; preds = %10
%20 = load i32, i32* %4
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %36
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 1
%30 = call i32 @memcpy(i8* %26, i8* %27, i32 %29)
%31 = load i8*, i8** %5
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %25, %19
%37 = load i8*, i8** %5
store i8* %37, i8** %2
br label %40
38: ; preds = %10, %1
%39 = load i8*, i8** %3
store i8* %39, i8** %2
br label %40
40: ; preds = %38, %36
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
define i8* @fromURIPath(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 1
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = add nsw i32 %2, -1
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
br i1 %9, label %10, label %17
10: ; preds = %4
%11 = tail call i64 @malloc(i32 %2)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = tail call i32 @memcpy(i8* %12, i8* %0, i32 %5)
%16 = getelementptr inbounds i8, i8* %12, i64 %6
store i8 0, i8* %16
br label %17
17: ; preds = %1, %4, %10, %14
%18 = phi i8* [ %12, %14 ], [ %12, %10 ], [ %0, %4 ], [ %0, %1 ]
ret i8* %18
}