#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 */
void *alloca(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
void print_ints(const int *A, int n) {
  void *t = alloca(n * 16 * sizeof(char));
  char *p = t;
  p += sprintf(p, "[");
  for (int i = 0; i < n; i++) {
    p += sprintf(p, "%i", A[i]);
    if (i < n - 1)
      p += sprintf(p, ",");
  }
  p += sprintf(p, "]\n");
  printf("%s", (char *)t);
}


x86 assembly (clang, -O0):
<print_ints>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1206 <print_ints+0xd6>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f3 <print_ints+0xc3>
mov    -0x20(%rbp),%rdi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11f8 <print_ints+0xc8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1187 <print_ints+0x57>
mov    -0x20(%rbp),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xdd7(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ints>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r12
mov    %esi,%edi
shl    $0x4,%edi
call   1040 <alloca@plt>
mov    %rax,%rbx
movw   $0x5b,(%rax)
mov    %rax,(%rsp)
add    $0x1,%rbx
test   %r15d,%r15d
jle    11b2 <print_ints+0x82>
lea    -0x1(%r15),%r13d
mov    %r15d,%ebp
lea    0xe92(%rip),%r15
xor    %r14d,%r14d
jmp    118c <print_ints+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
mov    %rax,%rbx
cmp    %r14,%rbp
je     11b5 <print_ints+0x85>
mov    (%r12,%r14,4),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <sprintf@plt>
cltq
add    %rbx,%rax
cmp    %r13,%r14
jae    1180 <print_ints+0x50>
movw   $0x2c,(%rax)
add    $0x1,%rax
jmp    1180 <print_ints+0x50>
mov    %rbx,%rax
movb   $0x0,0x2(%rax)
movw   $0xa5d,(%rax)
lea    0xe41(%rip),%rdi
mov    (%rsp),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%i\00"
@.str.3 = [3 x i8] c"]\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define void @print_ints(i32* nocapture %0, i32 %1) {
%3 = shl nsw i32 %1, 4
%4 = tail call i8* @alloca(i32 %3)
%5 = bitcast i8* %4 to i16*
store i16 91, i16* %5
%6 = getelementptr inbounds i8, i8* %4, i64 1
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = add nsw i32 %1, -1
%10 = zext i32 %9 to i64
%11 = zext i32 %1 to i64
br label %15
12: ; preds = %27, %2
%13 = phi i8* [ %6, %2 ], [ %28, %27 ]
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %13, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3, i1 false)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
ret void
15: ; preds = %8, %27
%16 = phi i64 [ 0, %8 ], [ %29, %27 ]
%17 = phi i8* [ %6, %8 ], [ %28, %27 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %16
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
%23 = icmp ult i64 %16, %10
br i1 %23, label %24, label %27
24: ; preds = %15
%25 = bitcast i8* %22 to i16*
store i16 44, i16* %25
%26 = getelementptr inbounds i8, i8* %22, i64 1
br label %27
27: ; preds = %15, %24
%28 = phi i8* [ %26, %24 ], [ %22, %15 ]
%29 = add nuw nsw i64 %16, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %12, label %15
}