// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movq 0x15a0c(%rip), %rax     # 0x17fe0
movq (%rax), %rdi
leaq 0xdd0c(%rip), %rsi      # 0x102ea
movq %r8, %rdx
xorl %eax, %eax
callq 0x2490
leaq 0xdd0e(%rip), %rsi      # 0x102fd
leaq 0x8(%rsp), %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rdx
xorl %eax, %eax
callq 0x5260
cmpl $-0x1, %eax
je 0x2742
movq 0x8(%rsp), %r9
leaq 0xdd90(%rip), %r8       # 0x103a8
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x3993
testq %rax, %rax
je 0x2765
movq %rax, %rdi
callq 0x23c0
leaq 0x8(%rsp), %r14
movq (%r14), %rdi
callq 0x23c0
leaq 0xdd7d(%rip), %rsi      # 0x103cb
movq %r14, %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x5260
cmpl $-0x1, %eax
je 0x2742
movq 0x8(%rsp), %r9
movq %r13, %rbx
movq %r13, %rdi
movq %r12, %r13
movq %r12, %rsi
movq %r15, %r12
movq %r15, %rdx
movq %rbp, %r15
movq %rbp, %rcx
leaq 0xdd54(%rip), %r8       # 0x103de
callq 0x3993
testq %rax, %rax
je 0x2799
movq %rax, %rbp
movq %rax, %rdi
callq 0x2140
movq %rbp, %rsi
addq %rax, %rsi
movq %rbp, %rdi
leaq 0xdd33(%rip), %rdx      # 0x103e6
callq 0x5c38
movq %rax, %r14
movq %rax, %rdi
callq 0x2140
leaq (%rax,%r14), %rsi
movq %r14, %rdi
leaq 0xdd34(%rip), %rdx      # 0x10405
callq 0x5c38
movq %rax, %r14
movq %rax, %rdi
leaq 0xdd2e(%rip), %rsi      # 0x10411
pushq $0xa
popq %rdx
callq 0x2150
testl %eax, %eax
jne 0x27be
movq 0x158e6(%rip), %rax     # 0x17fe0
movq (%rax), %rsi
pushq $0x2e
popq %rdi
callq 0x23f0
pushq $0x1
popq %rdi
callq 0x2210
movq %rbp, %rdi
callq 0x23c0
leaq 0x8(%rsp), %rdi
leaq 0xdcaa(%rip), %rsi      # 0x103cb
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x5260
cmpl $-0x1, %eax
movq %r15, %rbp
movq %r12, %r15
movq %r13, %r12
movq %rbx, %r13
jne 0x2666
callq 0x2040
cmpl $0x0, (%rax)
je 0x2780
movq %rax, %rbx
leaq 0xd9b3(%rip), %rdi      # 0x10109
xorl %eax, %eax
callq 0x73f0
andl $0x0, (%rbx)
jmp 0x280f
callq 0x2040
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x2790
movq %rax, %rbx
leaq 0xdc36(%rip), %rdi      # 0x103b4
jmp 0x27b2
leaq 0xd982(%rip), %rdi      # 0x10109
xorl %eax, %eax
callq 0x750f
jmp 0x280f
leaq 0xdc1d(%rip), %rdi      # 0x103b4
jmp 0x27fe
callq 0x2040
cmpl $0x0, (%rax)
movq 0x8(%rsp), %rsi
je 0x27f7
movq %rax, %rbx
leaq 0xdc3a(%rip), %rdi      # 0x103ec
xorl %eax, %eax
callq 0x73f0
andl $0x0, (%rbx)
jmp 0x2805
leaq 0xdc57(%rip), %rsi      # 0x1041c
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x2150
testl %eax, %eax
je 0x2821
leaq 0xdc4a(%rip), %rdi      # 0x10425
movq %rbp, %rsi
xorl %eax, %eax
callq 0x750f
callq 0x2040
andl $0x0, (%rax)
movq %rbp, %rdi
callq 0x23c0
jmp 0x2805
leaq 0xdbee(%rip), %rdi      # 0x103ec
xorl %eax, %eax
callq 0x750f
movq 0x8(%rsp), %rdi
callq 0x23c0
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
callq 0x23c0
movq 0x157b0(%rip), %rax     # 0x17fe0
movq (%rax), %rsi
pushq $0xa
popq %rdi
callq 0x23f0
xorl %eax, %eax
jmp 0x2812