#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 *, char);
int strlen(char *);
void get_array_string(int *list, int n, char *s) {
  int i = 0;
  s[0] = '\0';
  for (i = 0; i < n; i++)
    sprintf(s + strlen(s), "%d    ", *(list + i));
  sprintf(s + strlen(s), "%c", '\n');
}


x86 assembly (clang, -O0):
<get_array_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1196 <get_array_string+0x76>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
lea    0xe80(%rip),%rsi
movsbl %al,%edx
call   1040 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <get_array_string+0x28>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe50(%rip),%rsi
mov    $0xa,%edx
call   1040 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_array_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r13
movb   $0x0,(%rdx)
test   %esi,%esi
jle    1174 <get_array_string+0x54>
mov    %rdi,%r14
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0xebe(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %r13,%rdi
movsbl (%r14,%rbx,4),%edx
mov    %r15,%rsi
call   1040 <sprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <get_array_string+0x30>
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
movw   $0xa,0x0(%r13,%rax,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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