#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 */
size_t strlen(char const *);
extern char *ftg_get_filename_ext(const char *path) {
  size_t len = strlen(path);
  const char *end = &path[len];
  while (len > 0) {
    char c;
    len--;
    c = path[len];
    if (c == '/')
      break;
    if (c == '.')
      return (char *)&path[len + 1];
  }
  return (char *)end;
}


x86 assembly (clang, -O0):
<ftg_get_filename_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1196 <ftg_get_filename_ext+0x86>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x2f,%eax
jne    116c <ftg_get_filename_ext+0x5c>
jmp    1196 <ftg_get_filename_ext+0x86>
movsbl -0x21(%rbp),%eax
cmp    $0x2e,%eax
jne    1191 <ftg_get_filename_ext+0x81>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    119e <ftg_get_filename_ext+0x8e>
jmp    1135 <ftg_get_filename_ext+0x25>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftg_get_filename_ext>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
cmp    $0x1,%rcx
je     113b <ftg_get_filename_ext+0x2b>
movzbl -0x2(%rbx,%rcx,1),%edx
cmp    $0x2f,%dl
je     113b <ftg_get_filename_ext+0x2b>
add    $0xffffffffffffffff,%rcx
cmp    $0x2e,%dl
jne    1120 <ftg_get_filename_ext+0x10>
jmp    113e <ftg_get_filename_ext+0x2e>
mov    %rax,%rcx
add    %rcx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @ftg_get_filename_ext(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %4
%9 = load i8*, i8** %3
%10 = load i64, i64* %4
%11 = getelementptr inbounds i8, i8* %9, i64 %10
store i8* %11, i8** %5
br label %12
12: ; preds = %35, %1
%13 = load i64, i64* %4
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = load i64, i64* %4
%17 = add i64 %16, -1
store i64 %17, i64* %4
%18 = load i8*, i8** %3
%19 = load i64, i64* %4
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %6
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 47
br i1 %24, label %25, label %26
25: ; preds = %15
br label %36
26: ; preds = %15
%27 = load i8, i8* %6
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 46
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i8*, i8** %3
%32 = load i64, i64* %4
%33 = add i64 %32, 1
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8* %34, i8** %2
br label %38
35: ; preds = %26
br label %12
36: ; preds = %25, %12
%37 = load i8*, i8** %5
store i8* %37, i8** %2
br label %38
38: ; preds = %36, %30
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
define i8* @ftg_get_filename_ext(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %3
3: ; preds = %6, %1
%4 = phi i64 [ %2, %1 ], [ %7, %6 ]
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = add i64 %4, -1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %3 [
i8 47, label %11
i8 46, label %10
]
10: ; preds = %6
br label %11
11: ; preds = %6, %3, %10
%12 = phi i64 [ %4, %10 ], [ %2, %3 ], [ %2, %6 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
ret i8* %13
}