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


x86 assembly (clang, -O0):
<newextlong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ec <newextlong+0xbc>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b9 <newextlong+0x89>
mov    -0x10(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1050 <strconc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strconc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    11d5 <newextlong+0xa5>
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    $0x40,%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*
%8 = alloca i8*
%9 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %42
12: ; preds = %2
store i8* null, i8** %5
%13 = load i8**, i8*** %3
%14 = load i8*, i8** %13
%15 = call i8* @strrchr(i8* %14, i8 signext 46)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %29, label %19
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = call i8* @strconc(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
store i8* %22, i8** %8
%23 = load i8**, i8*** %3
%24 = load i8*, i8** %23
%25 = load i8*, i8** %8
%26 = call i8* @strconc(i8* %24, i8* %25)
store i8* %26, i8** %5
%27 = load i8*, i8** %8
%28 = call i32 @free(i8* %27)
br label %36
29: ; preds = %12
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8 0, i8* %31
%32 = load i8**, i8*** %3
%33 = load i8*, i8** %32
%34 = load i8*, i8** %4
%35 = call i8* @strconc(i8* %33, i8* %34)
store i8* %35, i8** %5
br label %36
36: ; preds = %29, %19
%37 = load i8**, i8*** %3
%38 = load i8*, i8** %37
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %5
%41 = load i8**, i8*** %3
store i8* %40, i8** %41
br label %42
42: ; preds = %36, %2
%43 = load i8**, i8*** %3
%44 = load i8*, i8** %43
ret i8* %44
}

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
}