#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*/ free(char *);
char *strconc(char *, char const *);
char *strrchr(char *, char);
char *newextlong(char **filename, const char *extension) {
  if (extension) {
    char *result = 0;
    char *finalperiod = strrchr(*filename, '.');
    if (!finalperiod) {
      char *periodized = strconc(".", extension);
      result = strconc(*filename, periodized);
      free(periodized);
    } else {
      finalperiod[1] = '\0';
      result = strconc(*filename, extension);
    }
    free(*filename);
    *filename = result;
  }
  return *filename;
}


x86 assembly (clang, -O0):
<newextlong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11dc <newextlong+0xac>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <newextlong+0x79>
mov    -0x10(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1050 <strconc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strconc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    11c5 <newextlong+0x95>
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strconc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newextlong>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%rbx
test   %rsi,%rsi
je     119c <newextlong+0x6c>
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1169 <newextlong+0x39>
movb   $0x0,0x1(%rax)
mov    (%r14),%rdi
mov    %r15,%rsi
call   1050 <strconc@plt>
mov    %rax,%rbx
jmp    1191 <newextlong+0x61>
lea    0xe90(%rip),%rdi
mov    %r15,%rsi
call   1050 <strconc@plt>
mov    %rax,%r15
mov    (%r14),%rdi
mov    %rax,%rsi
call   1050 <strconc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    %rbx,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @newextlong(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %38
10: ; preds = %2
store i8* null, i8** %5
%11 = load i8**, i8*** %3
%12 = load i8*, i8** %11
%13 = call i8* @strrchr(i8* %12, i8 signext 46)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %25, label %16
16: ; preds = %10
%17 = load i8*, i8** %4
%18 = call i8* @strconc(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %17)
store i8* %18, i8** %7
%19 = load i8**, i8*** %3
%20 = load i8*, i8** %19
%21 = load i8*, i8** %7
%22 = call i8* @strconc(i8* %20, i8* %21)
store i8* %22, i8** %5
%23 = load i8*, i8** %7
%24 = call i32 @free(i8* %23)
br label %32
25: ; preds = %10
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8 0, i8* %27
%28 = load i8**, i8*** %3
%29 = load i8*, i8** %28
%30 = load i8*, i8** %4
%31 = call i8* @strconc(i8* %29, i8* %30)
store i8* %31, i8** %5
br label %32
32: ; preds = %25, %16
%33 = load i8**, i8*** %3
%34 = load i8*, i8** %33
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %5
%37 = load i8**, i8*** %3
store i8* %36, i8** %37
br label %38
38: ; preds = %32, %2
%39 = load i8**, i8*** %3
%40 = load i8*, i8** %39
ret i8* %40
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @newextlong(i8** nocapture %0, i8* %1) {
%3 = icmp eq i8* %1, null
%4 = load i8*, i8** %0
br i1 %3, label %21, label %5
5: ; preds = %2
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %4, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = tail call i8* @strconc(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1)
%10 = load i8*, i8** %0
%11 = tail call i8* @strconc(i8* %10, i8* %9)
%12 = tail call i32 @free(i8* %9)
br label %17
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %6, i64 1
store i8 0, i8* %14
%15 = load i8*, i8** %0
%16 = tail call i8* @strconc(i8* %15, i8* %1)
br label %17
17: ; preds = %13, %8
%18 = phi i8* [ %16, %13 ], [ %11, %8 ]
%19 = load i8*, i8** %0
%20 = tail call i32 @free(i8* %19)
store i8* %18, i8** %0
br label %21
21: ; preds = %2, %17
%22 = phi i8* [ %18, %17 ], [ %4, %2 ]
ret i8* %22
}