#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strrchr(char *, char);
char *generate_output_filename(char *original, char *suffix) {
  char *outfilename;
  size_t original_size;
  size_t name_end;
  char *file_extension_point;
  original_size = strlen(original);
  outfilename =
      (char *)malloc(sizeof(char) * (original_size + strlen(suffix) + 1));
  if (outfilename != NULL) {
    file_extension_point = strrchr(original, '.');
    if (file_extension_point != NULL) {
      name_end = (file_extension_point - original);
      strncpy(outfilename, original, name_end);
      strcpy(outfilename + name_end, suffix);
      strcat(outfilename, file_extension_point);
    }
  }
  return outfilename;
}


x86 assembly (clang, -O0):
<generate_output_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1216 <generate_output_filename+0xb6>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1211 <generate_output_filename+0xb1>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
jmp    1216 <generate_output_filename+0xb6>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_output_filename>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d4 <generate_output_filename+0x74>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     11d4 <generate_output_filename+0x74>
mov    %rax,%r12
mov    %rax,%r13
sub    %r15,%r13
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
add    %r13,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @generate_output_filename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = add i64 %11, %13
%15 = add i64 %14, 1
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %46
22: ; preds = %2
%23 = load i8*, i8** %3
%24 = call i8* @strrchr(i8* %23, i8 signext 46)
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %45
27: ; preds = %22
%28 = load i8*, i8** %8
%29 = load i8*, i8** %3
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
store i64 %32, i64* %7
%33 = load i8*, i8** %5
%34 = load i8*, i8** %3
%35 = load i64, i64* %7
%36 = call i32 @strncpy(i8* %33, i8* %34, i64 %35)
%37 = load i8*, i8** %5
%38 = load i64, i64* %7
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8*, i8** %4
%41 = call i32 @strcpy(i8* %39, i8* %40)
%42 = load i8*, i8** %5
%43 = load i8*, i8** %8
%44 = call i32 @strcat(i8* %42, i8* %43)
br label %45
45: ; preds = %27, %22
br label %46
46: ; preds = %45, %2
%47 = load i8*, i8** %5
ret i8* %47
}

LLVM IR (-O2):
define i8* @generate_output_filename(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %4, %3
%6 = trunc i64 %5 to i32
%7 = add i32 %6, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %22, label %11
11: ; preds = %2
%12 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = ptrtoint i8* %12 to i64
%16 = ptrtoint i8* %0 to i64
%17 = sub i64 %15, %16
%18 = tail call i32 @strncpy(i8* %9, i8* %0, i64 %17)
%19 = getelementptr inbounds i8, i8* %9, i64 %17
%20 = tail call i32 @strcpy(i8* %19, i8* %1)
%21 = tail call i32 @strcat(i8* %9, i8* %12)
br label %22
22: ; preds = %11, %14, %2
ret i8* %9
}