// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/perftests/dynamodb_request/main.c
// Function: main
int
main(int argc, char * argv[])
{
	char * key_id;
	char * key_secret;
	struct sock_addr ** sas;
	const char * body;
	int done;

	WARNP_INIT;

	/* Sanity-check. */
	if (argc != 2) {
		fprintf(stderr, "usage: test_dynamodb %s\n", "<keyfile>");
		exit(1);
	}

	/* Read AWS keys. */
	if (aws_readkeys(argv[1], &key_id, &key_secret)) {
		warnp("Failure reading AWS keys");
		exit(1);
	}

	/* Resolve target addresses. */
	if ((sas = sock_resolve("dynamodb.us-east-1.amazonaws.com:443")) == NULL) {
		warnp("Cannot resolve DynamoDB DNS");
		exit(1);
	}

	/* Send DescribeTable request. */
	body = "{ \"TableName\": \"kivaloo-testing\" }";
	done = 0;
	(void)dynamodb_request(sas, key_id, key_secret, "us-east-1",
	    "DescribeTable", (const uint8_t *)body, strlen(body), 1024,
	    donereq, &done);

	/* Wait for request to complete. */
	if (events_spin(&done)) {
		warnp("Error in event loop");
		exit(1);
	}

	/* Send PutItem request. */
	body = "{"
		"\"TableName\": \"kivaloo-testing\","
		"\"ReturnConsumedCapacity\": \"TOTAL\","
		"\"Item\": {"
		    "\"K\": { \"S\": \"key\" },"
		    "\"V\": { \"B\": \"dmFsdWUK\" }"
		"}"
	    "}";
	done = 0;
	(void)dynamodb_request(sas, key_id, key_secret, "us-east-1",
	    "PutItem", (const uint8_t *)body, strlen(body), 1024,
	    donereq, &done);

	/* Wait for request to complete. */
	if (events_spin(&done)) {
		warnp("Error in event loop");
		exit(1);
	}

	/* Send GetItem request. */
	body = "{"
		"\"TableName\": \"kivaloo-testing\","
		"\"ReturnConsumedCapacity\": \"TOTAL\","
		"\"Key\": {"
		    "\"K\": { \"S\": \"key\" }"
		"}"
	    "}";
	done = 0;
	(void)dynamodb_request(sas, key_id, key_secret, "us-east-1",
	    "GetItem", (const uint8_t *)body, strlen(body), 1024,
	    donereq, &done);

	/* Wait for request to complete. */
	if (events_spin(&done)) {
		warnp("Error in event loop");
		exit(1);
	}

	/* Free address structures. */
	sock_addr_freelist(sas);

	/* Success! */
	exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x2688
callq 0x4e18
cmpl $0x2, %ebp
jne 0x26cf
movq 0x8(%rbx), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x2904
testl %eax, %eax
jne 0x26f3
leaq 0x9995(%rip), %rdi      # 0xc040
callq 0x3fa0
testq %rax, %rax
jne 0x270d
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2829
leaq 0x999b(%rip), %rdi      # 0xc065
jmp 0x2820
movq 0x1090a(%rip), %rax     # 0x12fe0
movq (%rax), %rdi
leaq 0x9924(%rip), %rsi      # 0xc004
leaq 0x9936(%rip), %rdx      # 0xc01d
xorl %eax, %eax
callq 0x2470
jmp 0x2849
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2803
leaq 0x991f(%rip), %rdi      # 0xc027
jmp 0x2820
movq %rax, %rbx
leaq 0x4(%rsp), %r14
andl $0x0, (%r14)
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x127(%rip), %r15       # 0x2851
leaq 0x9973(%rip), %rcx      # 0xc0a4
leaq 0x9976(%rip), %r8       # 0xc0ae
leaq 0x9942(%rip), %r9       # 0xc081
movq %rax, %rdi
pushq %r14
pushq %r15
pushq $0x400                  # imm = 0x400
pushq $0x22
callq 0x5273
addq $0x20, %rsp
movq %r14, %rdi
callq 0x2eb3
testl %eax, %eax
jne 0x280f
andl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x9928(%rip), %rcx      # 0xc0a4
leaq 0x99c7(%rip), %r8       # 0xc14a
leaq 0x9946(%rip), %r9       # 0xc0d0
movq %rbx, %rdi
pushq %r14
pushq %r15
pushq $0x400                  # imm = 0x400
pushq $0x79
callq 0x5273
addq $0x20, %rsp
movq %r14, %rdi
callq 0x2eb3
testl %eax, %eax
jne 0x280f
andl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x98e1(%rip), %rcx      # 0xc0a4
leaq 0x99e8(%rip), %r8       # 0xc1b2
leaq 0x9981(%rip), %r9       # 0xc152
movq %rbx, %rdi
pushq %r14
pushq %r15
pushq $0x400                  # imm = 0x400
pushq $0x5f
callq 0x5273
addq $0x20, %rsp
movq %r14, %rdi
callq 0x2eb3
testl %eax, %eax
jne 0x280f
movq %rbx, %rdi
callq 0x459f
xorl %edi, %edi
callq 0x23c0
movq %rax, %rbx
leaq 0x981a(%rip), %rdi      # 0xc027
jmp 0x283f
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2835
leaq 0x989c(%rip), %rdi      # 0xc0bc
xorl %eax, %eax
callq 0x5024
jmp 0x2849
movq %rax, %rbx
leaq 0x9832(%rip), %rdi      # 0xc065
jmp 0x283f
movq %rax, %rbx
leaq 0x987d(%rip), %rdi      # 0xc0bc
xorl %eax, %eax
callq 0x4e95
andl $0x0, (%rbx)
pushq $0x1
popq %rdi
callq 0x23c0