#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) - 1;
  while (s != in && *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
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     1178 <COM_FilePath+0x58>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1188 <COM_FilePath+0x68>
jmp    1199 <COM_FilePath+0x79>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <COM_FilePath+0x35>
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>
cltq
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x1,%rax
je     115a <COM_FilePath+0x3a>
lea    -0x1(%rax),%rbx
cmpb   $0x2f,-0x1(%r15,%rax,1)
mov    %rbx,%rax
jne    1140 <COM_FilePath+0x20>
add    %r15,%rbx
jmp    115d <COM_FilePath+0x3d>
mov    %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
%11 = getelementptr inbounds i8, i8* %10, i64 -1
store i8* %11, i8** %5
br label %12
12: ; preds = %23, %2
%13 = load i8*, i8** %5
%14 = load i8*, i8** %3
%15 = icmp ne i8* %13, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 47
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %5
br label %12
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i8*, i8** %3
%29 = load i8*, i8** %5
%30 = load i8*, i8** %3
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = trunc i64 %33 to i32
%35 = call i32 @strncpy(i8* %27, i8* %28, i32 %34)
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = load i8*, i8** %3
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = getelementptr inbounds i8, i8* %36, i64 %41
store i8 0, i8* %42
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
br label %6
6: ; preds = %10, %2
%7 = phi i8* [ %5, %2 ], [ %8, %10 ]
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp eq i8* %8, %0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %6
13: ; preds = %6, %10
%14 = phi i8* [ %0, %6 ], [ %8, %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
}