#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 *);
char *strrchr(char const *, char);
const char *arg_extension(const char *basename) {
  const char *result = (basename ? strrchr(basename, '.') : NULL);
  if (basename && !result)
    result = basename + strlen(basename);
  if (basename && result == basename)
    result = basename + strlen(basename);
  if (basename && result && result[1] == '\0')
    result = basename + strlen(basename);
  return result;
}


x86 assembly (clang, -O0):
<arg_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     114e <arg_extension+0x2e>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
jmp    1159 <arg_extension+0x39>
xor    %eax,%eax
mov    %rax,-0x18(%rbp)
jmp    1159 <arg_extension+0x39>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1198 <arg_extension+0x78>
cmpq   $0x0,-0x10(%rbp)
jne    1198 <arg_extension+0x78>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d2 <arg_extension+0xb2>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11d2 <arg_extension+0xb2>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     121a <arg_extension+0xfa>
cmpq   $0x0,-0x10(%rbp)
je     121a <arg_extension+0xfa>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    121a <arg_extension+0xfa>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_extension>:
push   %rbx
test   %rdi,%rdi
je     116e <arg_extension+0x4e>
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     114a <arg_extension+0x2a>
cmp    %rbx,%rax
je     115c <arg_extension+0x3c>
test   %rax,%rax
je     116e <arg_extension+0x4e>
cmpb   $0x0,0x1(%rax)
je     1172 <arg_extension+0x52>
pop    %rbx
ret
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
cmp    %rbx,%rax
jne    113d <arg_extension+0x1d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
test   %rax,%rax
jne    1142 <arg_extension+0x22>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @arg_extension(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %28, label %3
3: ; preds = %1
%4 = tail call i8* @strrchr(i8* %0, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
br label %10
10: ; preds = %6, %3
%11 = phi i8* [ %4, %3 ], [ %9, %6 ]
%12 = icmp eq i8* %11, %0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
br label %17
17: ; preds = %13, %10
%18 = phi i8* [ %16, %13 ], [ %11, %10 ]
%19 = icmp eq i8* %18, null
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = tail call i32 @strlen(i8* %0)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
br label %28
28: ; preds = %1, %24, %20, %17
%29 = phi i8* [ %27, %24 ], [ %18, %20 ], [ null, %17 ], [ null, %1 ]
ret i8* %29
}