#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 *basename2(char const *);
char *strchr(char const *, int /*<<< orphan*/);
char *strrchr(char const *, char);
const char *get_suffix(const char *filename) {
  const char *p, *s;
  if (!(p = basename2(filename)))
    p = filename;
  if (!(s = strrchr(p, '.')))
    s = strchr(p, 0);
  if (s == p)
    s = strchr(p, 0);
  return s;
}


x86 assembly (clang, -O0):
<get_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <basename2@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    115b <get_suffix+0x2b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1186 <get_suffix+0x56>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11a3 <get_suffix+0x73>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_suffix>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <basename2@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %r14,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1165 <get_suffix+0x35>
cmp    %rbx,%rax
je     1175 <get_suffix+0x45>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %rbx,%rax
cmp    %rbx,%rax
jne    115d <get_suffix+0x2d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %rbx,%rax
jmp    115d <get_suffix+0x2d>

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

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