#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*/ memcpy(char *, char const *, int);
scalar_t__ strlen(char const *);
char *iupStrFileGetPath(const char *file_name) {
  if (!file_name)
    return NULL;
  else {
    int len = (int)strlen(file_name) - 1;
    while (len != 0) {
      if (file_name[len] == '\\' || file_name[len] == '/') {
        len++;
        break;
      }
      len--;
    }
    if (len == 0)
      return NULL;
    {
      char *path = malloc(len + 1);
      memcpy(path, file_name, len);
      path[len] = 0;
      return path;
    }
  }
}


x86 assembly (clang, -O0):
<iupStrFileGetPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <iupStrFileGetPath+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11fd <iupStrFileGetPath+0xcd>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b3 <iupStrFileGetPath+0x83>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     1197 <iupStrFileGetPath+0x67>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11a5 <iupStrFileGetPath+0x75>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b3 <iupStrFileGetPath+0x83>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <iupStrFileGetPath+0x33>
cmpl   $0x0,-0x14(%rbp)
jne    11ca <iupStrFileGetPath+0x9a>
movq   $0x0,-0x8(%rbp)
jmp    11fd <iupStrFileGetPath+0xcd>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iupStrFileGetPath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11d5 <iupStrFileGetPath+0xa5>
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%rcx
shl    $0x20,%rcx
movslq %eax,%rdx
movabs $0x100000000,%rbx
add    %rcx,%rbx
lea    (%rdx,%r12,1),%rdi
add    $0xffffffffffffffff,%rdi
xor    %r14d,%r14d
movabs $0xffffffff00000000,%rsi
ff ff ff
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
lea    (%rax,%rcx,1),%edx
cmp    $0x1,%edx
je     11d8 <iupStrFileGetPath+0xa8>
movzbl (%rdi,%rcx,1),%edx
add    $0xffffffffffffffff,%rcx
add    %rsi,%rbx
cmp    $0x5c,%dl
je     119d <iupStrFileGetPath+0x6d>
cmp    $0x2f,%dl
jne    1180 <iupStrFileGetPath+0x50>
lea    (%rax,%rcx,1),%rdx
cmp    $0xffffffff,%edx
je     11d5 <iupStrFileGetPath+0xa5>
lea    (%rax,%rcx,1),%r15
add    $0x1,%r15
lea    (%rax,%rcx,1),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
sar    $0x20,%rbx
movb   $0x0,(%r14,%rbx,1)
jmp    11d8 <iupStrFileGetPath+0xa8>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @iupStrFileGetPath(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %25, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = shl i64 %4, 32
%6 = ashr exact i64 %5, 32
br label %7
7: ; preds = %12, %3
%8 = phi i64 [ %9, %12 ], [ %6, %3 ]
%9 = add nsw i64 %8, -1
%10 = trunc i64 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 %9
%14 = load i8, i8* %13
switch i8 %14, label %7 [
i8 92, label %15
i8 47, label %15
]
15: ; preds = %12, %12
%16 = trunc i64 %8 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = add nsw i32 %16, 1
%20 = tail call i8* @malloc(i32 %19)
%21 = tail call i32 @memcpy(i8* %20, i8* %0, i32 %16)
%22 = shl i64 %8, 32
%23 = ashr exact i64 %22, 32
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %7, %18, %15, %1
%26 = phi i8* [ null, %1 ], [ %20, %18 ], [ null, %15 ], [ null, %7 ]
ret i8* %26
}