// File: /workspace/github_cpp_makefile_star2_O1/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 $0x178, %rsp            # imm = 0x178
movq %r9, %r14
movl %r8d, -0x44(%rbp)
movq %rcx, %r13
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, -0x58(%rbp)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xb0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x90(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
cmpl $0x4, %edx
jae 0x940f
movl %ebx, %eax
leaq 0xa99d(%rip), %rdx      # 0x13d98
movslq (%rdx,%rax,4), %rcx
addq %rdx, %rcx
leaq 0xa99f(%rip), %rdx      # 0x13da8
movq (%rdx,%rax,8), %r8
jmp 0x941c
movl $0x3, %r8d
leaq 0x6daf(%rip), %rcx      # 0x101cb
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x76e0
callq 0x75d0
movq %rax, 0x28(%r12)
testq %rax, %rax
je 0x9980
xorps %xmm0, %xmm0
leaq -0x160(%rbp), %rax
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movq $0x100, 0x28(%rax)      # imm = 0x100
movq 0x10(%rax), %rdx
movq %rdx, 0x18(%rax)
leaq -0x1a0(%rbp), %rsi
movq %rax, (%rsi)
movups %xmm0, 0x8(%rsi)
movups %xmm0, 0x18(%rsi)
movq %rcx, 0x28(%rsi)
movq $0x200, 0x30(%rsi)      # imm = 0x200
movl $0x144, 0x38(%rsi)      # imm = 0x144
movb $0x0, 0x3c(%rsi)
movq %r14, %rdi
callq 0x7840
leaq -0x160(%rbp), %rdi
callq 0x7470
leaq -0x120(%rbp), %rdi
leaq -0x40(%rbp), %rdx
movq %rax, %rsi
callq 0x71a0
movb 0x10(%rbp), %r15b
leaq -0xc0(%rbp), %rdi
leaq -0x120(%rbp), %r14
movq %r14, %rsi
callq 0x7570
movq (%r14), %rdi
leaq -0x110(%rbp), %r14
cmpq %r14, %rdi
je 0x94e4
callq 0x73b0
movq -0xc0(%rbp), %rax
movq %rax, -0x50(%rbp)
testb %r15b, %r15b
je 0x9507
leaq 0x6d00(%rip), %rsi      # 0x101fb
xorl %edi, %edi
callq 0x75b0
movq %rax, %rdi
jmp 0x9509
xorl %edi, %edi
leaq 0x6d04(%rip), %rsi      # 0x10214
callq 0x75b0
movq %rax, -0x60(%rbp)
cmpb $0x0, 0x20(%r12)
jne 0x9539
movq 0x28(%r12), %rdi
leaq 0x6d06(%rip), %rdx      # 0x10233
movl $0x27f7, %esi           # imm = 0x27F7
xorl %eax, %eax
callq 0x74f0
movq 0x28(%r12), %r15
leaq -0x120(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x78a0
movq -0x120(%rbp), %rdx
movq %r15, %rdi
movl $0x2712, %esi           # imm = 0x2712
xorl %eax, %eax
callq 0x74f0
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x9577
callq 0x73b0
movq 0x28(%r12), %rdi
movq -0xa0(%rbp), %rdx
movl $0x2734, %esi           # imm = 0x2734
xorl %eax, %eax
callq 0x74f0
movq 0x28(%r12), %rdi
movl $0x2727, %esi           # imm = 0x2727
movq -0x60(%rbp), %rdx
xorl %eax, %eax
callq 0x74f0
movq 0x28(%r12), %rdi
movq 0xe9a8(%rip), %rdx      # 0x17f58
movl $0x4e2b, %esi           # imm = 0x4E2B
xorl %eax, %eax
callq 0x74f0
movq 0x28(%r12), %rdi
leaq -0x80(%rbp), %rdx
movl $0x2711, %esi           # imm = 0x2711
xorl %eax, %eax
callq 0x74f0
cmpl $0x1, %ebx
jne 0x960b
movq 0x28(%r12), %rdi
movl $0x271f, %esi           # imm = 0x271F
movq -0x50(%rbp), %rdx
xorl %eax, %eax
callq 0x74f0
movq 0x28(%r12), %r15
movq -0x50(%rbp), %rdi
callq 0x71d0
movq %r15, %rdi
movl $0x3c, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x74f0
movq 0x28(%r12), %rdi
callq 0x75f0
movl %eax, 0x30(%r12)
testl %eax, %eax
jne 0x9937
leaq -0x2c(%rbp), %rdx
movl $0x0, (%rdx)
movq 0x28(%r12), %rdi
movl $0x200002, %esi         # imm = 0x200002
xorl %eax, %eax
callq 0x7270
movq 0x28(%r12), %rdi
callq 0x7590
movq -0x80(%rbp), %r14
movl $0x400, %ecx            # imm = 0x400
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x70e0
movl -0x2c(%rbp), %eax
cmpl -0x44(%rbp), %eax
setne %cl
cmpl $0xc8, %eax
setne %al
testb %al, %cl
jne 0x9740
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x9961
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rsi
movaps %xmm0, (%rsi)
leaq 0x6bcb(%rip), %rax      # 0x10268
movabsq $0x405000000000000, %rdx # imm = 0x405000000000000
orq %rax, %rdx
movq %rdx, 0x8(%rsi)
movl $0x7, (%rsi)
leaq -0x120(%rbp), %rdx
movaps %xmm0, (%rdx)
movw $0xa, 0xe(%rdx)
movq %rbx, %rdi
callq 0x7060
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
je 0x9961
movq -0x80(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x7340
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x9961
movabsq $-0x1000000000000, %rax # imm = 0xFFFF000000000000
xorps %xmm0, %xmm0
leaq -0x120(%rbp), %rsi
movaps %xmm0, (%rsi)
movw $0x405, 0xe(%rsi)       # imm = 0x405
andq 0x8(%rsi), %rax
leaq 0x6b4e(%rip), %rdx      # 0x10270
orq %rax, %rdx
movq %rdx, 0x8(%rsi)
movl $0x4, (%rsi)
leaq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x7060
jmp 0x989d
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x9961
xorps %xmm0, %xmm0
leaq -0x120(%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
movl $0x0, 0x50(%rdi)
movq $0x0, 0x58(%rdi)
leaq -0x40(%rbp), %rsi
movq %r14, (%rsi)
movq %r14, 0x8(%rsi)
callq 0x73a0
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x9961
xorps %xmm0, %xmm0
leaq -0x130(%rbp), %rsi
movaps %xmm0, (%rsi)
leaq 0x6ab6(%rip), %rax      # 0x10268
movabsq $0x405000000000000, %rdx # imm = 0x405000000000000
orq %rax, %rdx
movq %rdx, 0x8(%rsi)
movl $0x7, (%rsi)
leaq -0x40(%rbp), %rdx
movaps %xmm0, (%rdx)
movw $0x9, 0xe(%rdx)
movq %rbx, %rdi
callq 0x7060
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x9961
movabsq $-0x1000000000000, %r14 # imm = 0xFFFF000000000000
movl -0x2c(%rbp), %eax
xorps %xmm0, %xmm0
leaq -0x130(%rbp), %rsi
movaps %xmm0, (%rsi)
movw $0x405, 0xe(%rsi)       # imm = 0x405
movq 0x8(%rsi), %rdx
andq %r14, %rdx
leaq 0x6a5c(%rip), %rdi      # 0x10275
orq %rdx, %rdi
movq %rdi, 0x8(%rsi)
movl $0x4, (%rsi)
leaq -0x40(%rbp), %rdx
movaps %xmm0, (%rdx)
movq %rax, (%rdx)
xorl %edi, %edi
testl %eax, %eax
setns %dil
shll $0x5, %edi
orl $0x1d6, %edi            # imm = 0x1D6
movw %di, 0xe(%rdx)
movq %rbx, %rdi
callq 0x7060
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x9961
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rsi
movaps %xmm0, (%rsi)
movw $0x405, 0xe(%rsi)       # imm = 0x405
andq 0x8(%rsi), %r14
leaq 0x69fb(%rip), %rax      # 0x10270
orq %r14, %rax
movq %rax, 0x8(%rsi)
movl $0x4, (%rsi)
leaq -0x120(%rbp), %rdx
movq %rbx, %rdi
callq 0x7060
leaq -0x120(%rbp), %rdi
callq 0x78d8
movq -0x60(%rbp), %rdi
callq 0x7120
movq -0x188(%rbp), %rdi
callq 0x7550
movq -0x190(%rbp), %rdi
testq %rdi, %rdi
je 0x98c3
callq 0x73b0
movq -0x150(%rbp), %rdi
callq 0x7550
movq -0x158(%rbp), %rdi
testq %rdi, %rdi
je 0x98e0
callq 0x73b0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x98f8
callq 0x73b0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x9910
callq 0x73b0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9922
callq 0x73b0
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe66a(%rip), %rcx      # 0x17fa8
movq (%rcx), %r14
movl %eax, %edi
callq 0x76a0
leaq 0x68f9(%rip), %rsi      # 0x10248
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x7690
jmp 0x9622
leaq 0x78bd(%rip), %rdi      # 0x11225
leaq 0x6955(%rip), %rsi      # 0x102c4
leaq 0x78ba(%rip), %rcx      # 0x11230
movl $0x98b, %edx            # imm = 0x98B
callq 0x72c0
movq 0xe619(%rip), %rdi      # 0x17fa0
leaq 0x6851(%rip), %rsi      # 0x101df
movl $0x1b, %edx
callq 0x74e0
movq 0xe601(%rip), %rdi      # 0x17fa0
callq 0x7200
callq 0x7180
movl $0x1, %edi
callq 0x7560
jmp 0x99d3
jmp 0x99f9
movq %rax, %r15
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x99fc
callq 0x73b0
jmp 0x99fc
jmp 0x99f9
jmp 0x99f9
jmp 0x99f9
movq %rax, %r15
jmp 0x99e7
movq %rax, %r15
leaq -0x120(%rbp), %rdi
callq 0x78d8
movq -0x58(%rbp), %rdi
callq 0x78d8
jmp 0x99fc
jmp 0x99f9
movq %rax, %r15
jmp 0x9a14
movq %rax, %r15
leaq -0x198(%rbp), %rdi
callq 0x7110
leaq -0x160(%rbp), %rdi
callq 0x7110
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x9a2c
callq 0x73b0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x9a44
callq 0x73b0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9a56
callq 0x73b0
movq %r15, %rdi
callq 0x77e0
jmp 0x9a60
movq %rax, %rdi
callq 0xad13