#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 *);
const char *extract_fileext(const char *path) {
  int i, n = strlen(path);
  for (i = n - 1; i >= 0; i--) {
    if (path[i] == '/' || path[i] == '\\' || path[i] == ':')
      break;
    if (path[i] == '.')
      return path + i;
  }
  return path + n;
}


x86 assembly (clang, -O0):
<extract_fileext>:
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)
cmpl   $0x0,-0x14(%rbp)
jl     11bb <extract_fileext+0xab>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     117a <extract_fileext+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     117a <extract_fileext+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    117f <extract_fileext+0x6f>
jmp    11bb <extract_fileext+0xab>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11a8 <extract_fileext+0x98>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11ca <extract_fileext+0xba>
jmp    11ad <extract_fileext+0x9d>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <extract_fileext+0x21>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_fileext>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%eax
mov    %rax,%rcx
xchg   %ax,%ax
test   %ecx,%ecx
jle    114a <extract_fileext+0x3a>
movzbl -0x1(%rbx,%rcx,1),%edx
add    $0xffffffffffffffff,%rcx
cmp    $0x39,%dl
jg     1140 <extract_fileext+0x30>
cmp    $0x2e,%dl
je     114e <extract_fileext+0x3e>
cmp    $0x2f,%dl
jne    1120 <extract_fileext+0x10>
jmp    114a <extract_fileext+0x3a>
xchg   %ax,%ax
cmp    $0x5c,%dl
je     114a <extract_fileext+0x3a>
cmp    $0x3a,%dl
jne    1120 <extract_fileext+0x10>
cltq
jmp    1150 <extract_fileext+0x40>
mov    %ecx,%eax
add    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @extract_fileext(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
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, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %0, i64 %6
%11 = load i8, i8* %10
switch i8 %11, label %4 [
i8 47, label %12
i8 92, label %12
i8 58, label %12
i8 46, label %14
]
12: ; preds = %9, %9, %9, %4
%13 = sext i32 %2 to i64
br label %16
14: ; preds = %9
%15 = and i64 %6, 4294967295
br label %16
16: ; preds = %14, %12
%17 = phi i64 [ %13, %12 ], [ %15, %14 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %17
ret i8* %18
}