#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*/ strcat(char *, char *);
char *strrchr(char *, char);
void strext(char *fn, char *ext) {
  char *p, *q;
  if ((p = strrchr(fn, '/')) == 0)
    p = fn;
  if ((q = strrchr(p, '.')) == 0)
    strcat(p, ".");
  else
    q[1] = '\0';
  strcat(p, ext);
}


x86 assembly (clang, -O0):
<strext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1154 <strext+0x34>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1185 <strext+0x65>
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1040 <strcat@plt>
jmp    118d <strext+0x6d>
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strext>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1157 <strext+0x37>
movb   $0x0,0x1(%rax)
jmp    1166 <strext+0x46>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strcat@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @strext(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* %0, i8* %3
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %12
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %6, i64 1
store i8 0, i8* %11
br label %12
12: ; preds = %10, %8
%13 = tail call i32 @strcat(i8* %5, i8* %1)
ret void
}