#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 sprintf(char *, char *, ...);
char *ints_idxs_to_string(char *buf, int *ints, size_t *idxs, size_t len) {
  size_t i;
  int x;
  x = sprintf(buf, "[");
  for (i = 0; i < len; ++i) {
    x += sprintf(buf + x, "%d, ", ints[idxs[i]]);
  }
  if (x > 2) {
    x -= 2;
  }
  sprintf(buf + x, "]");
  return buf;
}


x86 assembly (clang, -O0):
<ints_idxs_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xecd(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1196 <ints_idxs_to_string+0x86>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1145 <ints_idxs_to_string+0x35>
cmpl   $0x2,-0x2c(%rbp)
jle    11a9 <ints_idxs_to_string+0x99>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ints_idxs_to_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movw   $0x5b,(%rdi)
test   %rcx,%rcx
je     1175 <ints_idxs_to_string+0x65>
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    $0x1,%ebp
xor    %r13d,%r13d
nopl   0x0(%rax)
movslq %ebp,%rbp
lea    (%r14,%rbp,1),%rdi
mov    (%r15,%r13,8),%rax
mov    (%r12,%rax,4),%edx
lea    0xeaa(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    %eax,%ebp
add    $0x1,%r13
cmp    %r13,%rbx
jne    1140 <ints_idxs_to_string+0x30>
lea    -0x2(%rbp),%eax
cmp    $0x3,%ebp
cmovl  %ebp,%eax
cltq
jmp    117a <ints_idxs_to_string+0x6a>
mov    $0x1,%eax
movw   $0x5d,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%d, \00"
define i8* @ints_idxs_to_string(i8* returned writeonly %0, i32* nocapture %1, i64* nocapture %2, i64 %3) {
%5 = bitcast i8* %0 to i16*
store i16 91, i16* %5
%6 = icmp eq i64 %3, 0
br i1 %6, label %25, label %7
7: ; preds = %4, %7
%8 = phi i32 [ %17, %7 ], [ 1, %4 ]
%9 = phi i64 [ %18, %7 ], [ 0, %4 ]
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = getelementptr inbounds i64, i64* %2, i64 %9
%13 = load i64, i64* %12
%14 = getelementptr inbounds i32, i32* %1, i64 %13
%15 = load i32, i32* %14
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = add nsw i32 %16, %8
%18 = add nuw i64 %9, 1
%19 = icmp eq i64 %18, %3
br i1 %19, label %20, label %7
20: ; preds = %7
%21 = icmp sgt i32 %17, 2
%22 = add nsw i32 %17, -2
%23 = select i1 %21, i32 %22, i32 %17
%24 = sext i32 %23 to i64
br label %25
25: ; preds = %20, %4
%26 = phi i64 [ 1, %4 ], [ %24, %20 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = bitcast i8* %27 to i16*
store i16 93, i16* %28
ret i8* %0
}