#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ write_array_i32(int /*<<< orphan*/ *, unsigned int const *,
                                   int);
int /*<<< orphan*/ write_named_array_ui32(int /*<<< orphan*/ *, char *,
                                          unsigned int const *,
                                          unsigned int const);
void write_data_as_json(FILE *f, const unsigned int *a, const unsigned int *b,
                        const unsigned int *y, const unsigned int len) {
  int i;
  fprintf(f, "{");
  write_named_array_ui32(f, "a", a, len);
  fprintf(f, ",");
  write_named_array_ui32(f, "b", b, len);
  fprintf(f, ",");
  fprintf(f, "\"expected\":[");
  for (i = 0; i < len; i++) {
    fprintf(f, "[");
    write_array_i32(f, &y[i * 2], 2);
    fprintf(f, "]");
    if (i < len - 1) {
      fprintf(f, ",");
    }
  }
  fprintf(f, "]");
  fprintf(f, "}");
}


x86 assembly (clang, -O0):
<write_data_as_json>:
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    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe94(%rip),%rsi
call   1050 <write_named_array_ui32@plt>
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe71(%rip),%rsi
call   1050 <write_named_array_ui32@plt>
mov    -0x8(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1242 <write_data_as_json+0x112>
mov    -0x8(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1030 <write_array_i32@plt>
mov    -0x8(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    122f <write_data_as_json+0xff>
mov    -0x8(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1234 <write_data_as_json+0x104>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c1 <write_data_as_json+0x91>
mov    -0x8(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_data_as_json>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
mov    $0x7b,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
lea    0xe92(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
mov    %r15d,%ecx
call   1050 <write_named_array_ui32@plt>
mov    $0x2c,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
lea    0xe72(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
call   1050 <write_named_array_ui32@plt>
mov    $0x2c,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
lea    0xe52(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
test   %r15d,%r15d
je     122b <write_data_as_json+0xeb>
lea    -0x1(%r15),%r12d
mov    %r15d,%r15d
xor    %ebx,%ebx
jmp    11ed <write_data_as_json+0xad>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
add    $0x8,%rbp
cmp    %rbx,%r15
je     122b <write_data_as_json+0xeb>
mov    $0x5b,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1040 <write_array_i32@plt>
mov    $0x5d,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
cmp    %r12,%rbx
jae    11e0 <write_data_as_json+0xa0>
mov    $0x2c,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    11e0 <write_data_as_json+0xa0>
mov    $0x5d,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    $0x7d,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

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

LLVM IR (-O2):
@.str.1 = [2 x i8] c"a\00"
@.str.3 = [2 x i8] c"b\00"
@.str.4 = [13 x i8] c"\22expected\22:[\00"
define void @write_data_as_json(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4) {
%6 = tail call i32 @fputc(i32 123, i32* %0)
%7 = tail call i32 @write_named_array_ui32(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32 %4)
%8 = tail call i32 @fputc(i32 44, i32* %0)
%9 = tail call i32 @write_named_array_ui32(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32 %4)
%10 = tail call i32 @fputc(i32 44, i32* %0)
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 12, i64 1, i32* %0)
%12 = icmp eq i32 %4, 0
br i1 %12, label %30, label %13
13: ; preds = %5
%14 = add i32 %4, -1
%15 = zext i32 %14 to i64
%16 = zext i32 %4 to i64
br label %17
17: ; preds = %13, %27
%18 = phi i64 [ 0, %13 ], [ %28, %27 ]
%19 = tail call i32 @fputc(i32 91, i32* %0)
%20 = shl nuw nsw i64 %18, 1
%21 = getelementptr inbounds i32, i32* %3, i64 %20
%22 = tail call i32 @write_array_i32(i32* %0, i32* %21, i32 2)
%23 = tail call i32 @fputc(i32 93, i32* %0)
%24 = icmp ult i64 %18, %15
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = tail call i32 @fputc(i32 44, i32* %0)
br label %27
27: ; preds = %17, %25
%28 = add nuw nsw i64 %18, 1
%29 = icmp eq i64 %28, %16
br i1 %29, label %30, label %17
30: ; preds = %27, %5
%31 = tail call i32 @fputc(i32 93, i32* %0)
%32 = tail call i32 @fputc(i32 125, i32* %0)
ret void
}