#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 /*<<< orphan*/ I_Error(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
int /*<<< orphan*/ toupper(int);
void ExtractFileBase(char *path, char *dest) {
  char *src;
  int length;
  src = path + strlen(path) - 1;
  while (src != path && *(src - 1) != '\\' && *(src - 1) != '/') {
    src--;
  }
  memset(dest, 0, 8);
  length = 0;
  while (*src && *src != '.') {
    if (++length == 9)
      I_Error("Filename base of %s >8 chars", path);
    *dest++ = toupper((int)*src++);
  }
}


x86 assembly (clang, -O0):
<ExtractFileBase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%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),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x29(%rbp)
je     11af <ExtractFileBase+0x6f>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%ecx
xor    %eax,%eax
cmp    $0x5c,%ecx
mov    %al,-0x29(%rbp)
je     11af <ExtractFileBase+0x6f>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11bf <ExtractFileBase+0x7f>
jmp    11d0 <ExtractFileBase+0x90>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <ExtractFileBase+0x35>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2a(%rbp)
je     120c <ExtractFileBase+0xcc>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    121c <ExtractFileBase+0xdc>
jmp    126d <ExtractFileBase+0x12d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x9,%eax
jne    123e <ExtractFileBase+0xfe>
mov    -0x8(%rbp),%rsi
lea    0xdc7(%rip),%rdi
call   1060 <I_Error@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11e7 <ExtractFileBase+0xa7>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExtractFileBase>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
movslq %eax,%r13
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%r13
je     117d <ExtractFileBase+0x3d>
movzbl -0x2(%r12,%r13,1),%eax
add    $0xffffffffffffffff,%r13
cmp    $0x5c,%al
je     1178 <ExtractFileBase+0x38>
cmp    $0x2f,%al
jne    1160 <ExtractFileBase+0x20>
add    %r12,%r13
jmp    1180 <ExtractFileBase+0x40>
mov    %r12,%r13
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
lea    0xe68(%rip),%r15
jmp    11b0 <ExtractFileBase+0x70>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
movzbl 0x0(%r13,%rbx,1),%eax
test   %al,%al
je     11d6 <ExtractFileBase+0x96>
cmp    $0x2e,%al
je     11d6 <ExtractFileBase+0x96>
cmp    $0x8,%ebx
jne    11a0 <ExtractFileBase+0x60>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <I_Error@plt>
movzbl 0x0(%r13,%rbx,1),%eax
jmp    11a0 <ExtractFileBase+0x60>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Filename base of %s >8 chars\00"
define void @ExtractFileBase(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
store i8* %12, i8** %5
br label %13
13: ; preds = %31, %2
%14 = load i8*, i8** %5
%15 = load i8*, i8** %3
%16 = icmp ne i8* %14, %15
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 -1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 92
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 47
br label %29
29: ; preds = %23, %17, %13
%30 = phi i1 [ false, %17 ], [ false, %13 ], [ %28, %23 ]
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 -1
store i8* %33, i8** %5
br label %13
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = call i32 @memset(i8* %35, i32 0, i32 8)
store i32 0, i32* %6
br label %37
37: ; preds = %56, %34
%38 = load i8*, i8** %5
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i8*, i8** %5
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 46
br label %47
47: ; preds = %42, %37
%48 = phi i1 [ false, %37 ], [ %46, %42 ]
br i1 %48, label %49, label %65
49: ; preds = %47
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
%52 = icmp eq i32 %51, 9
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i8*, i8** %3
%55 = call i32 @I_Error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %53, %49
%57 = load i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %5
%59 = load i8, i8* %57
%60 = sext i8 %59 to i32
%61 = call i32 @toupper(i32 %60)
%62 = trunc i32 %61 to i8
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %4
store i8 %62, i8* %63
br label %37
65: ; preds = %47
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Filename base of %s >8 chars\00"
define void @ExtractFileBase(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 = getelementptr inbounds i8, i8* %7, i64 -2
%12 = load i8, i8* %11
switch i8 %12, label %6 [
i8 92, label %13
i8 47, label %13
]
13: ; preds = %10, %10, %6
%14 = phi i8* [ %8, %10 ], [ %8, %10 ], [ %0, %6 ]
%15 = tail call i32 @memset(i8* %1, i32 0, i32 8)
br label %16
16: ; preds = %27, %13
%17 = phi i8* [ %1, %13 ], [ %33, %27 ]
%18 = phi i8* [ %14, %13 ], [ %29, %27 ]
%19 = phi i32 [ 0, %13 ], [ %22, %27 ]
%20 = load i8, i8* %18
switch i8 %20, label %21 [
i8 0, label %34
i8 46, label %34
]
21: ; preds = %16
%22 = add nuw nsw i32 %19, 1
%23 = icmp eq i32 %22, 9
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call i32 @I_Error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
%26 = load i8, i8* %18
br label %27
27: ; preds = %24, %21
%28 = phi i8 [ %26, %24 ], [ %20, %21 ]
%29 = getelementptr inbounds i8, i8* %18, i64 1
%30 = sext i8 %28 to i32
%31 = tail call i32 @toupper(i32 %30)
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %32, i8* %17
br label %16
34: ; preds = %16, %16
ret void
}