#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, char *);
char *strcat(char *, char *);
char *strcpy(char *, char *);
char *strncat(char *, char *, int);
char *json_valueList(char *buffer, int *timestamps, char **values,
                     int nbOfValues) {
  buffer = strcpy(buffer, "[");
  int i = 0;
  for (i = 0; i < nbOfValues; i++) {
    sprintf(buffer, "%s {\"timestamp\" : %ld000, \"value\" : \"%s\"}", buffer,
            timestamps[i], values[i]);
    if (i < nbOfValues - 1)
      buffer = strcat(buffer, ", ");
  }
  buffer = strncat(buffer, "]", 2);
  return buffer;
}


x86 assembly (clang, -O0):
<json_valueList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e8 <json_valueList+0xa8>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rsi
mov    (%rax,%rsi,8),%r8
lea    0xe57(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d5 <json_valueList+0x95>
mov    -0x8(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1050 <strcat@plt>
mov    %rax,-0x8(%rbp)
jmp    11da <json_valueList+0x9a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1179 <json_valueList+0x39>
mov    -0x8(%rbp),%rdi
lea    0xe3c(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<json_valueList>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
movw   $0x5b,(%rdi)
test   %ecx,%ecx
jle    119d <json_valueList+0x6d>
mov    %rdx,%r14
mov    %rsi,%r15
lea    -0x1(%rcx),%r13d
mov    %ecx,%ebp
xor    %r12d,%r12d
jmp    1169 <json_valueList+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%rbp
je     119d <json_valueList+0x6d>
mov    (%r15,%r12,4),%ecx
mov    (%r14,%r12,8),%r8
mov    %rbx,%rdi
lea    0xe85(%rip),%rsi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
cmp    %r13,%r12
jae    1160 <json_valueList+0x30>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movw   $0x202c,(%rbx,%rax,1)
movb   $0x0,0x2(%rbx,%rax,1)
jmp    1160 <json_valueList+0x30>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strncat@plt>

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

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