// File: /workspace/github_cpp_makefile_star2_O2/cqbqdd11519[P]DockerClient/docker.cpp
// Function: Docker::requestAndParse(Method, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned int, rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>&, bool)
JSON_DOCUMENT Docker::requestAndParse(Method method, const std::string& path, unsigned success_code, JSON_DOCUMENT& param, bool isReturnJson){
    std::string readBuffer;
    std::string paramString;
    std::string method_str;
    struct curl_slist *headers = nullptr;
    const char *paramChar;
    switch(method){
        case GET:
            method_str = "GET";
            break;
        case POST:
            method_str = "POST";
            break;
        case DELETE:
            method_str = "DELETE";
            break;
        case PUT:
            method_str = "PUT";
            break;
        default:
            method_str = "GET";
    }

    curl = curl_easy_init();
    if(!curl){
        std::cout << "error while initiating curl" << std::endl;
        curl_global_cleanup();
        exit(1);
    }
    rapidjson::StringBuffer buffer;
    buffer.Clear();
    rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
    param.Accept(writer);
    paramString = std::string(buffer.GetString());
    paramChar = paramString.c_str();
    if(isReturnJson)
        headers = curl_slist_append(headers, "Accept: application/json");
    headers = curl_slist_append(headers, "Content-Type: application/json");

    //std::cout << "HOST_PATH : " << (host_uri + path) << std::endl;

    if(!is_remote)
        curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, "/var/run/docker.sock");
    curl_easy_setopt(curl, CURLOPT_URL, (host_uri + path).c_str());
    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method_str.c_str());
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    if(method == POST){
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, paramChar);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(paramChar));
    }

    res = curl_easy_perform(curl);
    if(res != CURLE_OK)
        fprintf(stderr, "curl_easy_perform() failed: %s\n",
            curl_easy_strerror(res));
    unsigned status = 0;
    curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &status);
    curl_easy_cleanup(curl);

    const char* buf = readBuffer.c_str();
    JSON_DOCUMENT doc(rapidjson::kObjectType);
    if(status == success_code || status == 200){
        doc.AddMember("success", true, doc.GetAllocator());

        JSON_VALUE dataString;
        dataString.SetString(readBuffer.c_str(), doc.GetAllocator());

        doc.AddMember("data", dataString, doc.GetAllocator());
    }else{
        JSON_DOCUMENT resp(&doc.GetAllocator());
        resp.Parse(buf);

        doc.AddMember("success", false, doc.GetAllocator());
        doc.AddMember("code", status, doc.GetAllocator());
        doc.AddMember("data", resp, doc.GetAllocator());
    }
    curl_slist_free_all(headers);
    return doc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %r9, %r14
