#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 /*<<< orphan*/ add_to_string(char *, char *);
int /*<<< orphan*/ initialize_string(char *);
char *strrchr(char *, char);
void extension(char *variable, char *filename) {
  initialize_string(variable);
  char *dot = strrchr(filename, '.');
  if (!dot || dot == filename) {
    add_to_string(variable, "");
  } else {
    add_to_string(variable, dot + 1);
  }
}


x86 assembly (clang, -O0):
<extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <initialize_string@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1174 <extension+0x44>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1189 <extension+0x59>
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1040 <add_to_string@plt>
jmp    119a <extension+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1040 <add_to_string@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extension>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1050 <initialize_string@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1162 <extension+0x32>
cmp    %rbx,%rax
je     1162 <extension+0x32>
add    $0x1,%rax
mov    %r14,%rdi
mov    %rax,%rsi
jmp    116c <extension+0x3c>
lea    0xe97(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <add_to_string@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @extension(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @initialize_string(i8* %6)
%8 = load i8*, i8** %4
%9 = call i8* @strrchr(i8* %8, i8 signext 46)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12, %2
%17 = load i8*, i8** %3
%18 = call i32 @add_to_string(i8* %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %24
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i32 @add_to_string(i8* %20, i8* %22)
br label %24
24: ; preds = %19, %16
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @extension(i8* %0, i8* %1) {
%3 = tail call i32 @initialize_string(i8* %0)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%5 = icmp eq i8* %4, null
%6 = icmp eq i8* %4, %1
%7 = or i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @add_to_string(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %13
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %4, i64 1
%12 = tail call i32 @add_to_string(i8* %0, i8* %11)
br label %13
13: ; preds = %10, %8
ret void
}