#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 *my_malloc(scalar_t__);
int /*<<< orphan*/ snprintf(char *, scalar_t__, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
char *insert_suffix(char *name, char *suffix) {
  char *new_name, *name1;
  new_name = my_malloc(strlen(name) + strlen(suffix) + 1);
  if (new_name == NULL)
    return NULL;
  char *p;
  p = strrchr(name, '.');
  if (p == NULL) {
    sprintf(new_name, "%s%s", name, suffix);
  } else {
    name1 = my_malloc(strlen(name) - strlen(p) + 1);
    if (name1 == NULL)
      return NULL;
    snprintf(name1, strlen(name) - strlen(p) + 1, "%s", name);
    sprintf(new_name, "%s%s%s", name1, suffix, p);
    free(name1);
  }
  return new_name;
}


x86 assembly (clang, -O0):
<insert_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <my_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b2 <insert_suffix+0x52>
movq   $0x0,-0x8(%rbp)
jmp    129c <insert_suffix+0x13c>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ee <insert_suffix+0x8e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    1294 <insert_suffix+0x134>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
sub    %rax,%rdi
add    $0x1,%rdi
call   1040 <my_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1230 <insert_suffix+0xd0>
movq   $0x0,-0x8(%rbp)
jmp    129c <insert_suffix+0x13c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdi
sub    %rax,%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rcx
lea    0xd9c(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_suffix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1040 <my_malloc@plt>
test   %rax,%rax
je     1230 <insert_suffix+0xd0>
mov    %rax,%r15
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     1235 <insert_suffix+0xd5>
mov    %rax,%r12
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <my_malloc@plt>
test   %rax,%rax
je     1230 <insert_suffix+0xd0>
mov    %rax,%r13
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbx
add    $0x1,%rbx
lea    0xe06(%rip),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rcx
call   1060 <snprintf@plt>
lea    0xded(%rip),%rsi
mov    %r15,%rdi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    124c <insert_suffix+0xec>
xor    %r15d,%r15d
jmp    124c <insert_suffix+0xec>
lea    0xdc6(%rip),%rsi
mov    %r15,%rdi
mov    %rbp,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"%s%s%s\00"
define i8* @insert_suffix(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %10, %12
%14 = add nsw i64 %13, 1
%15 = call i8* @my_malloc(i64 %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %2
store i8* null, i8** %3
br label %59
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i8* @strrchr(i8* %20, i8 signext 46)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %27)
br label %57
29: ; preds = %19
%30 = load i8*, i8** %4
%31 = call i64 @strlen(i8* %30)
%32 = load i8*, i8** %8
%33 = call i64 @strlen(i8* %32)
%34 = sub nsw i64 %31, %33
%35 = add nsw i64 %34, 1
%36 = call i8* @my_malloc(i64 %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %40
39: ; preds = %29
store i8* null, i8** %3
br label %59
40: ; preds = %29
%41 = load i8*, i8** %7
%42 = load i8*, i8** %4
%43 = call i64 @strlen(i8* %42)
%44 = load i8*, i8** %8
%45 = call i64 @strlen(i8* %44)
%46 = sub nsw i64 %43, %45
%47 = add nsw i64 %46, 1
%48 = load i8*, i8** %4
%49 = call i32 @snprintf(i8* %41, i64 %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = load i8*, i8** %6
%51 = load i8*, i8** %7
%52 = load i8*, i8** %5
%53 = load i8*, i8** %8
%54 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %51, i8* %52, i8* %53)
%55 = load i8*, i8** %7
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %40, %24
%58 = load i8*, i8** %6
store i8* %58, i8** %3
br label %59
59: ; preds = %57, %39, %18
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"%s%s%s\00"
define i8* @insert_suffix(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 %3, 1
%6 = add i64 %5, %4
%7 = tail call i8* @my_malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %29, label %9
9: ; preds = %2
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %29
14: ; preds = %9
%15 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%16 = tail call i64 @strlen(i8* %10)
%17 = add i64 %15, 1
%18 = sub i64 %17, %16
%19 = tail call i8* @my_malloc(i64 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %29, label %21
21: ; preds = %14
%22 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%23 = tail call i64 @strlen(i8* %10)
%24 = add i64 %22, 1
%25 = sub i64 %24, %23
%26 = tail call i32 @snprintf(i8* %19, i64 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%27 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %1, i8* %10)
%28 = tail call i32 @free(i8* %19)
br label %29
29: ; preds = %14, %21, %12, %2
%30 = phi i8* [ null, %2 ], [ null, %14 ], [ %7, %21 ], [ %7, %12 ]
ret i8* %30
}