// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs-dynamodb-init/main.c
// Function: createtable
static int
createtable(const char * key_id, const char * key_secret, const char * region,
    struct sock_addr * const * sas_ddb, const char * tablename)
{
	char * ddbreq;
	char * body;
	const uint8_t * desc;
	const char * tablestatus;

	/* Tell the user what we're doing. */
	fprintf(stderr, "Creating table %s ", tablename);

	/* Construct a CreateTable DynamoDB request. */
	if (asprintf(&ddbreq,
	    "{"
	    "\"TableName\":\"%s\","
	    "\"AttributeDefinitions\":[{"
	        "\"AttributeName\":\"K\","
	        "\"AttributeType\":\"S\"}],"
	    "\"KeySchema\":[{"
	        "\"AttributeName\":\"K\","
	        "\"KeyType\":\"HASH\"}],"
	    "\"BillingMode\":\"PAY_PER_REQUEST\"}", tablename) == -1) {
		warnp("asprintf");
		goto err0;
	}

	/* Send the request. */
	if ((body = request(key_id, key_secret, region, sas_ddb,
	    "CreateTable", ddbreq)) == NULL) {
		warnp("CreateTable failed: %s", ddbreq);
		goto err1;
	}

	/* Free request and response. */
	free(body);
	free(ddbreq);

	/* Wait until the table creation completes. */
	do {
		/* Construct a DescribeTable request. */
		if (asprintf(&ddbreq, "{\"TableName\":\"%s\"}",
		    tablename) == -1) {
			warnp("asprintf");
			goto err0;
		}

		/* Send the request. */
		if ((body = request(key_id, key_secret, region, sas_ddb,
		    "DescribeTable", ddbreq)) == NULL) {
			warnp("DescribeTable failed: %s", ddbreq);
			goto err1;
		}

		/* Find a the Table->TableStatus field. */
		desc = json_find((uint8_t *)body,
		    (uint8_t *)body + strlen(body), "Table");
		tablestatus = (const char *)json_find(desc,
		    desc + strlen((const char *)desc), "TableStatus");

		/* It should be "CREATING" or "ACTIVE". */
		if (strncmp(tablestatus, "\"CREATING\"", 10) == 0) {
			/* Wait a second and try again. */
			fprintf(stderr, ".");
			sleep(1);
			free(body);
		} else if (strncmp(tablestatus, "\"ACTIVE\"", 8) == 0) {
			/* We're done. */
			free(body);
			break;
		} else {
			/* Invalid status. */
			warn0("Unexpected DescribeTable response: %s", body);
			free(body);
			goto err1;
		}
	} while (1);

	/* Print delayed EOL. */
	fprintf(stderr, "\n");

	/* Success! */
	return (0);

err1:
	free(ddbreq);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq 0x20a0d(%rip), %rax     # 0x23fe0
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
leaq 0x18e37(%rip), %rsi     # 0x1c418
movb $0x0, %al
callq 0x24a0
movq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rdi
leaq 0x18e34(%rip), %rsi     # 0x1c42b
movb $0x0, %al
callq 0x62a0
cmpl $-0x1, %eax
jne 0x363f
jmp 0x3605
callq 0x2040
cmpl $0x0, (%rax)
je 0x362a
leaq 0x18ba3(%rip), %rdi     # 0x1c1b9
movb $0x0, %al
callq 0x9d30
callq 0x2040
movl $0x0, (%rax)
jmp 0x3638
leaq 0x18b88(%rip), %rdi     # 0x1c1b9
movb $0x0, %al
callq 0x9f80
jmp 0x363a
jmp 0x38ba
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %r9
leaq 0x18e7c(%rip), %r8      # 0x1c4d6
callq 0x3c60
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x36ad
jmp 0x366b
callq 0x2040
cmpl $0x0, (%rax)
je 0x3694
movq -0x38(%rbp), %rsi
leaq 0x18e62(%rip), %rdi     # 0x1c4e2
movb $0x0, %al
callq 0x9d30
callq 0x2040
movl $0x0, (%rax)
jmp 0x36a6
movq -0x38(%rbp), %rsi
leaq 0x18e43(%rip), %rdi     # 0x1c4e2
movb $0x0, %al
callq 0x9f80
jmp 0x36a8
jmp 0x38b1
movq -0x40(%rbp), %rdi
callq 0x23e0
movq -0x38(%rbp), %rdi
callq 0x23e0
movq -0x30(%rbp), %rdx
leaq -0x38(%rbp), %rdi
leaq 0x18e2b(%rip), %rsi     # 0x1c4f9
movb $0x0, %al
callq 0x62a0
cmpl $-0x1, %eax
jne 0x3716
jmp 0x36dc
callq 0x2040
cmpl $0x0, (%rax)
je 0x3701
leaq 0x18acc(%rip), %rdi     # 0x1c1b9
movb $0x0, %al
callq 0x9d30
callq 0x2040
movl $0x0, (%rax)
jmp 0x370f
leaq 0x18ab1(%rip), %rdi     # 0x1c1b9
movb $0x0, %al
callq 0x9f80
jmp 0x3711
jmp 0x38ba
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %r9
leaq 0x18ddb(%rip), %r8      # 0x1c50c
callq 0x3c60
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x3784
jmp 0x3742
callq 0x2040
cmpl $0x0, (%rax)
je 0x376b
movq -0x38(%rbp), %rsi
leaq 0x18dc3(%rip), %rdi     # 0x1c51a
movb $0x0, %al
callq 0x9d30
callq 0x2040
movl $0x0, (%rax)
jmp 0x377d
movq -0x38(%rbp), %rsi
leaq 0x18da4(%rip), %rdi     # 0x1c51a
movb $0x0, %al
callq 0x9f80
jmp 0x377f
jmp 0x38b1
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2150
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdi
addq %rax, %rsi
leaq 0x18d65(%rip), %rdx     # 0x1c514
callq 0x74f0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2150
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdi
addq %rax, %rsi
leaq 0x18d50(%rip), %rdx     # 0x1c533
callq 0x74f0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x18d48(%rip), %rsi     # 0x1c53f
movl $0xa, %edx
callq 0x2170
cmpl $0x0, %eax
jne 0x3833
movq 0x207d3(%rip), %rax     # 0x23fe0
movq (%rax), %rdi
leaq 0x18f5e(%rip), %rsi     # 0x1c775
movb $0x0, %al
callq 0x24a0
movl $0x1, %edi
callq 0x2240
movq -0x40(%rbp), %rdi
callq 0x23e0
jmp 0x3882
movq -0x50(%rbp), %rdi
leaq 0x18d0c(%rip), %rsi     # 0x1c54a
movl $0x8, %edx
callq 0x2170
cmpl $0x0, %eax
jne 0x3858
movq -0x40(%rbp), %rdi
callq 0x23e0
jmp 0x3890
jmp 0x385a
movq -0x40(%rbp), %rsi
leaq 0x18cee(%rip), %rdi     # 0x1c553
movb $0x0, %al
callq 0x9f80
callq 0x2040
movl $0x0, (%rax)
movq -0x40(%rbp), %rdi
callq 0x23e0
jmp 0x38b1
jmp 0x3884
movb $0x1, %al
testb $0x1, %al
jne 0x36bf
jmp 0x3890
movq 0x20749(%rip), %rax     # 0x23fe0
movq (%rax), %rdi
leaq 0x1b06f(%rip), %rsi     # 0x1e910
movb $0x0, %al
callq 0x24a0
movl $0x0, -0x4(%rbp)
jmp 0x38c1
movq -0x38(%rbp), %rdi
callq 0x23e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)