#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__ strlen(char const *);
int SHPGetLenWithoutExtension(const char *pszBasename) {
  int i;
  int nLen = ((int)(strlen(pszBasename)));
  for (i = nLen - 1; i > 0 && pszBasename[i] != '/' && pszBasename[i] != '\\';
       i--) {
    if (pszBasename[i] == '.') {
      return i;
    }
  }
  return nLen;
}


x86 assembly (clang, -O0):
<SHPGetLenWithoutExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jle    116f <SHPGetLenWithoutExtension+0x5f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x19(%rbp)
je     116f <SHPGetLenWithoutExtension+0x5f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117f <SHPGetLenWithoutExtension+0x6f>
jmp    11b2 <SHPGetLenWithoutExtension+0xa2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    119f <SHPGetLenWithoutExtension+0x8f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b8 <SHPGetLenWithoutExtension+0xa8>
jmp    11a4 <SHPGetLenWithoutExtension+0x94>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <SHPGetLenWithoutExtension+0x21>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHPGetLenWithoutExtension>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    %ecx,%eax
mov    %ecx,%edx
add    $0xffffffff,%edx
add    %rbx,%rdx
cs nopw 0x0(%rax,%rax,1)
cmp    $0x2,%eax
jl     1151 <SHPGetLenWithoutExtension+0x41>
movzbl (%rdx),%ebx
cmp    $0x5c,%bl
je     1151 <SHPGetLenWithoutExtension+0x41>
cmp    $0x2f,%bl
je     1151 <SHPGetLenWithoutExtension+0x41>
add    $0xffffffffffffffff,%rdx
add    $0xffffffffffffffff,%rax
cmp    $0x2e,%bl
jne    1130 <SHPGetLenWithoutExtension+0x20>
pop    %rbx
ret
mov    %rcx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @SHPGetLenWithoutExtension(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = and i64 %2, 4294967295
br label %4
4: ; preds = %9, %1
%5 = phi i64 [ %6, %9 ], [ %3, %1 ]
%6 = add nsw i64 %5, -1
%7 = trunc i64 %5 to i32
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = and i64 %6, 4294967295
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %4 [
i8 47, label %14
i8 92, label %14
i8 46, label %13
]
13: ; preds = %9
br label %14
14: ; preds = %4, %9, %9, %13
%15 = phi i64 [ %6, %13 ], [ %2, %9 ], [ %2, %9 ], [ %2, %4 ]
%16 = trunc i64 %15 to i32
ret i32 %16
}