#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 strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void COM_FilePath(const char *in, char *out) {
  const char *s;
  s = in + strlen(in);
  while (s != in && *s != '/' && *s != '\\')
    s--;
  strncpy(out, in, s - in);
  out[s - in] = 0;
}


x86 assembly (clang, -O0):
<COM_FilePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     1189 <COM_FilePath+0x69>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x21(%rbp)
je     1189 <COM_FilePath+0x69>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1199 <COM_FilePath+0x79>
jmp    11aa <COM_FilePath+0x8a>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <COM_FilePath+0x31>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<COM_FilePath>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
movslq %eax,%rbx
test   %ebx,%ebx
je     1158 <COM_FilePath+0x38>
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
cmp    $0x2f,%al
je     1158 <COM_FilePath+0x38>
cmp    $0x5c,%al
je     1158 <COM_FilePath+0x38>
add    $0xffffffffffffffff,%rbx
jne    1140 <COM_FilePath+0x20>
mov    %r15,%rbx
jmp    115b <COM_FilePath+0x3b>
add    %r15,%rbx
sub    %r15,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @COM_FilePath(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8* %10, i8** %5
br label %11
11: ; preds = %27, %2
%12 = load i8*, i8** %5
%13 = load i8*, i8** %3
%14 = icmp ne i8* %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 47
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 92
br label %25
25: ; preds = %20, %15, %11
%26 = phi i1 [ false, %15 ], [ false, %11 ], [ %24, %20 ]
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %5
br label %11
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = load i8*, i8** %3
%33 = load i8*, i8** %5
%34 = load i8*, i8** %3
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
%39 = call i32 @strncpy(i8* %31, i8* %32, i32 %38)
%40 = load i8*, i8** %4
%41 = load i8*, i8** %5
%42 = load i8*, i8** %3
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
%46 = getelementptr inbounds i8, i8* %40, i64 %45
store i8 0, i8* %46
ret void
}

LLVM IR (-O2):
define void @COM_FilePath(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = icmp eq i32 %3, 0
br i1 %6, label %13, label %7
7: ; preds = %2, %10
%8 = phi i8* [ %11, %10 ], [ %5, %2 ]
%9 = load i8, i8* %8
switch i8 %9, label %10 [
i8 47, label %13
i8 92, label %13
]
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 -1
%12 = icmp eq i8* %11, %0
br i1 %12, label %13, label %7
13: ; preds = %10, %7, %7, %2
%14 = phi i8* [ %5, %2 ], [ %8, %7 ], [ %8, %7 ], [ %0, %10 ]
%15 = ptrtoint i8* %14 to i64
%16 = ptrtoint i8* %0 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %18)
%20 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 0, i8* %20
ret void
}