// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/lbs-dynamodb/metadata.c
// Function: metadata_init
struct metadata *
metadata_init(struct wire_requestqueue * Q, uint64_t * itemsz,
    uint8_t * tableid)
{
	struct metadata * M;

	/* Bake a cookie. */
	if ((M = malloc(sizeof(struct metadata))) == NULL)
		goto err0;
	M->Q = Q;

	/* Read metadata and take ownership. */
tryagain:
	M->init_done = 0;
	if (proto_dynamodb_kv_request_getc(Q, "metadata",
	    callback_readmetadata, M)) {
		warnp("Error reading LBS metadata");
		goto err1;
	}
	if (events_spin(&M->init_done)) {
		warnp("Error claiming ownership of LBS metadata");
		goto err1;
	}

	/* Did we lose a race trying to claim the metadata? */
	if (M->init_lostrace) {
		warn0("Lost race claiming metadata; trying again...");
		goto tryagain;
	}

	/* The next metadata will be the same except one higher generation. */
	M->M_latest = M->M_stored;
	M->M_latest.generation++;

	/* Nothing in progress yet. */
	M->M_latest.callback_state = NULL;
	M->M_latest.cookie_state = NULL;
	M->callback_deletedto = NULL;
	M->cookie_deletedto = NULL;
	M->write_inprogress = 0;
	M->write_wanted = 0;

	/* Return the item size and table ID. */
	*itemsz = M->itemsz;
	memcpy(tableid, M->tableid, 32);

	/* Success! */
	return (M);

err1:
	free(M);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movl $0x100, %edi            # imm = 0x100
callq 0x2270
testq %rax, %rax
je 0x4396
movq %rax, %rbx
movq %r12, (%rax)
movl $0x0, 0xd0(%rax)
leaq 0x9533(%rip), %rsi      # 0xd7fc
leaq 0x168(%rip), %rdx       # 0x4438
movq %r12, %rdi
movq %rax, %rcx
callq 0x9f84
testl %eax, %eax
je 0x430b
callq 0x20a0
movq %rax, %rbp
cmpl $0x0, (%rbp)
je 0x4380
leaq 0x94c9(%rip), %rdi      # 0xd7c1
xorl %eax, %eax
callq 0x95b0
movl $0x0, (%rbp)
jmp 0x438e
movq %r15, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, %r13
addq $0xd0, %r13
xorl %r15d, %r15d
leaq 0x10f(%rip), %r14       # 0x4438
movq %r13, %rdi
callq 0x4c35
testl %eax, %eax
jne 0x43aa
cmpl $0x0, 0xd4(%rbx)
je 0x43ce
leaq 0x94bc(%rip), %rdi      # 0xd805
xorl %eax, %eax
callq 0x96cf
callq 0x20a0
movq %rax, %rbp
movl %r15d, (%rax)
movl %r15d, 0xd0(%rbx)
movq %r12, %rdi
leaq 0x9490(%rip), %rsi      # 0xd7fc
movq %r14, %rdx
movq %rbx, %rcx
callq 0x9f84
testl %eax, %eax
je 0x4329
jmp 0x42e7
leaq 0x943a(%rip), %rdi      # 0xd7c1
xorl %eax, %eax
callq 0x96cf
movq %rbx, %rdi
callq 0x2040
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20a0
cmpl $0x0, (%rax)
je 0x442c
movq %rax, %r14
leaq 0x941e(%rip), %rdi      # 0xd7dc
xorl %eax, %eax
callq 0x95b0
movl $0x0, (%r14)
jmp 0x438e
movups 0x8(%rbx), %xmm0
movups 0x18(%rbx), %xmm1
movups %xmm1, 0x78(%rbx)
movups %xmm0, 0x68(%rbx)
incq 0x78(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x88(%rbx)
movups %xmm0, 0xb8(%rbx)
movq $0x0, 0xc8(%rbx)
movq 0xd8(%rbx), %rax
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movups 0xe0(%rbx), %xmm0
movups 0xf0(%rbx), %xmm1
movq 0x10(%rsp), %rax
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
jmp 0x4398
leaq 0x93a9(%rip), %rdi      # 0xd7dc
jmp 0x4387