#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*/ printf(char *, char *, ...);
int /*<<< orphan*/ snprintf(char *, scalar_t__, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
scalar_t__ strlen(char *);
char *insert_suffix(char *name, char *suffix) {
  char *new_name, *name1;
  new_name = my_malloc(strlen(name) + strlen(suffix) + 1);
  char *p = name;
  p = p + strlen(name);
  while (p[0] != '.' && strlen(p) < strlen(name)) {
    p--;
  }
  printf("p_len = %d\nname_len = %d\n", strlen(p), strlen(name));
  printf("p = %s\n", p);
  if (strlen(p) == strlen(name)) {
    sprintf(new_name, "%s%s", name, suffix);
  } else {
    name1 = my_malloc(strlen(name) - strlen(p) + 1);
    snprintf(name1, strlen(name) - strlen(p) + 1, "%s", name);
    sprintf(new_name, "%s%s%s", name1, suffix, p);
    free(name1);
  }
  printf("new_name = %s\n", new_name);
  return new_name;
}


x86 assembly (clang, -O0):
<insert_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <my_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x39(%rbp)
je     11fc <insert_suffix+0x9c>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    120c <insert_suffix+0xac>
jmp    121d <insert_suffix+0xbd>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    11c1 <insert_suffix+0x61>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jne    129f <insert_suffix+0x13f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    132d <insert_suffix+0x1cd>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
sub    %rax,%rdi
add    $0x1,%rdi
call   1040 <my_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdi
sub    %rax,%rsi
add    $0x1,%rsi
mov    -0x8(%rbp),%rcx
lea    0xd25(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xd05(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rsi
lea    0xcf1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x70,%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,%r12
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>
mov    %rax,%r15
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%r13
lea    (%r12,%rax,1),%rbp
cmpb   $0x2e,(%r12,%rax,1)
jne    11b0 <insert_suffix+0x50>
mov    %rbp,%rbx
jmp    11ca <insert_suffix+0x6a>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    %r13,%rax
jge    11a7 <insert_suffix+0x47>
lea    -0x1(%rbp),%rbx
cmpb   $0x2e,-0x1(%rbp)
mov    %rbx,%rbp
jne    11b0 <insert_suffix+0x50>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe27(%rip),%rdi
mov    %rax,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1050 <strlen@plt>
sub    %rbp,%rax
jne    1228 <insert_suffix+0xc8>
lea    0xe0e(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    1288 <insert_suffix+0x128>
add    $0x1,%rax
mov    %rax,%rdi
call   1040 <my_malloc@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbp
add    $0x1,%rbp
lea    0xdce(%rip),%rdx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12,%rcx
call   1070 <snprintf@plt>
lea    0xdb5(%rip),%rsi
mov    %r15,%rdi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
lea    0xd9a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"p_len = %d\0Aname_len = %d\0A\00"
@.str.1 = [8 x i8] c"p = %s\0A\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [7 x i8] c"%s%s%s\00"
@.str.5 = [15 x i8] c"new_name = %s\0A\00"
define i8* @insert_suffix(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** %3
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %9, %11
%13 = add nsw i64 %12, 1
%14 = call i8* @my_malloc(i64 %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %3
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8* %19, i8** %7
br label %20
20: ; preds = %34, %2
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 46
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i8*, i8** %7
%28 = call i64 @strlen(i8* %27)
%29 = load i8*, i8** %3
%30 = call i64 @strlen(i8* %29)
%31 = icmp slt i64 %28, %30
br label %32
32: ; preds = %26, %20
%33 = phi i1 [ false, %20 ], [ %31, %26 ]
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 -1
store i8* %36, i8** %7
br label %20
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = call i64 @strlen(i8* %38)
%40 = inttoptr i64 %39 to i8*
%41 = load i8*, i8** %3
%42 = call i64 @strlen(i8* %41)
%43 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %40, i64 %42)
%44 = load i8*, i8** %7
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %7
%47 = call i64 @strlen(i8* %46)
%48 = load i8*, i8** %3
%49 = call i64 @strlen(i8* %48)
%50 = icmp eq i64 %47, %49
br i1 %50, label %51, label %56
51: ; preds = %37
%52 = load i8*, i8** %5
%53 = load i8*, i8** %3
%54 = load i8*, i8** %4
%55 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %53, i8* %54)
br label %80
56: ; preds = %37
%57 = load i8*, i8** %3
%58 = call i64 @strlen(i8* %57)
%59 = load i8*, i8** %7
%60 = call i64 @strlen(i8* %59)
%61 = sub nsw i64 %58, %60
%62 = add nsw i64 %61, 1
%63 = call i8* @my_malloc(i64 %62)
store i8* %63, i8** %6
%64 = load i8*, i8** %6
%65 = load i8*, i8** %3
%66 = call i64 @strlen(i8* %65)
%67 = load i8*, i8** %7
%68 = call i64 @strlen(i8* %67)
%69 = sub nsw i64 %66, %68
%70 = add nsw i64 %69, 1
%71 = load i8*, i8** %3
%72 = call i32 @snprintf(i8* %64, i64 %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %71)
%73 = load i8*, i8** %5
%74 = load i8*, i8** %6
%75 = load i8*, i8** %4
%76 = load i8*, i8** %7
%77 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %74, i8* %75, i8* %76)
%78 = load i8*, i8** %6
%79 = call i32 @free(i8* %78)
br label %80
80: ; preds = %56, %51
%81 = load i8*, i8** %5
%82 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %81)
%83 = load i8*, i8** %5
ret i8* %83
}

LLVM IR (-O2):
@.str = [26 x i8] c"p_len = %d\0Aname_len = %d\0A\00"
@.str.1 = [8 x i8] c"p = %s\0A\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [7 x i8] c"%s%s%s\00"
@.str.5 = [15 x i8] c"new_name = %s\0A\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 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
br i1 %11, label %20, label %12
12: ; preds = %2, %16
%13 = phi i8* [ %17, %16 ], [ %9, %2 ]
%14 = tail call i64 @strlen(i8* %13)
%15 = icmp slt i64 %14, %8
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %13, i64 -1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 46
br i1 %19, label %20, label %12
20: ; preds = %12, %16, %2
%21 = phi i8* [ %9, %2 ], [ %17, %16 ], [ %13, %12 ]
%22 = tail call i64 @strlen(i8* %21)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %23, i64 %8)
%25 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%26 = tail call i64 @strlen(i8* %21)
%27 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%28 = icmp eq i64 %27, %26
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %42
31: ; preds = %20
%32 = sub i64 1, %26
%33 = add i64 %32, %27
%34 = tail call i8* @my_malloc(i64 %33)
%35 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%36 = tail call i64 @strlen(i8* %21)
%37 = add i64 %35, 1
%38 = sub i64 %37, %36
%39 = tail call i32 @snprintf(i8* %34, i64 %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%40 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %34, i8* %1, i8* %21)
%41 = tail call i32 @free(i8* %34)
br label %42
42: ; preds = %31, %29
%43 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %7)
ret i8* %7
}