#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 */
char *malloc(size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *, char const *,
                            int);
int strlen(char const *);
char *cg_name_indexed(const char *root, const char *name, int index) {
  size_t len = strlen(root) + strlen(name) + 10;
  char *ret = malloc(len);
  snprintf(ret, len, "%s/%s_%d", root, name, index);
  return ret;
}


x86 assembly (clang, -O0):
<cg_name_indexed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0xa,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
lea    0xe70(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_name_indexed>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
add    $0xa,%eax
movslq %eax,%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbp
lea    0xe96(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
mov    %r15,%r8
mov    %r14d,%r9d
call   1040 <snprintf@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s/%s_%d\00"
define i8* @cg_name_indexed(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = add nsw i32 %13, 10
%15 = sext i32 %14 to i64
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = load i64, i64* %7
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = call i32 @snprintf(i8* %18, i64 %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21, i32 %22)
%24 = load i8*, i8** %8
ret i8* %24
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s/%s_%d\00"
define i8* @cg_name_indexed(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 10
%7 = add i32 %6, %5
%8 = sext i32 %7 to i64
%9 = tail call i8* @malloc(i64 %8)
%10 = tail call i32 @snprintf(i8* %9, i64 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %2)
ret i8* %9
}