// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs-s3/findlast.c
// Function: findlast
int
findlast(struct wire_requestqueue * Q_S3, const char * bucket,
    uint64_t * L, size_t * olen)
{
	uint64_t N;
	int i;
	int status;
	size_t clen;

	/* We have no objects yet. */
	*L = 0;
	*olen = 0;

	/* See Algorithm FindLast in the DESIGN file. */
	for (i = 0; i < 64; i++) {
		if (head(Q_S3, bucket, (uint64_t)(1) << i, &status, &clen))
			goto err0;
		if (status == 404)
			break;
		if (status != 200)
			goto err1;
		*L = (uint64_t)(1) << i;
		*olen = clen;
	}
	for (N = *L / 2; N > 0; N = N / 2) {
		if (head(Q_S3, bucket, *L + N, &status, &clen))
			goto err0;
		if (status == 200) {
			*L = *L + N;
			*olen = clen;
		} else if (status != 404)
			goto err1;
	}

	/* If necessary, scan backwards until we find a non-empty object. */
	while ((*olen == 0) && (*L > 1)) {
		*L -= 1;
		if (head(Q_S3, bucket, *L, &status, &clen))
			goto err0;
		if (status == 404) {
			warn0("Cannot find non-empty S3 object");
			goto err0;
		} else if (status != 200)
			goto err1;
		*olen = clen;
	}

	/* Success! */
	return (0);

err1:
	warn0("HEAD returned status %d!", status);
err0:
	/* 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 %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x34(%rbp)
cmpl $0x40, -0x34(%rbp)
jge 0x4ddd
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x4f40
cmpl $0x0, %eax
je 0x4d97
jmp 0x4f28
cmpl $0x194, -0x38(%rbp)     # imm = 0x194
jne 0x4da2
jmp 0x4ddd
cmpl $0xc8, -0x38(%rbp)
je 0x4db0
jmp 0x4f08
movl -0x34(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4d65
movq -0x20(%rbp), %rax
movq (%rax), %rax
shrq %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jbe 0x4e63
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
addq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x4f40
cmpl $0x0, %eax
je 0x4e1c
jmp 0x4f28
cmpl $0xc8, -0x38(%rbp)
jne 0x4e44
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0x4e54
cmpl $0x194, -0x38(%rbp)     # imm = 0x194
je 0x4e52
jmp 0x4f08
jmp 0x4e54
jmp 0x4e56
movq -0x30(%rbp), %rax
shrq %rax
movq %rax, -0x30(%rbp)
jmp 0x4deb
jmp 0x4e65
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x41(%rbp)
jne 0x4e82
movq -0x20(%rbp), %rax
cmpq $0x1, (%rax)
seta %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x4e8b
jmp 0x4eff
movq -0x20(%rbp), %rax
movq (%rax), %rcx
subq $0x1, %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x4f40
cmpl $0x0, %eax
je 0x4ebc
jmp 0x4f28
cmpl $0x194, -0x38(%rbp)     # imm = 0x194
jne 0x4ee2
jmp 0x4ec7
leaq 0xf9d6(%rip), %rdi      # 0x148a4
movb $0x0, %al
callq 0xe050
callq 0x20a0
movl $0x0, (%rax)
jmp 0x4f28
cmpl $0xc8, -0x38(%rbp)
je 0x4eed
jmp 0x4f08
jmp 0x4eef
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0x4e65
movl $0x0, -0x4(%rbp)
jmp 0x4f2f
jmp 0x4f0a
movl -0x38(%rbp), %esi
leaq 0xf9b0(%rip), %rdi      # 0x148c4
movb $0x0, %al
callq 0xe050
callq 0x20a0
movl $0x0, (%rax)
jmp 0x4f28
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)