#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 normalizePathname(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int ParseFilename(char *fullname, char *filename, char *pathname) {
  int fullLen = strlen(fullname);
  int i, pathLen, fileLen;
  for (i = fullLen - 1; i >= 0; i--) {
    if (fullname[i] == '/')
      break;
  }
  pathLen = i + 1;
  fileLen = fullLen - pathLen;
  strncpy(pathname, fullname, pathLen);
  pathname[pathLen] = 0;
  strncpy(filename, &fullname[pathLen], fileLen);
  filename[fileLen] = 0;
  return normalizePathname(pathname);
}


x86 assembly (clang, -O0):
<ParseFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     1190 <ParseFilename+0x60>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    117d <ParseFilename+0x4d>
jmp    1190 <ParseFilename+0x60>
jmp    1182 <ParseFilename+0x52>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1159 <ParseFilename+0x29>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    -0x28(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1050 <normalizePathname@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ParseFilename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r12d
xor    %ebp,%ebp
test   %eax,%eax
cmovs  %eax,%ebp
mov    %r12,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %eax,%eax
jle    1177 <ParseFilename+0x47>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
jne    1160 <ParseFilename+0x30>
add    $0x1,%ecx
mov    %ecx,%ebp
sub    %ebp,%r12d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movslq %r12d,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <normalizePathname@plt>

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

LLVM IR (-O2):
define i32 @ParseFilename(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = zext i32 %4 to i64
%6 = call i32 @llvm.smin.i32(i32 %4, i32 0)
br label %7
7: ; preds = %12, %3
%8 = phi i64 [ %9, %12 ], [ %5, %3 ]
%9 = add nsw i64 %8, -1
%10 = trunc i64 %8 to i32
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 %9
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %16, label %7
16: ; preds = %12
%17 = trunc i64 %8 to i32
br label %18
18: ; preds = %7, %16
%19 = phi i32 [ %17, %16 ], [ %6, %7 ]
%20 = sub nsw i32 %4, %19
%21 = tail call i32 @strncpy(i8* %2, i8* %0, i32 %19)
%22 = sext i32 %19 to i64
%23 = getelementptr inbounds i8, i8* %2, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds i8, i8* %0, i64 %22
%25 = tail call i32 @strncpy(i8* %1, i8* %24, i32 %20)
%26 = sext i32 %20 to i64
%27 = getelementptr inbounds i8, i8* %1, i64 %26
store i8 0, i8* %27
%28 = tail call i32 @normalizePathname(i8* %2)
ret i32 %28
}