movl %r8d, -0x30(%rbp)
movq %rcx, %r12
movl %edx, %r15d
movq %rsi, %r13
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rdi, %rbx
xorl %ecx, %ecx
leaq -0xf0(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
leaq -0x70(%rbp), %rsi
movq %rsi, -0x10(%rsi)
andq $0x0, -0x8(%rsi)
movb %cl, (%rax)
movb %cl, (%rdx)
movb %cl, (%rsi)
cmpl $0x4, %r15d
jae 0xacb8
movl %r15d, %eax
leaq 0xa279(%rip), %rcx      # 0x14f28
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
jmp 0xacbf
leaq 0x64fc(%rip), %rsi      # 0x111bb
leaq -0x80(%rbp), %rdi
callq 0x9c90
callq 0x9850
movq %r12, -0x40(%rbp)
movl %r15d, -0x34(%rbp)
movq %rax, 0x28(%r13)
testq %rax, %rax
je 0xb0e7
xorps %xmm0, %xmm0
leaq -0x130(%rbp), %rax
movaps %xmm0, 0x10(%rax)
andq $0x0, 0x20(%rax)
movaps %xmm0, (%rax)
movq $0x100, 0x28(%rax)      # imm = 0x100
leaq -0x1b8(%rbp), %rcx
movq %rax, -0x8(%rcx)
movups %xmm0, (%rcx)
andq $0x0, 0x20(%rcx)
movups %xmm0, 0x10(%rcx)
movq $0x200, 0x28(%rcx)      # imm = 0x200
movl $0x144, 0x30(%rcx)      # imm = 0x144
movb $0x0, 0x34(%rcx)
leaq -0x1c0(%rbp), %rsi
movq %r14, %rdi
callq 0x9c40
leaq -0x130(%rbp), %rdi
callq 0x9620
leaq -0xe0(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
movq %rax, %rsi
callq 0x9200
movb 0x10(%rbp), %r12b
leaq -0x100(%rbp), %r14
leaq -0xe0(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x97b0
movq %r15, %rdi
callq 0x9240
movq (%r14), %r14
testb %r12b, %r12b
je 0xad98
leaq 0x645f(%rip), %rsi      # 0x111eb
xorl %edi, %edi
callq 0x9810
movq %rax, %rdi
jmp 0xad9a
xorl %edi, %edi
leaq 0x6463(%rip), %rsi      # 0x11204
callq 0x9810
movq %rax, %r12
cmpb $0x0, 0x20(%r13)
jne 0xadc7
movq 0x28(%r13), %rdi
leaq 0x6468(%rip), %rdx      # 0x11223
movl $0x27f7, %esi           # imm = 0x27F7
xorl %eax, %eax
callq 0x9730
movq 0x28(%r13), %r15
leaq -0xe0(%rbp), %rdi
movq %r13, %rsi
movq -0x40(%rbp), %rdx
callq 0x9cd0
movq -0xe0(%rbp), %rdx
movq %r15, %rdi
movl $0x2712, %esi           # imm = 0x2712
xorl %eax, %eax
callq 0x9730
leaq -0xe0(%rbp), %rdi
callq 0x9240
movq 0x28(%r13), %rdi
movq -0x80(%rbp), %rdx
movl $0x2734, %esi           # imm = 0x2734
xorl %eax, %eax
callq 0x9730
movq 0x28(%r13), %rdi
movl $0x2727, %esi           # imm = 0x2727
movq %r12, %rdx
xorl %eax, %eax
callq 0x9730
movq 0x28(%r13), %rdi
movq 0xe12e(%rip), %rdx      # 0x18f60
movl $0x4e2b, %esi           # imm = 0x4E2B
xorl %eax, %eax
callq 0x9730
movq 0x28(%r13), %rdi
leaq -0x60(%rbp), %rdx
movl $0x2711, %esi           # imm = 0x2711
xorl %eax, %eax
callq 0x9730
cmpl $0x1, -0x34(%rbp)
jne 0xae87
movq 0x28(%r13), %rdi
movl $0x271f, %esi           # imm = 0x271F
movq %r14, %rdx
xorl %eax, %eax
callq 0x9730
movq 0x28(%r13), %r15
movq %r14, %rdi
callq 0x9230
pushq $0x3c
popq %rsi
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9730
movq 0x28(%r13), %rdi
callq 0x98a0
movl %eax, 0x30(%r13)
testl %eax, %eax
jne 0xb0bd
leaq -0x2c(%rbp), %rdx
andl $0x0, (%rdx)
movq 0x28(%r13), %rdi
movl $0x200002, %esi         # imm = 0x200002
xorl %eax, %eax
callq 0x9320
movq 0x28(%r13), %rdi
callq 0x97e0
movq -0x60(%rbp), %r14
pushq $0x3
popq %rsi
movl $0x400, %ecx            # imm = 0x400
movq %rbx, %rdi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x9130
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
setne %cl
cmpl $0xc8, %eax
setne %al
testb %al, %cl
jne 0xaf83
leaq 0x6363(%rip), %rax      # 0x11258
leaq -0x180(%rbp), %r14
movq %rax, (%r14)
movl $0x7, 0x8(%r14)
movq %rbx, %rdi
callq 0x9350
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
callq 0x9c30
xorps %xmm0, %xmm0
leaq -0xe0(%rbp), %r14
movaps %xmm0, (%r14)
movq -0x60(%rbp), %r15
movq %rbx, %rdi
callq 0x9350
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x9450
leaq 0x6311(%rip), %rax      # 0x11260
leaq -0x170(%rbp), %r14
movq %rax, (%r14)
movl $0x4, 0x8(%r14)
movq %rbx, %rdi
callq 0x9350
leaq -0xe0(%rbp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
callq 0x9540
jmp 0xb06a
movq %rbx, %rdi
callq 0x9350
xorps %xmm0, %xmm0
leaq -0xe0(%rbp), %rdi
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x28(%rdi)
movups %xmm0, 0x38(%rdi)
movq $0x400, 0x48(%rdi)      # imm = 0x400
andl $0x0, 0x50(%rdi)
andq $0x0, 0x58(%rdi)
movq %r14, %rsi
callq 0x9930
leaq 0x6290(%rip), %rax      # 0x11258
leaq -0x160(%rbp), %r14
movq %rax, (%r14)
movl $0x7, 0x8(%r14)
movq %rbx, %rdi
callq 0x9350
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x9c30
leaq 0x626c(%rip), %rax      # 0x11265
leaq -0x150(%rbp), %r14
movq %rax, (%r14)
movl $0x4, 0x8(%r14)
movl -0x2c(%rbp), %r15d
movq %rbx, %rdi
callq 0x9350
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq %rax, %rcx
callq 0x99c0
leaq 0x6231(%rip), %rax      # 0x11260
leaq -0x140(%rbp), %r14
movq %rax, (%r14)
movl $0x4, 0x8(%r14)
movq %rbx, %rdi
callq 0x9350
leaq -0xe0(%rbp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
callq 0x9540
leaq -0xe0(%rbp), %rdi
callq 0x9d48
movq %r12, %rdi
callq 0x9170
leaq -0x1b8(%rbp), %rdi
callq 0x9ca0
leaq -0x130(%rbp), %rdi
callq 0x9ca0
leaq -0x80(%rbp), %rdi
callq 0x9240
leaq -0x100(%rbp), %rdi
callq 0x9240
leaq -0x60(%rbp), %rdi
callq 0x9240
movq %rbx, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xdee4(%rip), %rcx      # 0x18fa8
movq (%rcx), %r14
movl %eax, %edi
callq 0x99a0
leaq 0x6163(%rip), %rsi      # 0x11238
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9980
jmp 0xae9c
movq 0xdeb2(%rip), %rdi      # 0x18fa0
leaq 0x60da(%rip), %rsi      # 0x111cf
callq 0x9560
movq %rax, %rdi
callq 0x9290
callq 0x91e0
pushq $0x1
popq %rdi
callq 0x97a0
jmp 0xb12a
jmp 0xb14f
movq %rax, %r14
leaq -0xe0(%rbp), %rdi
callq 0x9240
jmp 0xb152
jmp 0xb14f
jmp 0xb14f
jmp 0xb14f
movq %rax, %r14
jmp 0xb13e
movq %rax, %r14
leaq -0xe0(%rbp), %rdi
callq 0x9d48
movq %rbx, %rdi
callq 0x9d48
jmp 0xb152
jmp 0xb14f
movq %rax, %r14
jmp 0xb16a
movq %rax, %r14
leaq -0x1b8(%rbp), %rdi
callq 0x9ca0
leaq -0x130(%rbp), %rdi
callq 0x9ca0
leaq -0x80(%rbp), %rdi
callq 0x9240
leaq -0x100(%rbp), %rdi
callq 0x9240
leaq -0x60(%rbp), %rdi
callq 0x9240
movq %r14, %rdi
callq 0x9be0