#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 *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void blGetFilestem(char *filename, char *stem) {
  char *p, *q;
  q = filename;
  if ((p = strchr(q, ']')) != NULL)
    q = p + 1;
  while ((p = strchr(q, ':')) != NULL)
    q = p + 1;
  while ((p = strchr(q, '/')) != NULL)
    q = p + 1;
  while ((p = strchr(q, '\\')) != NULL)
    q = p + 1;
  strcpy(stem, q);
  q = stem;
  for (p = q + strlen(q) - 1; p != q; p--) {
    if (*p == '.') {
      *p = '\0';
      break;
    }
  }
}


x86 assembly (clang, -O0):
<blGetFilestem>:
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    -0x20(%rbp),%rdi
mov    $0x5d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1170 <blGetFilestem+0x40>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1175 <blGetFilestem+0x45>
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a2 <blGetFilestem+0x72>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1175 <blGetFilestem+0x45>
jmp    11a7 <blGetFilestem+0x77>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d4 <blGetFilestem+0xa4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a7 <blGetFilestem+0x77>
jmp    11d9 <blGetFilestem+0xa9>
mov    -0x20(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1206 <blGetFilestem+0xd6>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d9 <blGetFilestem+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1280 <blGetFilestem+0x150>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    126a <blGetFilestem+0x13a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1280 <blGetFilestem+0x150>
jmp    126f <blGetFilestem+0x13f>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1240 <blGetFilestem+0x110>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blGetFilestem>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x5d,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmove  %rbx,%rcx
mov    %rcx,%rbx
mov    %rcx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
jne    1150 <blGetFilestem+0x20>
nopl   0x0(%rax)
mov    %rbx,%r15
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
jne    1170 <blGetFilestem+0x40>
nopl   0x0(%rax)
mov    %r15,%rbx
mov    %r15,%rdi
mov    $0x5c,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%r15
test   %rax,%rax
jne    1190 <blGetFilestem+0x60>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
xchg   %ax,%ax
cmp    $0x1,%rax
je     11da <blGetFilestem+0xaa>
lea    -0x1(%rax),%rcx
cmpb   $0x2e,-0x1(%r14,%rax,1)
mov    %rcx,%rax
jne    11c0 <blGetFilestem+0x90>
movb   $0x0,(%r14,%rcx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @blGetFilestem(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 93)
%4 = icmp eq i8* %3, null
%5 = getelementptr inbounds i8, i8* %3, i64 1
%6 = select i1 %4, i8* %0, i8* %5
br label %7
7: ; preds = %7, %2
%8 = phi i8* [ %6, %2 ], [ %11, %7 ]
%9 = tail call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 58)
%10 = icmp eq i8* %9, null
%11 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %10, label %12, label %7
12: ; preds = %7, %12
%13 = phi i8* [ %16, %12 ], [ %8, %7 ]
%14 = tail call i8* @strchr(i8* dereferenceable(1) %13, i8 signext 47)
%15 = icmp eq i8* %14, null
%16 = getelementptr inbounds i8, i8* %14, i64 1
br i1 %15, label %17, label %12
17: ; preds = %12, %17
%18 = phi i8* [ %21, %17 ], [ %13, %12 ]
%19 = tail call i8* @strchr(i8* dereferenceable(1) %18, i8 signext 92)
%20 = icmp eq i8* %19, null
%21 = getelementptr inbounds i8, i8* %19, i64 1
br i1 %20, label %22, label %17
22: ; preds = %17
%23 = tail call i32 @strcpy(i8* %1, i8* %18)
%24 = tail call i32 @strlen(i8* %1)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
br label %27
27: ; preds = %31, %22
%28 = phi i8* [ %26, %22 ], [ %29, %31 ]
%29 = getelementptr inbounds i8, i8* %28, i64 -1
%30 = icmp eq i8* %29, %1
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8, i8* %29
%33 = icmp eq i8 %32, 46
br i1 %33, label %34, label %27
34: ; preds = %31
store i8 0, i8* %29
br label %35
35: ; preds = %27, %34
ret void
}