// File: /workspace/github_c_makefile_star2_O2/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 0x379f
callq 0x5330
cmpl $0x3, %ebx
jne 0x37d5
leaq 0xc88f(%rip), %rdi      # 0x1003a
pushq $0x1e
popq %rsi
pushq $0x78
popq %rdx
callq 0x729c
testq %rax, %rax
jne 0x3800
callq 0x3040
cmpl $0x0, (%rax)
jne 0x384b
leaq 0xc88f(%rip), %rdi      # 0x1005f
jmp 0x386b
movq 0x14804(%rip), %rax     # 0x17fe0
movq (%rax), %rdi
leaq 0xc81e(%rip), %rsi      # 0x10004
leaq 0xc839(%rip), %rdx      # 0x10026
leaq 0xc83c(%rip), %rcx      # 0x10030
xorl %eax, %eax
callq 0x3540
jmp 0x3be6
movq %rax, %rbx
movq 0x8(%r15), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x3c94
testl %eax, %eax
jne 0x385a
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
leaq 0xc869(%rip), %rdx      # 0x10094
movq %rbx, %rcx
callq 0x5f6c
testq %rax, %rax
jne 0x3877
callq 0x3040
cmpl $0x0, (%rax)
jne 0x38b9
leaq 0xc855(%rip), %rdi      # 0x1009e
jmp 0x386b
movq %rax, %rbx
leaq 0xc80a(%rip), %rdi      # 0x1005f
jmp 0x3bdc
callq 0x3040
cmpl $0x0, (%rax)
jne 0x38aa
leaq 0xc810(%rip), %rdi      # 0x1007b
xorl %eax, %eax
callq 0x553c
jmp 0x3be6
movq %rax, %r14
pushq $0x5
popq %rsi
movq %rax, %rdi
callq 0x60aa
movq 0x10(%r15), %rdi
callq 0x6bd4
testq %rax, %rax
jne 0x38c8
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3998
leaq 0xc820(%rip), %rdi      # 0x100c8
jmp 0x386b
movq %rax, %rbx
leaq 0xc7c7(%rip), %rdi      # 0x1007b
jmp 0x3bdc
movq %rax, %rbx
leaq 0xc7db(%rip), %rdi      # 0x1009e
jmp 0x3bdc
movq %rbx, 0x18(%rsp)
movq %r14, 0x8(%rsp)
movq %r14, %rdi
movq %rax, 0x10(%rsp)
movq %rax, %rsi
callq 0x613f
andl $0x0, 0x14e1b(%rip)     # 0x18704
leaq 0x30(%rsp), %r13
pushq $0x6
popq %rbx
leaq 0x14e0c(%rip), %r15     # 0x18704
leaq 0xc812(%rip), %r14      # 0x10111
pushq $0x1
popq %r12
xorl %ebp, %ebp
cmpq $0x1f4, %rbp            # imm = 0x1F4
je 0x39a7
movq %r13, %rdi
leaq 0xc7c7(%rip), %rsi      # 0x100e3
movq %rbp, %rdx
xorl %eax, %eax
callq 0x30a0
leaq 0xc7bd(%rip), %rdi      # 0x100ea
movq %r13, %rsi
leaq 0xc7c3(%rip), %rdx      # 0x100fa
movq %rbx, %rcx
callq 0x56c0
movq %rax, 0x70(%rsp,%rbp,8)
testq %rax, %rax
je 0x39d5
incl 0x14db5(%rip)           # 0x18708
movl $0x400, %r8d            # imm = 0x400
movq 0x8(%rsp), %rdi
movl %r12d, %esi
movq %r14, %rdx
movq %rax, %rcx
movq %r13, %r9
pushq %r15
leaq 0x2c0(%rip), %rax       # 0x3c33
pushq %rax
callq 0x6147
popq %rcx
popq %rdx
incq %rbp
testl %eax, %eax
je 0x3905
callq 0x3040
cmpl $0x0, (%rax)
jne 0x39ef
leaq 0xc786(%rip), %rdi      # 0x10119
jmp 0x386b
movq %rax, %rbx
leaq 0xc726(%rip), %rdi      # 0x100c8
jmp 0x3bdc
leaq 0x14d56(%rip), %rdi     # 0x18704
callq 0x4243
testl %eax, %eax
jne 0x3bbc
xorl %ebx, %ebx
cmpq $0x1f4, %rbx            # imm = 0x1F4
je 0x39fe
movq 0x70(%rsp,%rbx,8), %rdi
callq 0x3460
incq %rbx
jmp 0x39bd
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3a92
leaq 0xc717(%rip), %rdi      # 0x10101
jmp 0x386b
movq %rax, %rbx
leaq 0xc720(%rip), %rdi      # 0x10119
jmp 0x3bdc
andl $0x0, 0x14cff(%rip)     # 0x18704
leaq 0xc6d7(%rip), %rbx      # 0x100e3
leaq 0x30(%rsp), %r14
leaq 0xc6d2(%rip), %r15      # 0x100ea
leaq 0xc73d(%rip), %r13      # 0x1015c
pushq $0x1
popq %rbp
xorl %r12d, %r12d
cmpq $0x1f4, %r12            # imm = 0x1F4
je 0x3aa1
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x30a0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5bd5
movq %rax, 0x70(%rsp,%r12,8)
testq %rax, %rax
je 0x3acf
incl 0x14caf(%rip)           # 0x18708
movl $0x400, %r8d            # imm = 0x400
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %rax, %rcx
movq %r14, %r9
leaq 0x14c8e(%rip), %rax     # 0x18704
pushq %rax
leaq 0x1b5(%rip), %rax       # 0x3c33
pushq %rax
callq 0x6147
popq %rcx
popq %rdx
incq %r12
testl %eax, %eax
je 0x3a25
jmp 0x3982
movq %rax, %rbx
leaq 0xc665(%rip), %rdi      # 0x10101
jmp 0x3bdc
leaq 0x14c5c(%rip), %rdi     # 0x18704
callq 0x4243
testl %eax, %eax
jne 0x3bbc
xorl %ebx, %ebx
cmpq $0x1f4, %rbx            # imm = 0x1F4
je 0x3ae9
movq 0x70(%rsp,%rbx,8), %rdi
callq 0x3460
incq %rbx
jmp 0x3ab7
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3b81
leaq 0xc668(%rip), %rdi      # 0x1014c
jmp 0x386b
andl $0x0, 0x14c14(%rip)     # 0x18704
leaq 0xc5ec(%rip), %rbx      # 0x100e3
leaq 0x30(%rsp), %r14
leaq 0xc5e7(%rip), %r15      # 0x100ea
leaq 0xc66d(%rip), %r13      # 0x10177
pushq $0x1
popq %rbp
xorl %r12d, %r12d
cmpq $0x1f4, %r12            # imm = 0x1F4
je 0x3b8d
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x30a0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5d9d
movq %rax, 0x70(%rsp,%r12,8)
testq %rax, %rax
je 0x3bee
incl 0x14bc0(%rip)           # 0x18708
movl $0x400, %r8d            # imm = 0x400
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %rax, %rcx
movq %r14, %r9
leaq 0x14b9f(%rip), %rax     # 0x18704
pushq %rax
leaq 0xc6(%rip), %rax        # 0x3c33
pushq %rax
callq 0x6147
popq %rcx
popq %rdx
incq %r12
testl %eax, %eax
je 0x3b10
jmp 0x3982
movq %rax, %rbx
leaq 0xc5c1(%rip), %rdi      # 0x1014c
jmp 0x3bdc
leaq 0x14b70(%rip), %rdi     # 0x18704
callq 0x4243
testl %eax, %eax
jne 0x3bbc
xorl %ebx, %ebx
movq 0x8(%rsp), %r14
cmpq $0x1f4, %rbx            # imm = 0x1F4
je 0x3c04
movq 0x70(%rsp,%rbx,8), %rdi
callq 0x3460
incq %rbx
jmp 0x3ba4
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3bd2
leaq 0xc56b(%rip), %rdi      # 0x10138
jmp 0x386b
movq %rax, %rbx
leaq 0xc55c(%rip), %rdi      # 0x10138
xorl %eax, %eax
callq 0x53ad
andl $0x0, (%rbx)
pushq $0x1
popq %rdi
callq 0x3480
callq 0x3040
cmpl $0x0, (%rax)
jne 0x3c27
leaq 0xc565(%rip), %rdi      # 0x10164
jmp 0x386b
movq %r14, %rdi
callq 0x62e8
movq 0x10(%rsp), %rdi
callq 0x722d
movq 0x18(%rsp), %rdi
callq 0x797d
xorl %edi, %edi
callq 0x3480
movq %rax, %rbx
leaq 0xc533(%rip), %rdi      # 0x10164
jmp 0x3bdc