// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/proto_s3/proto_s3_server.c
// Function: proto_s3_request_parse
static int
proto_s3_request_parse(const struct wire_packet * P,
    struct proto_s3_request * R)
{
	size_t pos = 0;

	/* Store request ID. */
	R->ID = P->ID;

	/* Extract the request type. */
	if (P->len < pos + 4)
		goto err0;
	R->type = be32dec(&P->buf[pos]);
	pos += 4;

	/* Extract bucket name (appears in every request type). */
	if ((R->bucket = mkstr(P->buf, P->len, &pos)) == NULL)
		goto err0;

	/* Extract object name (appears in every request type). */
	if ((R->object = mkstr(P->buf, P->len, &pos)) == NULL)
		goto err1;

	/* Parse request-type-specific fields. */
	switch (R->type) {
	case PROTO_S3_PUT:
		if (P->len < pos + 4)
			goto err2;
		R->r.put.len = be32dec(&P->buf[pos]);
		pos += 4;
		if (P->len != pos + R->r.put.len)
			goto err2;
		if ((R->r.put.buf = malloc(R->r.put.len)) == NULL)
			goto err2;
		memcpy(R->r.put.buf, &P->buf[pos], R->r.put.len);
		break;
	case PROTO_S3_GET:
		if (P->len != pos + 4)
			goto err2;
		R->r.get.maxlen = be32dec(&P->buf[pos]);
		break;
	case PROTO_S3_RANGE:
		if (P->len != pos + 8)
			goto err2;
		R->r.range.offset = be32dec(&P->buf[pos]);
		R->r.range.len = be32dec(&P->buf[pos + 4]);
		break;
	case PROTO_S3_HEAD:
	case PROTO_S3_DELETE:
		if (P->len != pos)
			goto err2;
		break;
	default:
		goto err2;
	}

	/* Success! */
	return (0);

err2:
	free(R->object);
err1:
	free(R->bucket);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
jae 0xf530
jmp 0xf746
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq -0x20(%rbp), %rdi
callq 0xf9e0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x20(%rbp), %rdx
callq 0xfa20
movq -0x18(%rbp), %rcx
movq %rax, 0x10(%rcx)
cmpq $0x0, %rax
jne 0xf582
jmp 0xf746
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x20(%rbp), %rdx
callq 0xfa20
movq -0x18(%rbp), %rcx
movq %rax, 0x18(%rcx)
cmpq $0x0, %rax
jne 0xf5ae
jmp 0xf739
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
addl $0xffff0000, %eax       # imm = 0xFFFF0000
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x30, %eax
ja 0xf721
movq -0x28(%rbp), %rax
leaq 0x108e0(%rip), %rcx     # 0x1feb4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
jae 0xf5f7
jmp 0xf72c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq -0x20(%rbp), %rdi
callq 0xf9e0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rdx
movl 0x20(%rdx), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
je 0xf63d
jmp 0xf72c
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, %edi
callq 0x2350
movq -0x18(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0xf65e
jmp 0xf72c
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
addq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, %edx
callq 0x2300
jmp 0xf723
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
je 0xf69f
jmp 0xf72c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq -0x20(%rbp), %rdi
callq 0xf9e0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0xf723
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0xf6d2
jmp 0xf72c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq -0x20(%rbp), %rdi
callq 0xf9e0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
addq $0x4, %rax
addq %rax, %rdi
callq 0xf9e0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0xf723
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x20(%rbp), %rax
je 0xf71f
jmp 0xf72c
jmp 0xf723
jmp 0xf72c
movl $0x0, -0x4(%rbp)
jmp 0xf74d
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)