// File: /workspace/github_cpp_makefile_star2_O3/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 0x993b
movl %ebx, %eax
leaq 0x9471(%rip), %rdx      # 0x12d98
movslq (%rdx,%rax,4), %rcx
addq %rdx, %rcx
leaq 0x9473(%rip), %rdx      # 0x12da8
movq (%rdx,%rax,8), %r8
jmp 0x9948
movl $0x3, %r8d
leaq 0x5883(%rip), %rcx      # 0xf1cb
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x76c0
callq 0x75b0
movq %rax, 0x28(%r12)
testq %rax, %rax
je 0x9e9f
xorps %xmm0, %xmm0
leaq -0x150(%rbp), %rax
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movq $0x100, 0x28(%rax)      # imm = 0x100
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 0x7820
leaq -0x150(%rbp), %rdi
callq 0x7460
leaq -0x120(%rbp), %rdi
leaq -0x40(%rbp), %rdx
movq %rax, %rsi
callq 0x7190
movb 0x10(%rbp), %r15b
leaq -0xc0(%rbp), %rdi
leaq -0x120(%rbp), %r14
movq %r14, %rsi
callq 0x7550
movq (%r14), %rdi
leaq -0x110(%rbp), %r14
cmpq %r14, %rdi
je 0x9a08
callq 0x73a0
movq -0xc0(%rbp), %rax
movq %rax, -0x50(%rbp)
testb %r15b, %r15b
je 0x9a2b
leaq 0x57dc(%rip), %rsi      # 0xf1fb
xorl %edi, %edi
callq 0x7590
movq %rax, %rdi
jmp 0x9a2d
xorl %edi, %edi
leaq 0x57e0(%rip), %rsi      # 0xf214
callq 0x7590
movq %rax, -0x60(%rbp)
cmpb $0x0, 0x20(%r12)
jne 0x9a5d
movq 0x28(%r12), %rdi
leaq 0x57e2(%rip), %rdx      # 0xf233
movl $0x27f7, %esi           # imm = 0x27F7
xorl %eax, %eax
callq 0x74e0
movq 0x28(%r12), %r15
leaq -0x120(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x7890
movq -0x120(%rbp), %rdx
movq %r15, %rdi
movl $0x2712, %esi           # imm = 0x2712
xorl %eax, %eax
callq 0x74e0
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x9a9b
callq 0x73a0
movq 0x28(%r12), %rdi
movq -0xa0(%rbp), %rdx
movl $0x2734, %esi           # imm = 0x2734
xorl %eax, %eax
callq 0x74e0
movq 0x28(%r12), %rdi
movl $0x2727, %esi           # imm = 0x2727
movq -0x60(%rbp), %rdx
xorl %eax, %eax
callq 0x74e0
movq 0x28(%r12), %rdi
movq 0xc484(%rip), %rdx      # 0x15f58
movl $0x4e2b, %esi           # imm = 0x4E2B
xorl %eax, %eax
callq 0x74e0
movq 0x28(%r12), %rdi
leaq -0x80(%rbp), %rdx
movl $0x2711, %esi           # imm = 0x2711
xorl %eax, %eax
callq 0x74e0
cmpl $0x1, %ebx
jne 0x9b2f
movq 0x28(%r12), %rdi
movl $0x271f, %esi           # imm = 0x271F
movq -0x50(%rbp), %rdx
xorl %eax, %eax
callq 0x74e0
movq 0x28(%r12), %r15
movq -0x50(%rbp), %rdi
callq 0x71c0
movq %r15, %rdi
movl $0x3c, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x74e0
movq 0x28(%r12), %rdi
callq 0x75d0
movl %eax, 0x30(%r12)
testl %eax, %eax
jne 0x9e56
leaq -0x2c(%rbp), %rdx
movl $0x0, (%rdx)
movq 0x28(%r12), %rdi
movl $0x200002, %esi         # imm = 0x200002
xorl %eax, %eax
callq 0x7260
movq 0x28(%r12), %rdi
callq 0x7570
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 0x9c64
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x9e80
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rsi
movaps %xmm0, (%rsi)
leaq 0x56a7(%rip), %rax      # 0xf268
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 0x9e80
movq -0x80(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x7330
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x9e80
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 0x562a(%rip), %rdx      # 0xf270
orq %rax, %rdx
movq %rdx, 0x8(%rsi)
movl $0x4, (%rsi)
leaq -0x40(%rbp), %rdx
movq %rbx, %rdi
callq 0x7060
jmp 0x9dc6
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x9e80
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 0x7390
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x9e80
xorps %xmm0, %xmm0
leaq -0x160(%rbp), %rsi
movaps %xmm0, (%rsi)
leaq 0x5592(%rip), %rax      # 0xf268
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 0x9e80
movabsq $-0x1000000000000, %r14 # imm = 0xFFFF000000000000
movl -0x2c(%rbp), %eax
xorps %xmm0, %xmm0
leaq -0x160(%rbp), %rsi
movaps %xmm0, (%rsi)
movw $0x405, 0xe(%rsi)       # imm = 0x405
movq 0x8(%rsi), %rdx
andq %r14, %rdx
leaq 0x5538(%rip), %rdi      # 0xf275
orq %rdx, %rdi
movq %rdi, 0x8(%rsi)
movl $0x4, (%rsi)
leaq -0x40(%rbp), %rdx
movq $0x0, 0x8(%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 0x9e80
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rsi
movaps %xmm0, (%rsi)
movw $0x405, 0xe(%rsi)       # imm = 0x405
andq 0x8(%rsi), %r14
leaq 0x54d2(%rip), %rax      # 0xf270
orq %r14, %rax
movq %rax, 0x8(%rsi)
movl $0x4, (%rsi)
leaq -0x120(%rbp), %rdx
movq %rbx, %rdi
callq 0x7060
leaq -0x120(%rbp), %rdi
callq 0x78c8
movq -0x60(%rbp), %rdi
callq 0x7110
movq -0x188(%rbp), %rdi
callq 0x7530
movq -0x190(%rbp), %rdi
callq 0x73a0
movq -0x140(%rbp), %rdi
callq 0x7530
movq -0x148(%rbp), %rdi
callq 0x73a0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x9e17
callq 0x73a0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x9e2f
callq 0x73a0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9e41
callq 0x73a0
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc14b(%rip), %rcx      # 0x15fa8
movq (%rcx), %r14
movl %eax, %edi
callq 0x7680
leaq 0x53da(%rip), %rsi      # 0xf248
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x7670
jmp 0x9b46
leaq 0x639e(%rip), %rdi      # 0x10225
leaq 0x5436(%rip), %rsi      # 0xf2c4
leaq 0x639b(%rip), %rcx      # 0x10230
movl $0x98b, %edx            # imm = 0x98B
callq 0x72b0
movq 0xc0fa(%rip), %rdi      # 0x15fa0
leaq 0x5332(%rip), %rsi      # 0xf1df
movl $0x1b, %edx
callq 0x74d0
movq 0xc0e2(%rip), %rdi      # 0x15fa0
callq 0x71f0
callq 0x7170
movl $0x1, %edi
callq 0x7540
jmp 0x9ef2
jmp 0x9f18
movq %rax, %r15
movq -0x120(%rbp), %rdi
cmpq %r14, %rdi
je 0x9f1b
callq 0x73a0
jmp 0x9f1b
jmp 0x9f18
jmp 0x9f18
jmp 0x9f18
movq %rax, %r15
jmp 0x9f06
movq %rax, %r15
leaq -0x120(%rbp), %rdi
callq 0x78c8
movq -0x58(%rbp), %rdi
callq 0x78c8
jmp 0x9f1b
jmp 0x9f18
movq %rax, %r15
jmp 0x9f4b
movq %rax, %r15
movq -0x188(%rbp), %rdi
callq 0x7530
movq -0x190(%rbp), %rdi
callq 0x73a0
movq -0x140(%rbp), %rdi
callq 0x7530
movq -0x148(%rbp), %rdi
callq 0x73a0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x9f63
callq 0x73a0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x9f7b
callq 0x73a0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9f8d
callq 0x73a0
movq %r15, %rdi
callq 0x77c0
nop