#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 *strrchr(char *, char);
char *getPathExt(char *path) {
  char *slash = strrchr(path, '/');
  char *backslash = strrchr(path, '\\');
  char *dot = strrchr(path, '.');
  if (!slash || (slash && backslash > slash))
    slash = backslash;
  if (dot && (!slash || (slash && slash < dot)))
    return dot;
  else
    return NULL;
}


x86 assembly (clang, -O0):
<getPathExt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1176 <getPathExt+0x66>
cmpq   $0x0,-0x18(%rbp)
je     117e <getPathExt+0x6e>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    117e <getPathExt+0x6e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ba <getPathExt+0xaa>
cmpq   $0x0,-0x18(%rbp)
je     11ad <getPathExt+0x9d>
cmpq   $0x0,-0x18(%rbp)
je     11ba <getPathExt+0xaa>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11ba <getPathExt+0xaa>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <getPathExt+0xb2>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPathExt>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
cmp    %r14,%rbx
mov    %r14,%rcx
cmova  %rbx,%rcx
test   %r14,%r14
cmove  %rbx,%rcx
test   %rax,%rax
je     1162 <getPathExt+0x52>
test   %rcx,%rcx
je     1164 <getPathExt+0x54>
cmp    %rax,%rcx
jb     1164 <getPathExt+0x54>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @getPathExt(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %4
%9 = load i8*, i8** %3
%10 = call i8* @strrchr(i8* %9, i8 signext 92)
store i8* %10, i8** %5
%11 = load i8*, i8** %3
%12 = call i8* @strrchr(i8* %11, i8 signext 46)
store i8* %12, i8** %6
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %1
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = load i8*, i8** %4
%21 = icmp ugt i8* %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18, %1
%23 = load i8*, i8** %5
store i8* %23, i8** %4
br label %24
24: ; preds = %22, %18, %15
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i8*, i8** %4
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i8*, i8** %4
%35 = load i8*, i8** %6
%36 = icmp ult i8* %34, %35
br i1 %36, label %37, label %39
37: ; preds = %33, %27
%38 = load i8*, i8** %6
store i8* %38, i8** %2
br label %40
39: ; preds = %33, %30, %24
store i8* null, i8** %2
br label %40
40: ; preds = %39, %37
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
define i8* @getPathExt(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%5 = icmp eq i8* %2, null
%6 = icmp ugt i8* %3, %2
%7 = select i1 %5, i1 true, i1 %6
%8 = select i1 %7, i8* %3, i8* %2
%9 = icmp eq i8* %4, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = icmp eq i8* %8, null
%12 = icmp ult i8* %8, %4
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %15, label %14
14: ; preds = %10, %1
br label %15
15: ; preds = %10, %14
%16 = phi i8* [ null, %14 ], [ %4, %10 ]
ret i8* %16
}