#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*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
void create_name_with_id(char *name, char *new_name, int id) {
  char extension[16];
  char str_id[16];
  char *dot_pos = 0;
  sprintf(str_id, "%d", id);
  strcpy(new_name, name);
  dot_pos = strrchr(new_name, '.');
  if (dot_pos) {
    strcpy(extension, dot_pos);
    *dot_pos = '\0';
    strcat(new_name, "_");
    strcat(new_name, str_id);
    strcat(new_name, extension);
  } else {
    strcat(new_name, "_");
    strcat(new_name, str_id);
  }
}


x86 assembly (clang, -O0):
<create_name_with_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe97(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     11db <create_name_with_id+0x9b>
lea    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <strcat@plt>
jmp    11f8 <create_name_with_id+0xb8>
mov    -0x10(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_name_with_id>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeaa(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11a8 <create_name_with_id+0x68>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
movb   $0x0,(%rbx)
lea    0xe68(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    %rsp,%rsi
jmp    11af <create_name_with_id+0x6f>
lea    0xe54(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"_\00"
define void @create_name_with_id(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [16 x i8]
%8 = alloca [16 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %9
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%11 = load i32, i32* %6
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8*, i8** %5
%17 = call i8* @strrchr(i8* %16, i8 signext 46)
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %33
20: ; preds = %3
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%22 = load i8*, i8** %9
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %9
store i8 0, i8* %24
%25 = load i8*, i8** %5
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = load i8*, i8** %5
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%29 = call i32 @strcat(i8* %27, i8* %28)
%30 = load i8*, i8** %5
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%32 = call i32 @strcat(i8* %30, i8* %31)
br label %39
33: ; preds = %3
%34 = load i8*, i8** %5
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = load i8*, i8** %5
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%38 = call i32 @strcat(i8* %36, i8* %37)
br label %39
39: ; preds = %33, %20
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"_\00"
define void @create_name_with_id(i8* %0, i8* %1, i32 %2) {
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
%9 = tail call i32 @strcpy(i8* %1, i8* %0)
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = call i32 @strcpy(i8* %6, i8* %10)
store i8 0, i8* %10
%14 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @strcat(i8* %1, i8* %7)
br label %18
16: ; preds = %3
%17 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = phi i8* [ %7, %16 ], [ %6, %12 ]
%20 = call i32 @strcat(i8* %1, i8* %19)
ret void
}