// File: /workspace/github_c_makefile_star2_O2/xapi-project[P]rrd-client-lib/parson/parson.c
// Function: json_serialize_to_buffer_r
static int json_serialize_to_buffer_r(const JSON_Value *value, char *buf, int level, int is_pretty, char *num_buf)
{
    const char *key = NULL, *string = NULL;
    JSON_Value *temp_value = NULL;
    JSON_Array *array = NULL;
    JSON_Object *object = NULL;
    size_t i = 0, count = 0;
    double num = 0.0;
    int written = -1, written_total = 0;

    switch (json_value_get_type(value)) {
        case JSONArray:
            array = json_value_get_array(value);
            count = json_array_get_count(array);
            APPEND_STRING("[");
            if (count > 0 && is_pretty) {
                APPEND_STRING("\n");
            }
            for (i = 0; i < count; i++) {
                if (is_pretty) {
                    APPEND_INDENT(level+1);
                }
                temp_value = json_array_get_value(array, i);
                written = json_serialize_to_buffer_r(temp_value, buf, level+1, is_pretty, num_buf);
                if (written < 0) {
                    return -1;
                }
                if (buf != NULL) {
                    buf += written;
                }
                written_total += written;
                if (i < (count - 1)) {
                    APPEND_STRING(",");
                }
                if (is_pretty) {
                    APPEND_STRING("\n");
                }
            }
            if (count > 0 && is_pretty) {
                APPEND_INDENT(level);
            }
            APPEND_STRING("]");
            return written_total;
        case JSONObject:
            object = json_value_get_object(value);
            count  = json_object_get_count(object);
            APPEND_STRING("{");
            if (count > 0 && is_pretty) {
                APPEND_STRING("\n");
            }
            for (i = 0; i < count; i++) {
                key = json_object_get_name(object, i);
                if (key == NULL) {
                    return -1;
                }
                if (is_pretty) {
                    APPEND_INDENT(level+1);
                }
                written = json_serialize_string(key, buf);
                if (written < 0) {
                    return -1;
                }
                if (buf != NULL) {
                    buf += written;
                }
                written_total += written;
                APPEND_STRING(":");
                if (is_pretty) {
                    APPEND_STRING(" ");
                }
                temp_value = json_object_get_value(object, key);
                written = json_serialize_to_buffer_r(temp_value, buf, level+1, is_pretty, num_buf);
                if (written < 0) {
                    return -1;
                }
                if (buf != NULL) {
                    buf += written;
                }
                written_total += written;
                if (i < (count - 1)) {
                    APPEND_STRING(",");
                }
                if (is_pretty) {
                    APPEND_STRING("\n");
                }
            }
            if (count > 0 && is_pretty) {
                APPEND_INDENT(level);
            }
            APPEND_STRING("}");
            return written_total;
        case JSONString:
            string = json_value_get_string(value);
            if (string == NULL) {
                return -1;
            }
            written = json_serialize_string(string, buf);
            if (written < 0) {
                return -1;
            }
            if (buf != NULL) {
                buf += written;
            }
            written_total += written;
            return written_total;
        case JSONBoolean:
            if (json_value_get_boolean(value)) {
                APPEND_STRING("true");
            } else {
                APPEND_STRING("false");
            }
            return written_total;
        case JSONNumber:
            num = json_value_get_number(value);
            if (buf != NULL) {
                num_buf = buf;
            }
            if (num == ((double)(int)num)) { /*  check if num is integer */
                written = sprintf(num_buf, "%d", (int)num);
	    } else if (num == ((double)(unsigned int)num)) {
                written = sprintf(num_buf, "%u", (unsigned int)num);
            } else {
                written = sprintf(num_buf, DOUBLE_SERIALIZATION_FORMAT, num);
            }
            if (written < 0) {
                return -1;
            }
            if (buf != NULL) {
                buf += written;
            }
            written_total += written;
            return written_total;
        case JSONNull:
            APPEND_STRING("null");
            return written_total;
        case JSONError:
            return -1;
        default:
            return -1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, 0xc(%rsp)
pushq $-0x1
popq %r13
testq %rdi, %rdi
je 0x3676
movl 0x8(%rdi), %eax
decl %eax
cmpl $0x5, %eax
ja 0x3676
movq %r8, %r12
movl %edx, %ebp
movq %rsi, %r14
leaq 0x2233(%rip), %rcx      # 0x5360
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2376(%rip), %rsi      # 0x54b3
jmp 0x35bc
movq 0x10(%rdi), %rbx
testq %rbx, %rbx
movq %r12, 0x40(%rsp)
je 0x31ed
movq 0x10(%rbx), %rax
movq %rax, 0x18(%rsp)
jmp 0x31f6
movsd 0x10(%rdi), %xmm0
testq %r14, %r14
cmovneq %r14, %r12
cvttpd2dq %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x3354
jp 0x3354
cvttsd2si %xmm0, %edx
leaq 0x2333(%rip), %rsi      # 0x54c4
movq %r12, %rdi
jmp 0x337a
movq 0x10(%rdi), %r15
testq %r15, %r15
je 0x3390
movq 0x18(%r15), %rax
movq %rax, 0x20(%rsp)
jmp 0x3399
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0x3676
movq %r14, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4a25
cmpl $0x0, 0x10(%rdi)
je 0x35b5
leaq 0x20e4(%rip), %rsi      # 0x52cc
jmp 0x35bc
movq $0x0, 0x18(%rsp)
leaq 0x22bb(%rip), %rsi      # 0x54b8
movq %r14, %rdi
callq 0x49b7
testl %eax, %eax
js 0x3676
movl %eax, %r12d
movl %eax, %r15d
addq %r14, %r15
testq %r14, %r14
cmoveq %r14, %r15
cmpq $0x0, 0x18(%rsp)
setne %al
cmpl $0x0, 0xc(%rsp)
setne %cl
andb %al, %cl
movb %cl, 0x14(%rsp)
cmpb $0x1, %cl
jne 0x325f
leaq 0x1eaf(%rip), %rsi      # 0x50ef
movq %r15, %rdi
callq 0x49b7
testl %eax, %eax
js 0x3676
movl %eax, %ecx
addq %r15, %rcx
testq %r15, %r15
cmovneq %rcx, %r15
addl %eax, %r12d
leal 0x1(%rbp), %eax
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rax
decq %rax
movq %rax, 0x28(%rsp)
xorl %r13d, %r13d
cmpq %r13, 0x18(%rsp)
je 0x35d1
cmpl $0x0, 0xc(%rsp)
je 0x32ab
movq %r15, %rdi
movl 0x20(%rsp), %esi
callq 0x49d4
testl %eax, %eax
js 0x3672
movl %eax, %ecx
addq %r15, %rcx
testq %r15, %r15
cmovneq %rcx, %r15
addl %eax, %r12d
testq %rbx, %rbx
je 0x32c0
cmpq %r13, 0x10(%rbx)
jbe 0x32c0
movq 0x8(%rbx), %rax
movq (%rax,%r13,8), %rdi
jmp 0x32c2
xorl %edi, %edi
movq %r15, %rsi
movl 0x20(%rsp), %edx
movl 0xc(%rsp), %ecx
movq 0x40(%rsp), %r8
callq 0x30f1
testl %eax, %eax
js 0x3672
movl %eax, %r14d
addq %r15, %r14
testq %r15, %r15
cmoveq %r15, %r14
addl %eax, %r12d
cmpq 0x28(%rsp), %r13
jae 0x331c
movq %r14, %rdi
leaq 0x21ba(%rip), %rsi      # 0x54ba
callq 0x49b7
testl %eax, %eax
js 0x3672
movl %eax, %ecx
addq %r14, %rcx
testq %r14, %r14
cmovneq %rcx, %r14
addl %eax, %r12d
cmpl $0x0, 0xc(%rsp)
je 0x3349
movq %r14, %rdi
leaq 0x1dc2(%rip), %rsi      # 0x50ef
callq 0x49b7
testl %eax, %eax
js 0x3672
movl %eax, %ecx
addq %r14, %rcx
testq %r14, %r14
cmovneq %rcx, %r14
addl %eax, %r12d
incq %r13
movq %r14, %r15
jmp 0x3276
cvttsd2si %xmm0, %rdx
movl %edx, %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jne 0x35ff
jp 0x35ff
leaq 0x2150(%rip), %rsi      # 0x54c7
movq %r12, %rdi
xorl %eax, %eax
callq 0x1290
testl %eax, %eax
pushq $-0x1
popq %rcx
cmovnsl %eax, %ecx
movl %ecx, %eax
jmp 0x3679
movq $0x0, 0x20(%rsp)
leaq 0x211e(%rip), %rsi      # 0x54be
movq %r14, %rdi
callq 0x49b7
testl %eax, %eax
js 0x3676
movl %eax, %ebx
movl %eax, %r13d
addq %r14, %r13
testq %r14, %r14
cmoveq %r14, %r13
cmpq $0x0, 0x20(%rsp)
setne %al
cmpl $0x0, 0xc(%rsp)
setne %cl
andb %al, %cl
movb %cl, 0x13(%rsp)
cmpb $0x1, %cl
jne 0x3400
leaq 0x1d0d(%rip), %rsi      # 0x50ef
movq %r13, %rdi
callq 0x49b7
testl %eax, %eax
js 0x3672
movl %eax, %ecx
addq %r13, %rcx
testq %r13, %r13
cmovneq %rcx, %r13
addl %eax, %ebx
leal 0x1(%rbp), %eax
movl %eax, 0x14(%rsp)
movq 0x20(%rsp), %rax
decq %rax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
movq %r15, 0x18(%rsp)
movq %rbp, 0x38(%rsp)
cmpq %r14, 0x20(%rsp)
je 0x3631
testq %r15, %r15
je 0x3672
cmpq %r14, 0x18(%r15)
jbe 0x3672
movq 0x8(%r15), %rax
movq %r14, 0x28(%rsp)
movq (%rax,%r14,8), %r14
testq %r14, %r14
je 0x3672
cmpl $0x0, 0xc(%rsp)
je 0x347e
movq %r13, %rdi
movl 0x14(%rsp), %esi
callq 0x49d4
testl %eax, %eax
js 0x3672
movl %eax, %ecx
addq %r13, %rcx
testq %r13, %r13
cmovneq %rcx, %r13
addl %eax, %ebx
movq %r14, %rdi
movq %r13, %rsi
callq 0x4a25
testl %eax, %eax
js 0x3672
movl %eax, %r15d
movq %r12, %rbp
movl %eax, %r12d
addq %r13, %r12
testq %r13, %r13
cmoveq %r13, %r12
movq %r12, %rdi
leaq 0x2012(%rip), %rsi      # 0x54c0
callq 0x49b7
testl %eax, %eax
js 0x3672
addl %ebx, %r15d
movl %eax, %ebx
addq %r12, %rbx
testq %r12, %r12
cmoveq %r12, %rbx
addl %eax, %r15d
cmpl $0x0, 0xc(%rsp)
je 0x3503
movq %rbx, %rdi
leaq 0x1ff2(%rip), %rsi      # 0x54d0
callq 0x49b7
testl %eax, %eax
pushq $-0x1
popq %r13
js 0x3676
movq %rbp, %r12
movl %eax, %ecx
addq %rbx, %rcx
testq %rbx, %rbx
cmovneq %rcx, %rbx
addl %eax, %r15d
jmp 0x3506
movq %rbp, %r12
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x25cc
movq %rax, %rdi
movq %rbx, %rsi
movl 0x14(%rsp), %edx
movl 0xc(%rsp), %ecx
movq %r12, %r8
callq 0x30f1
testl %eax, %eax
movq 0x38(%rsp), %rbp
js 0x3672
movl %eax, %r13d
addq %rbx, %r13
testq %rbx, %rbx
cmoveq %rbx, %r13
addl %eax, %r15d
movq 0x28(%rsp), %r14
cmpq 0x30(%rsp), %r14
jae 0x3578
movq %r13, %rdi
leaq 0x1f5e(%rip), %rsi      # 0x54ba
callq 0x49b7
testl %eax, %eax
js 0x3672
movl %eax, %ecx
addq %r13, %rcx
testq %r13, %r13
cmovneq %rcx, %r13
addl %eax, %r15d
cmpl $0x0, 0xc(%rsp)
je 0x35a5
movq %r13, %rdi
leaq 0x1b66(%rip), %rsi      # 0x50ef
callq 0x49b7
testl %eax, %eax
js 0x3672
movl %eax, %ecx
addq %r13, %rcx
testq %r13, %r13
cmovneq %rcx, %r13
addl %eax, %r15d
incq %r14
movl %r15d, %ebx
movq 0x18(%rsp), %r15
jmp 0x3421
leaq 0x1d15(%rip), %rsi      # 0x52d1
movq %r14, %rdi
callq 0x49b7
testl %eax, %eax
pushq $-0x1
popq %rcx
cmovsl %ecx, %eax
jmp 0x3679
cmpb $0x0, 0x14(%rsp)
je 0x3615
movq %r15, %rdi
movl %ebp, %esi
callq 0x49d4
testl %eax, %eax
pushq $-0x1
popq %r13
js 0x3676
movl %eax, %ecx
addq %r15, %rcx
testq %r15, %r15
cmovneq %rcx, %r15
addl %eax, %r12d
jmp 0x3619
leaq 0x1ec4(%rip), %rsi      # 0x54ca
movq %r12, %rdi
movb $0x1, %al
callq 0x1290
jmp 0x3381
pushq $-0x1
popq %r13
leaq 0x1e9c(%rip), %rsi      # 0x54bc
movq %r15, %rdi
callq 0x49b7
testl %eax, %eax
js 0x3676
addl %r12d, %eax
jmp 0x366d
cmpb $0x0, 0x13(%rsp)
je 0x3654
movq %r13, %rdi
movl %ebp, %esi
callq 0x49d4
testl %eax, %eax
js 0x3672
movl %eax, %ecx
addq %r13, %rcx
testq %r13, %r13
cmovneq %rcx, %r13
addl %eax, %ebx
leaq 0x1e67(%rip), %rsi      # 0x54c2
movq %r13, %rdi
callq 0x49b7
testl %eax, %eax
pushq $-0x1
popq %r13
js 0x3676
addl %ebx, %eax
movl %eax, %r13d
jmp 0x3676
pushq $-0x1
popq %r13
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq