#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 const *, char);
const char *find_filename_extension(const char *fname) {
  const char *retval = strchr(fname, '.');
  const char *p = retval;
  while (p != NULL) {
    p = strchr(p + 1, '.');
    if (p != NULL)
      retval = p;
  }
  if (retval != NULL)
    retval++;
  return (retval);
}


x86 assembly (clang, -O0):
<find_filename_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116f <find_filename_extension+0x5f>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116a <find_filename_extension+0x5a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1136 <find_filename_extension+0x26>
cmpq   $0x0,-0x10(%rbp)
je     1186 <find_filename_extension+0x76>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_filename_extension>:
push   %rbx
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1138 <find_filename_extension+0x28>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1120 <find_filename_extension+0x10>
jmp    113a <find_filename_extension+0x2a>
xor    %ebx,%ebx
lea    0x1(%rbx),%rax
test   %rbx,%rbx
cmove  %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @find_filename_extension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 46)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
store i8* %7, i8** %4
br label %8
8: ; preds = %19, %1
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = call i8* @strchr(i8* %13, i8 signext 46)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i8*, i8** %4
store i8* %18, i8** %3
br label %19
19: ; preds = %17, %11
br label %8
20: ; preds = %8
%21 = load i8*, i8** %3
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
br label %26
26: ; preds = %23, %20
%27 = load i8*, i8** %3
ret i8* %27
}

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