#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char *generatefilename(char *sourcefilename) {
  char *result = NULL;
  char *exten;
  int len = strlen(sourcefilename);
  result = (char *)malloc(len + 4 + 1);
  memset(result, 0, len + 4 + 1);
  exten = strrchr(sourcefilename, '.');
  strncpy(result, sourcefilename, exten - sourcefilename);
  strcat(result, ".new");
  strcat(result, exten);
  return result;
}


x86 assembly (clang, -O0):
<generatefilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x4,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    $0x4,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generatefilename>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x5(%rax),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbp
mov    %ebp,%edx
sub    %r14d,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".new\00"
define i8* @generatefilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = add nsw i32 %8, 4
%10 = add nsw i32 %9, 1
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 4
%16 = add nsw i32 %15, 1
%17 = call i32 @memset(i8* %13, i32 0, i32 %16)
%18 = load i8*, i8** %2
%19 = call i8* @strrchr(i8* %18, i8 signext 46)
store i8* %19, i8** %4
%20 = load i8*, i8** %3
%21 = load i8*, i8** %2
%22 = load i8*, i8** %4
%23 = load i8*, i8** %2
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
%28 = call i32 @strncpy(i8* %20, i8* %21, i32 %27)
%29 = load i8*, i8** %3
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %3
%32 = load i8*, i8** %4
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [5 x i8] c".new\00"
define i8* @generatefilename(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 5
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @memset(i8* %5, i32 0, i32 %3)
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%8 = ptrtoint i8* %7 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = tail call i32 @strncpy(i8* %5, i8* %0, i32 %11)
%13 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @strcat(i8* %5, i8* %7)
ret i8* %5
}