// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/perftests/dynamodb_queue/main.c
// Function: main
int
main(int argc, char * argv[])
{
	char * key_id;
	char * key_secret;
	struct serverpool * SP;
	struct logging_file * F;
	struct dynamodb_request_queue * Q;
	char * bodies[500];
	char keyname[50];
	size_t i;

	WARNP_INIT;

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

	/* Resolve target addresses. */
	if ((SP = serverpool_create("dynamodb.us-east-1.amazonaws.com:443",
	    30, 120)) == NULL) {
		warnp("Error launching DNS lookups");
		exit(1);
	}

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

	/* Create a request queue. */
	if ((Q = dynamodb_request_queue_init(key_id, key_secret, "us-east-1",
	    SP)) == NULL) {
		warnp("Error initializing DynamoDB request queue");
		exit(1);
	}
	dynamodb_request_queue_setcapacity(Q, 5);

	/* Log requests. */
	if ((F = logging_open(argv[2])) == NULL) {
		warnp("Error initializing logging");
		exit(1);
	}
	dynamodb_request_queue_log(Q, F);

	/* Send PutItem requests. */
	done = 0;
	for (i = 0; i < 500; i++) {
		sprintf(keyname, "key%zu", i);
		if ((bodies[i] = dynamodb_kv_put("kivaloo-testing", keyname,
		    (const uint8_t *)"value\n", 6)) == NULL) {
			warnp("dynamodb_kv_put");
			exit(1);
		}
		inprogress++;
		if (dynamodb_request_queue(Q, 1, "PutItem", bodies[i], 1024,
		    keyname, donereq, &done)) {
			warnp("Error queuing DynamoDB request");
			exit(1);
		}
	}

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

	/* Free requests. */
	for (i = 0; i < 500; i++)
		free(bodies[i]);

	/* Send GetItem requests. */
	done = 0;
	for (i = 0; i < 500; i++) {
		sprintf(keyname, "key%zu", i);
		if ((bodies[i] =
		    dynamodb_kv_get("kivaloo-testing", keyname)) == NULL) {
			warnp("dynamodb_kv_get");
			exit(1);
		}
		inprogress++;
		if (dynamodb_request_queue(Q, 1, "GetItem", bodies[i], 1024,
		    keyname, donereq, &done)) {
			warnp("Error queuing DynamoDB request");
			exit(1);
		}
	}

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

	/* Free requests. */
	for (i = 0; i < 500; i++)
		free(bodies[i]);

	/* Send DeleteItem requests. */
	done = 0;
	for (i = 0; i < 500; i++) {
		sprintf(keyname, "key%zu", i);
		if ((bodies[i] =
		    dynamodb_kv_delete("kivaloo-testing", keyname)) == NULL) {
			warnp("dynamodb_kv_delete");
			exit(1);
		}
		inprogress++;
		if (dynamodb_request_queue(Q, 1, "DeleteItem", bodies[i], 1024,
		    keyname, donereq, &done)) {
			warnp("Error queuing DynamoDB request");
			exit(1);
		}
	}

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

	/* Free requests. */
	for (i = 0; i < 500; i++)
		free(bodies[i]);

	/* Shut down request queue. */
	dynamodb_request_queue_free(Q);

	/* Close log file. */
	logging_close(F);

	/* Shut down the DNS lookups. */
	serverpool_free(SP);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movq %rsi, %r15
movl %edi, %ebx
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x38af
callq 0x570c
cmpl $0x3, %ebx
jne 0x38e9
leaq 0xd77f(%rip), %rdi      # 0x1103a
movl $0x78, %edx
movl $0x1e, %esi
callq 0x7874
testq %rax, %rax
jne 0x3914
callq 0x3040
cmpl $0x0, (%rax)
jne 0x395f
leaq 0xd77b(%rip), %rdi      # 0x1105f
jmp 0x397f
movq 0x146f0(%rip), %rax     # 0x17fe0
movq (%rax), %rdi
leaq 0xd70a(%rip), %rsi      # 0x11004
leaq 0xd725(%rip), %rdx      # 0x11026
leaq 0xd728(%rip), %rcx      # 0x11030
xorl %eax, %eax
callq 0x3530
jmp 0x3d18
movq %rax, %rbx
movq 0x8(%r15), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x3dac
testl %eax, %eax
jne 0x396e
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
leaq 0xd755(%rip), %rdx      # 0x11094
movq %rbx, %rcx
callq 0x6428
testq %rax, %rax
jne 0x398b
callq 0x3040
cmpl $0x0, (%rax)
jne 0x39cf
leaq 0xd741(%rip), %rdi      # 0x1109e
jmp 0x397f
movq %rax, %rbx
leaq 0xd6f6(%rip), %rdi      # 0x1105f
jmp 0x3d0b
callq 0x3040
cmpl $0x0, (%rax)
jne 0x39c0
leaq 0xd6fc(%rip), %rdi      # 0x1107b
xorl %eax, %eax
callq 0x58ab
jmp 0x3d18
movq %rax, %r14
movl $0x5, %esi
movq %rax, %rdi
callq 0x6583
movq 0x10(%r15), %rdi
callq 0x7174
testq %rax, %rax
jne 0x39de
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3c76
leaq 0xd70a(%rip), %rdi      # 0x110c8
jmp 0x397f
movq %rax, %rbx
leaq 0xd6b1(%rip), %rdi      # 0x1107b
jmp 0x3d0b
movq %rax, %rbx
leaq 0xd6c5(%rip), %rdi      # 0x1109e
jmp 0x3d0b
movq %rbx, 0x18(%rsp)
movq %r14, 0x8(%rsp)
movq %r14, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rsi
callq 0x6633
movl $0x0, 0x14d02(%rip)     # 0x18704
leaq 0x30(%rsp), %r13
leaq 0xd6dc(%rip), %rbp      # 0x110ea
leaq 0xd6e5(%rip), %r15      # 0x110fa
leaq 0x14ce8(%rip), %r12     # 0x18704
leaq 0xd6ee(%rip), %rbx      # 0x11111
xorl %r14d, %r14d
movq %r13, %rdi
leaq 0xd6b3(%rip), %rsi      # 0x110e3
movq %r14, %rdx
xorl %eax, %eax
callq 0x30a0
movl $0x6, %ecx
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x59d0
movq %rax, 0x70(%rsp,%r14,8)
testq %rax, %rax
je 0x3c9b
incl 0x14ca7(%rip)           # 0x18708
movl $0x400, %r8d            # imm = 0x400
movq 0x8(%rsp), %rdi
movl $0x1, %esi
movq %rbx, %rdx
movq %rax, %rcx
movq %r13, %r9
pushq %r12
leaq 0x2c1(%rip), %rax       # 0x3d44
pushq %rax
callq 0x663b
addq $0x10, %rsp
testl %eax, %eax
jne 0x3c85
incq %r14
cmpq $0x1f4, %r14            # imm = 0x1F4
jne 0x3a26
leaq 0x14c5c(%rip), %r12     # 0x18704
movq %r12, %rdi
callq 0x434d
testl %eax, %eax
jne 0x3cbd
xorl %ebx, %ebx
movq 0x70(%rsp,%rbx,8), %rdi
callq 0x3450
incq %rbx
cmpq $0x1f4, %rbx            # imm = 0x1F4
jne 0x3aba
movl $0x0, 0x14c2a(%rip)     # 0x18704
leaq 0xd602(%rip), %rbx      # 0x110e3
leaq 0x30(%rsp), %r14
leaq 0xd5fd(%rip), %r15      # 0x110ea
leaq 0xd668(%rip), %r13      # 0x1115c
xorl %ebp, %ebp
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x30a0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5fb8
movq %rax, 0x70(%rsp,%rbp,8)
testq %rax, %rax
je 0x3ceb
incl 0x14be3(%rip)           # 0x18708
movl $0x400, %r8d            # imm = 0x400
movq 0x8(%rsp), %rdi
movl $0x1, %esi
movq %r13, %rdx
movq %rax, %rcx
movq %r14, %r9
pushq %r12
leaq 0x1fd(%rip), %rax       # 0x3d44
pushq %rax
callq 0x663b
addq $0x10, %rsp
testl %eax, %eax
jne 0x3c85
incq %rbp
cmpq $0x1f4, %rbp            # imm = 0x1F4
jne 0x3af6
leaq 0x14b98(%rip), %r12     # 0x18704
movq %r12, %rdi
callq 0x434d
testl %eax, %eax
jne 0x3cbd
xorl %ebx, %ebx
movq 0x70(%rsp,%rbx,8), %rdi
callq 0x3450
incq %rbx
cmpq $0x1f4, %rbx            # imm = 0x1F4
jne 0x3b7e
movl $0x0, 0x14b66(%rip)     # 0x18704
leaq 0xd53e(%rip), %rbx      # 0x110e3
leaq 0x30(%rsp), %r14
leaq 0xd539(%rip), %r15      # 0x110ea
leaq 0xd5bf(%rip), %r13      # 0x11177
xorl %ebp, %ebp
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x30a0
movq %r15, %rdi
movq %r14, %rsi
callq 0x61ee
movq %rax, 0x70(%rsp,%rbp,8)
testq %rax, %rax
je 0x3d22
incl 0x14b1f(%rip)           # 0x18708
movl $0x400, %r8d            # imm = 0x400
movq 0x8(%rsp), %rdi
movl $0x1, %esi
movq %r13, %rdx
movq %rax, %rcx
movq %r14, %r9
pushq %r12
leaq 0x139(%rip), %rax       # 0x3d44
pushq %rax
callq 0x663b
addq $0x10, %rsp
testl %eax, %eax
jne 0x3c85
incq %rbp
cmpq $0x1f4, %rbp            # imm = 0x1F4
jne 0x3bba
leaq 0x14ad8(%rip), %rdi     # 0x18704
callq 0x434d
testl %eax, %eax
jne 0x3cbd
xorl %ebx, %ebx
movq 0x70(%rsp,%rbx,8), %rdi
callq 0x3450
incq %rbx
cmpq $0x1f4, %rbx            # imm = 0x1F4
jne 0x3c3b
movq 0x8(%rsp), %rdi
callq 0x67e1
movq 0x10(%rsp), %rdi
callq 0x7805
movq 0x18(%rsp), %rdi
callq 0x7ffb
xorl %edi, %edi
callq 0x3470
movq %rax, %rbx
leaq 0xd448(%rip), %rdi      # 0x110c8
jmp 0x3d0b
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3cb1
leaq 0xd483(%rip), %rdi      # 0x11119
jmp 0x397f
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3cd3
leaq 0xd455(%rip), %rdi      # 0x11101
jmp 0x397f
movq %rax, %rbx
leaq 0xd45e(%rip), %rdi      # 0x11119
jmp 0x3d0b
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3cdf
leaq 0xd46a(%rip), %rdi      # 0x11138
jmp 0x397f
movq %rax, %rbx
leaq 0xd424(%rip), %rdi      # 0x11101
jmp 0x3d0b
movq %rax, %rbx
leaq 0xd44f(%rip), %rdi      # 0x11138
jmp 0x3d0b
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3d01
leaq 0xd450(%rip), %rdi      # 0x1114c
jmp 0x397f
movq %rax, %rbx
leaq 0xd441(%rip), %rdi      # 0x1114c
xorl %eax, %eax
callq 0x578c
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x3470
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3d38
leaq 0xd431(%rip), %rdi      # 0x11164
jmp 0x397f
movq %rax, %rbx
leaq 0xd422(%rip), %rdi      # 0x11164
jmp 0x3d0b