// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/dynamodb-kv/dispatch.c
// Function: callback_response
static int
callback_response(void * cookie, struct http_response * res, const char * err)
{
	struct request * R = cookie;
	struct dispatch_state * D = R->D;
	uint8_t * vbuf;
	uint32_t vlen;
	int status;

	/* Did we succeed? */
	switch (res->status) {
	case 200:
		status = 0;
		break;
	case 400:
		if (strcmp(err, "ConditionalCheckFailedException") == 0)
			status = 2;
		else
			status = 1;
		break;
	default:
		status = 1;
		break;
	}

	/* Send appropriate response back to the client. */
	switch (R->R.type) {
	case PROTO_DDBKV_PUT:
	case PROTO_DDBKV_ICAS:
	case PROTO_DDBKV_CREATE:
	case PROTO_DDBKV_DELETE:	/* Has same response as PUT. */
		if (proto_dynamodb_kv_response_put(D->writeq, R->R.ID,
		    status))
			goto err1;
		break;
	case PROTO_DDBKV_GET:
	case PROTO_DDBKV_GETC:		/* Has same response as GET. */
		/* Extract the value. */
		if (dynamodb_kv_extractv(res->body, res->bodylen,
		    &vbuf, &vlen))
			goto err1;

		/* A success without data is a status of 2. */
		if ((status == 0) && (vbuf == NULL))
			status = 2;

		/* Send a response back. */
		if (proto_dynamodb_kv_response_get(D->writeq, R->R.ID,
		    status, vlen, vbuf))
			goto err2;

		/* Free the value. */
		free(vbuf);
		break;
	}

	/* Free the response body buffer. */
	free(res->body);

	/* Remove this request from the in-progress list. */
	request_dequeue(D, R);

	/* Success! */
	return (0);

err2:
	free(vbuf);
err1:
	free(res->body);
	request_dequeue(D, R);

	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
subl $0xc8, %eax
je 0x5dd5
jmp 0x5dc9
movl -0x44(%rbp), %eax
subl $0x190, %eax            # imm = 0x190
je 0x5dde
jmp 0x5e05
movl $0x0, -0x40(%rbp)
jmp 0x5e0c
movq -0x20(%rbp), %rdi
leaq 0x1da6b(%rip), %rsi     # 0x23854
callq 0x3510
cmpl $0x0, %eax
jne 0x5dfc
movl $0x2, -0x40(%rbp)
jmp 0x5e03
movl $0x1, -0x40(%rbp)
jmp 0x5e0c
movl $0x1, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x48(%rbp)
addl $0xfffeff00, %eax       # imm = 0xFFFEFF00
subl $0x3, %eax
jb 0x5e41
jmp 0x5e22
movl -0x48(%rbp), %eax
addl $0xfffefef0, %eax       # imm = 0xFFFEFEF0
subl $0x2, %eax
jb 0x5e65
jmp 0x5e31
movl -0x48(%rbp), %eax
subl $0x10120, %eax          # imm = 0x10120
jne 0x5ecc
jmp 0x5e41
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rsi
movl -0x40(%rbp), %edx
callq 0x144f0
cmpl $0x0, %eax
je 0x5e63
jmp 0x5ef8
jmp 0x5ecc
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x38(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
callq 0x11980
cmpl $0x0, %eax
je 0x5e89
jmp 0x5ef8
cmpl $0x0, -0x40(%rbp)
jne 0x5e9d
cmpq $0x0, -0x38(%rbp)
jne 0x5e9d
movl $0x2, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rsi
movl -0x40(%rbp), %edx
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %r8
callq 0x14610
cmpl $0x0, %eax
je 0x5ec3
jmp 0x5eef
movq -0x38(%rbp), %rdi
callq 0x3460
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x3460
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x5c10
movl $0x0, -0x4(%rbp)
jmp 0x5f19
movq -0x38(%rbp), %rdi
callq 0x3460
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x3460
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x5c10
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)