// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1040, %rsp           # imm = 0x1040
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x37af
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x6620
jmp 0x37b1
cmpl $0x3, -0x8(%rbp)
je 0x37e7
movq 0x22822(%rip), %rax     # 0x25fe0
movq (%rax), %rdi
leaq 0x1a83c(%rip), %rsi     # 0x1e004
leaq 0x1a857(%rip), %rdx     # 0x1e026
leaq 0x1a85a(%rip), %rcx     # 0x1e030
movb $0x0, %al
callq 0x3530
movl $0x1, %edi
callq 0x3480
leaq 0x1a84c(%rip), %rdi     # 0x1e03a
movl $0x1e, %esi
movl $0x78, %edx
callq 0xa320
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x3848
jmp 0x3809
callq 0x3040
cmpl $0x0, (%rax)
je 0x382e
leaq 0x1a845(%rip), %rdi     # 0x1e05f
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x383c
leaq 0x1a82a(%rip), %rdi     # 0x1e05f
movb $0x0, %al
callq 0x6930
jmp 0x383e
movl $0x1, %edi
callq 0x3480
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x18(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0x4020
cmpl $0x0, %eax
je 0x38a3
jmp 0x3864
callq 0x3040
cmpl $0x0, (%rax)
je 0x3889
leaq 0x1a806(%rip), %rdi     # 0x1e07b
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3897
leaq 0x1a7eb(%rip), %rdi     # 0x1e07b
movb $0x0, %al
callq 0x6930
jmp 0x3899
movl $0x1, %edi
callq 0x3480
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rcx
leaq 0x1a7de(%rip), %rdx     # 0x1e094
callq 0x81f0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x3906
jmp 0x38c7
callq 0x3040
cmpl $0x0, (%rax)
je 0x38ec
leaq 0x1a7c6(%rip), %rdi     # 0x1e09e
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x38fa
leaq 0x1a7ab(%rip), %rdi     # 0x1e09e
movb $0x0, %al
callq 0x6930
jmp 0x38fc
movl $0x1, %edi
callq 0x3480
movq -0x38(%rbp), %rdi
movl $0x5, %esi
callq 0x83d0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x99b0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x396c
jmp 0x392d
callq 0x3040
cmpl $0x0, (%rax)
je 0x3952
leaq 0x1a78a(%rip), %rdi     # 0x1e0c8
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3960
leaq 0x1a76f(%rip), %rdi     # 0x1e0c8
movb $0x0, %al
callq 0x6930
jmp 0x3962
movl $0x1, %edi
callq 0x3480
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x85a0
movl $0x0, 0x22d81(%rip)     # 0x26704
movq $0x0, -0x1028(%rbp)
cmpq $0x1f4, -0x1028(%rbp) # imm = 0x1F4
jae 0x3ae6
leaq -0x1020(%rbp), %rdi
movq -0x1028(%rbp), %rdx
leaq 0x1a72f(%rip), %rsi     # 0x1e0e3
movb $0x0, %al
callq 0x30b0
leaq -0x1020(%rbp), %rsi
leaq 0x1a721(%rip), %rdi     # 0x1e0ea
leaq 0x1a72a(%rip), %rdx     # 0x1e0fa
movl $0x6, %ecx
callq 0x6b70
movq -0x1028(%rbp), %rcx
movq %rax, -0xfe0(%rbp,%rcx,8)
cmpq $0x0, %rax
jne 0x3a30
jmp 0x39f1
callq 0x3040
cmpl $0x0, (%rax)
je 0x3a16
leaq 0x1a6ff(%rip), %rdi     # 0x1e101
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3a24
leaq 0x1a6e4(%rip), %rdi     # 0x1e101
movb $0x0, %al
callq 0x6930
jmp 0x3a26
movl $0x1, %edi
callq 0x3480
movl 0x22cd2(%rip), %eax     # 0x26708
addl $0x1, %eax
movl %eax, 0x22cc9(%rip)     # 0x26708
movq -0x38(%rbp), %rdi
movq -0x1028(%rbp), %rax
movq -0xfe0(%rbp,%rax,8), %rcx
leaq -0x1020(%rbp), %r9
movl $0x1, %esi
leaq 0x1a6ac(%rip), %rdx     # 0x1e111
movl $0x400, %r8d            # imm = 0x400
leaq 0x50e(%rip), %r10       # 0x3f80
leaq 0x22c8b(%rip), %rax     # 0x26704
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x85c0
cmpl $0x0, %eax
je 0x3acd
jmp 0x3a8e
callq 0x3040
cmpl $0x0, (%rax)
je 0x3ab3
leaq 0x1a67a(%rip), %rdi     # 0x1e119
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3ac1
leaq 0x1a65f(%rip), %rdi     # 0x1e119
movb $0x0, %al
callq 0x6930
jmp 0x3ac3
movl $0x1, %edi
callq 0x3480
jmp 0x3acf
movq -0x1028(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1028(%rbp)
jmp 0x398e
leaq 0x22c17(%rip), %rdi     # 0x26704
callq 0x46d0
cmpl $0x0, %eax
je 0x3b38
jmp 0x3af9
callq 0x3040
cmpl $0x0, (%rax)
je 0x3b1e
leaq 0x1a62e(%rip), %rdi     # 0x1e138
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3b2c
leaq 0x1a613(%rip), %rdi     # 0x1e138
movb $0x0, %al
callq 0x6930
jmp 0x3b2e
movl $0x1, %edi
callq 0x3480
movq $0x0, -0x1028(%rbp)
cmpq $0x1f4, -0x1028(%rbp) # imm = 0x1F4
jae 0x3b78
movq -0x1028(%rbp), %rax
movq -0xfe0(%rbp,%rax,8), %rdi
callq 0x3460
movq -0x1028(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1028(%rbp)
jmp 0x3b43
movl $0x0, 0x22b82(%rip)     # 0x26704
movq $0x0, -0x1028(%rbp)
cmpq $0x1f4, -0x1028(%rbp) # imm = 0x1F4
jae 0x3cd9
leaq -0x1020(%rbp), %rdi
movq -0x1028(%rbp), %rdx
leaq 0x1a530(%rip), %rsi     # 0x1e0e3
movb $0x0, %al
callq 0x30b0
leaq -0x1020(%rbp), %rsi
leaq 0x1a522(%rip), %rdi     # 0x1e0ea
callq 0x7910
movq -0x1028(%rbp), %rcx
movq %rax, -0xfe0(%rbp,%rcx,8)
cmpq $0x0, %rax
jne 0x3c23
jmp 0x3be4
callq 0x3040
cmpl $0x0, (%rax)
je 0x3c09
leaq 0x1a557(%rip), %rdi     # 0x1e14c
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3c17
leaq 0x1a53c(%rip), %rdi     # 0x1e14c
movb $0x0, %al
callq 0x6930
jmp 0x3c19
movl $0x1, %edi
callq 0x3480
movl 0x22adf(%rip), %eax     # 0x26708
addl $0x1, %eax
movl %eax, 0x22ad6(%rip)     # 0x26708
movq -0x38(%rbp), %rdi
movq -0x1028(%rbp), %rax
movq -0xfe0(%rbp,%rax,8), %rcx
leaq -0x1020(%rbp), %r9
movl $0x1, %esi
leaq 0x1a504(%rip), %rdx     # 0x1e15c
movl $0x400, %r8d            # imm = 0x400
leaq 0x31b(%rip), %r10       # 0x3f80
leaq 0x22a98(%rip), %rax     # 0x26704
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x85c0
cmpl $0x0, %eax
je 0x3cc0
jmp 0x3c81
callq 0x3040
cmpl $0x0, (%rax)
je 0x3ca6
leaq 0x1a487(%rip), %rdi     # 0x1e119
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3cb4
leaq 0x1a46c(%rip), %rdi     # 0x1e119
movb $0x0, %al
callq 0x6930
jmp 0x3cb6
movl $0x1, %edi
callq 0x3480
jmp 0x3cc2
movq -0x1028(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1028(%rbp)
jmp 0x3b8d
leaq 0x22a24(%rip), %rdi     # 0x26704
callq 0x46d0
cmpl $0x0, %eax
je 0x3d2b
jmp 0x3cec
callq 0x3040
cmpl $0x0, (%rax)
je 0x3d11
leaq 0x1a43b(%rip), %rdi     # 0x1e138
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3d1f
leaq 0x1a420(%rip), %rdi     # 0x1e138
movb $0x0, %al
callq 0x6930
jmp 0x3d21
movl $0x1, %edi
callq 0x3480
movq $0x0, -0x1028(%rbp)
cmpq $0x1f4, -0x1028(%rbp) # imm = 0x1F4
jae 0x3d6b
movq -0x1028(%rbp), %rax
movq -0xfe0(%rbp,%rax,8), %rdi
callq 0x3460
movq -0x1028(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1028(%rbp)
jmp 0x3d36
movl $0x0, 0x2298f(%rip)     # 0x26704
movq $0x0, -0x1028(%rbp)
cmpq $0x1f4, -0x1028(%rbp) # imm = 0x1F4
jae 0x3ecc
leaq -0x1020(%rbp), %rdi
movq -0x1028(%rbp), %rdx
leaq 0x1a33d(%rip), %rsi     # 0x1e0e3
movb $0x0, %al
callq 0x30b0
leaq -0x1020(%rbp), %rsi
leaq 0x1a32f(%rip), %rdi     # 0x1e0ea
callq 0x7df0
movq -0x1028(%rbp), %rcx
movq %rax, -0xfe0(%rbp,%rcx,8)
cmpq $0x0, %rax
jne 0x3e16
jmp 0x3dd7
callq 0x3040
cmpl $0x0, (%rax)
je 0x3dfc
leaq 0x1a37c(%rip), %rdi     # 0x1e164
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3e0a
leaq 0x1a361(%rip), %rdi     # 0x1e164
movb $0x0, %al
callq 0x6930
jmp 0x3e0c
movl $0x1, %edi
callq 0x3480
movl 0x228ec(%rip), %eax     # 0x26708
addl $0x1, %eax
movl %eax, 0x228e3(%rip)     # 0x26708
movq -0x38(%rbp), %rdi
movq -0x1028(%rbp), %rax
movq -0xfe0(%rbp,%rax,8), %rcx
leaq -0x1020(%rbp), %r9
movl $0x1, %esi
leaq 0x1a32c(%rip), %rdx     # 0x1e177
movl $0x400, %r8d            # imm = 0x400
leaq 0x128(%rip), %r10       # 0x3f80
leaq 0x228a5(%rip), %rax     # 0x26704
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x85c0
cmpl $0x0, %eax
je 0x3eb3
jmp 0x3e74
callq 0x3040
cmpl $0x0, (%rax)
je 0x3e99
leaq 0x1a294(%rip), %rdi     # 0x1e119
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3ea7
leaq 0x1a279(%rip), %rdi     # 0x1e119
movb $0x0, %al
callq 0x6930
jmp 0x3ea9
movl $0x1, %edi
callq 0x3480
jmp 0x3eb5
movq -0x1028(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1028(%rbp)
jmp 0x3d80
leaq 0x22831(%rip), %rdi     # 0x26704
callq 0x46d0
cmpl $0x0, %eax
je 0x3f1e
jmp 0x3edf
callq 0x3040
cmpl $0x0, (%rax)
je 0x3f04
leaq 0x1a248(%rip), %rdi     # 0x1e138
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x3f12
leaq 0x1a22d(%rip), %rdi     # 0x1e138
movb $0x0, %al
callq 0x6930
jmp 0x3f14
movl $0x1, %edi
callq 0x3480
movq $0x0, -0x1028(%rbp)
cmpq $0x1f4, -0x1028(%rbp) # imm = 0x1F4
jae 0x3f5e
movq -0x1028(%rbp), %rax
movq -0xfe0(%rbp,%rax,8), %rdi
callq 0x3460
movq -0x1028(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1028(%rbp)
jmp 0x3f29
movq -0x38(%rbp), %rdi
callq 0x8870
movq -0x30(%rbp), %rdi
callq 0xa280
movq -0x28(%rbp), %rdi
callq 0xadc0
xorl %edi, %edi
callq 0x3480