#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
char *c45_node_ints_to_string(int *values, int n) {
  if (n <= 0) {
    return "";
  }
  char *num_buffer = (char *)malloc(12);
  char *str_buffer = (char *)malloc((12 + 2) * n);
  str_buffer[0] = '\0';
  int i;
  for (i = 0; i < n; i++) {
    sprintf(num_buffer, (i == 0 ? "%d" : ", %d"), values[i]);
    strcat(str_buffer, num_buffer);
  }
  free(num_buffer);
  return str_buffer;
}


x86 assembly (clang, -O0):
<c45_node_ints_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1169 <c45_node_ints_to_string+0x29>
lea    0xea4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f6 <c45_node_ints_to_string+0xb6>
mov    $0xc,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
imul   $0xe,-0x14(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e5 <c45_node_ints_to_string+0xa5>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
lea    0xe54(%rip),%rsi
lea    0xe4f(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1192 <c45_node_ints_to_string+0x52>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c45_node_ints_to_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11cb <c45_node_ints_to_string+0x8b>
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0xc,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
shl    $0x4,%edi
sub    %ebp,%edi
sub    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %ebp,%r12d
xor    %ebp,%ebp
lea    0xe7f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %rbp,%rbp
mov    %r13,%rsi
lea    0xe65(%rip),%rax
cmove  %rax,%rsi
mov    (%r14,%rbp,4),%edx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1190 <c45_node_ints_to_string+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11d2 <c45_node_ints_to_string+0x92>
lea    0xe32(%rip),%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c", %d\00"
define i8* @c45_node_ints_to_string(i32* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %47
12: ; preds = %2
%13 = call i64 @malloc(i32 12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = load i32, i32* %5
%16 = mul nsw i32 14, %15
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 0, i8* %20
store i32 0, i32* %8
br label %21
21: ; preds = %40, %12
%22 = load i32, i32* %8
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%31 = load i32*, i32** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @sprintf(i8* %26, i8* %30, i32 %35)
%37 = load i8*, i8** %7
%38 = load i8*, i8** %6
%39 = call i32 @strcat(i8* %37, i8* %38)
br label %40
40: ; preds = %25
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %21
43: ; preds = %21
%44 = load i8*, i8** %6
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %7
store i8* %46, i8** %3
br label %47
47: ; preds = %43, %11
%48 = load i8*, i8** %3
ret i8* %48
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c", %d\00"
define i8* @c45_node_ints_to_string(i32* nocapture %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = tail call i64 @malloc(i32 12)
%6 = inttoptr i64 %5 to i8*
%7 = mul nsw i32 %1, 14
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
store i8 0, i8* %9
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %4, %11
%12 = phi i64 [ 0, %4 ], [ %19, %11 ]
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%15 = getelementptr inbounds i32, i32* %0, i64 %12
%16 = load i32, i32* %15
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) %14, i32 %16)
%18 = tail call i32 @strcat(i8* %9, i8* %6)
%19 = add nuw nsw i64 %12, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %21, label %11
21: ; preds = %11
%22 = tail call i32 @free(i8* %6)
br label %23
23: ; preds = %2, %21
%24 = phi i8* [ %9, %21 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
ret i8* %24
}