// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/lbs-dynamodb-init/main.c
// Function: main
int
main(int argc, char * argv[])
{

	/* Command-line parameters. */
	size_t opt_b = 0;
	char * opt_k = NULL;
	char * opt_m = NULL;
	char * opt_r = NULL;
	char * opt_t = NULL;

	/* Working variables. */
	char * dynamodb_host;
	char * key_id;
	char * key_secret;
	struct sock_addr ** sas_ddb;
	const char * ch;
	uint8_t tableid[32];

	WARNP_INIT;

	/* Parse the command line. */
	while ((ch = GETOPT(argc, argv)) != NULL) {
		GETOPT_SWITCH(ch) {
		GETOPT_OPTARG("-b"):
			if (opt_b != 0)
				usage();
			if (PARSENUM(&opt_b, optarg, 512, 8192))
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-k"):
			if (opt_k != NULL)
				usage();
			if ((opt_k = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-m"):
			if (opt_m != NULL)
				usage();
			if ((opt_m = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-r"):
			if (opt_r != NULL)
				usage();
			if ((opt_r = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPTARG("-t"):
			if (opt_t != NULL)
				usage();
			if ((opt_t = strdup(optarg)) == NULL)
				OPT_EPARSE(ch, optarg);
			break;
		GETOPT_OPT("--version"):
			fprintf(stderr, "kivaloo-lbs-dynamodb-init @VERSION@\n");
			exit(0);
		GETOPT_MISSING_ARG:
			warn0("Missing argument to %s", ch);
			usage();
		GETOPT_DEFAULT:
			warn0("illegal option -- %s", ch);
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	/* We should have processed all the arguments. */
	if (argc != 0)
		usage();
	(void)argv; /* argv is not used beyond this point. */

	/* Sanity-check options. */
	if (opt_b == 0)
		usage();
	if (opt_k == NULL)
		usage();
	if (opt_m == NULL)
		usage();
	if (opt_r == NULL)
		usage();
	if (opt_t == NULL)
		usage();

	/* Warn about poor choices of block sizes. */
	if (opt_b % 1024) {
		warn0("DynamoDB item size is unlikely to be optimal: %zu",
		    opt_b);
	}

	/* Construct the DynamoDB endpoint host name. */
	if (asprintf(&dynamodb_host, "dynamodb.%s.amazonaws.com:443",
	    opt_r) == -1) {
		warnp("asprintf");
		exit(1);
	}

	/* Resolve the DynamoDB endpoint. */
	if ((sas_ddb = sock_resolve(dynamodb_host)) == NULL) {
		warnp("Error resolving DynamoDB host: %s", dynamodb_host);
		exit(1);
	}

	/* Read the key file. */
	if (aws_readkeys(opt_k, &key_id, &key_secret)) {
		warnp("Error reading AWS keys from %s", opt_k);
		exit(1);
	}

	/* Create the data and metadata tables. */
	if (createtable(key_id, key_secret, opt_r, sas_ddb, opt_t)) {
		warnp("Failed to create DynamoDB table: %s", opt_t);
		exit(1);
	}
	if (createtable(key_id, key_secret, opt_r, sas_ddb, opt_m)) {
		warnp("Failed to create DynamoDB table: %s", opt_m);
		exit(1);
	}

	/* Generate a random table ID. */
	if (entropy_read(tableid, 32)) {
		warnp("Error generating table ID");
		exit(1);
	}

	/* Record the table ID in the data table. */
	if (storetableid(key_id, key_secret, opt_r, sas_ddb, opt_t, tableid)) {
		warnp("Failed to store table ID");
		exit(1);
	}

	/* Store a metadata blob in the metadata table. */
	if (createmetadata(key_id, key_secret, opt_r, sas_ddb, opt_m,
	    opt_b, tableid)) {
		warnp("Failed to store metadata");
		exit(1);
	}

	/* Free the address structures. */
	sock_addr_freelist(sas_ddb);

	/* Free string allocated by asprintf. */
	free(dynamodb_host);

	/* Free key strings. */
	free(key_id);
	insecure_memzero(key_secret, strlen(key_secret));
	free(key_secret);

	/* Free option strings. */
	free(opt_k);
	free(opt_m);
	free(opt_r);
	free(opt_t);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r12
movl %edi, %ebx
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x26cf
callq 0x6a34
movq $0x0, 0x28(%rsp)
leaq 0x24071(%rip), %r14     # 0x26750
pushq $0x1
popq %r15
movq $0x0, 0x8(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq %r12, 0x58(%rsp)
leaq 0xb91e(%rip), %r13      # 0xe031
movl %ebx, %edi
movq %r12, %rsi
callq 0x4d68
testq %rax, %rax
je 0x2a48
movq %rax, %rbp
movq $0x14d, (%rsp)          # imm = 0x14D
movq (%rsp), %rax
decq %rax
movq %rax, 0x50(%rsp)
movl $0x0, 0x44(%rsp)
cmpl $0x0, (%r14)
je 0x2759
movq %rbp, %rdi
callq 0x517d
addq (%rsp), %rax
jmp 0x2767
movq 0x50(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x50(%rsp)
cmpq $0x14e, %rax            # imm = 0x14E
je 0x2850
cmpq $0x154, %rax            # imm = 0x154
je 0x28a1
cmpq $0x15a, %rax            # imm = 0x15A
je 0x2885
cmpq $0x160, %rax            # imm = 0x160
je 0x27ef
cmpq $0x166, %rax            # imm = 0x166
je 0x2834
cmpq $0x16c, %rax            # imm = 0x16C
je 0x280e
cmpq $0x16f, %rax            # imm = 0x16F
je 0x2868
cmpq $0x172, %rax            # imm = 0x172
je 0x28c8
cmpl $0x0, (%r14)
jne 0x2dc3
cmpl $0x0, 0x44(%rsp)
jne 0x2745
movl $0x172, %edi            # imm = 0x172
subq (%rsp), %rdi
callq 0x54ea
movl $0x1, 0x44(%rsp)
jmp 0x2745
cmpl $0x0, (%r14)
jne 0x2905
movl $0x160, %esi            # imm = 0x160
subq (%rsp), %rsi
leaq 0xb84f(%rip), %rdi      # 0xe058
jmp 0x28bb
cmpl $0x0, (%r14)
jne 0x2dea
movl $0x16c, %esi            # imm = 0x16C
subq (%rsp), %rsi
leaq 0xb836(%rip), %rdi      # 0xe05e
xorl %edx, %edx
callq 0x5295
jmp 0x2745
cmpl $0x0, (%r14)
jne 0x28d4
movl $0x166, %esi            # imm = 0x166
subq (%rsp), %rsi
leaq 0xb80d(%rip), %rdi      # 0xe05b
jmp 0x28bb
cmpl $0x0, (%r14)
jne 0x299b
movl $0x14e, %esi            # imm = 0x14E
subq (%rsp), %rsi
movq %r13, %rdi
jmp 0x28bb
cmpl $0x0, (%r14)
jne 0x2dcc
movl $0x16f, %edi            # imm = 0x16F
subq (%rsp), %rdi
callq 0x545f
jmp 0x2745
cmpl $0x0, (%r14)
jne 0x2933
movl $0x15a, %esi            # imm = 0x15A
subq (%rsp), %rsi
leaq 0xb7b6(%rip), %rdi      # 0xe055
jmp 0x28bb
cmpl $0x0, (%r14)
jne 0x2961
movl $0x154, %esi            # imm = 0x154
subq (%rsp), %rsi
leaq 0xb797(%rip), %rdi      # 0xe052
movl %r15d, %edx
callq 0x5295
jmp 0x2745
movl $0x1, (%r14)
jmp 0x2713
leaq 0x23e6d(%rip), %rax     # 0x26748
movq (%rax), %r13
testq %r13, %r13
je 0x2e6b
cmpq $0x0, 0x18(%rsp)
jne 0x2e0b
movq %r13, %rdi
callq 0x2530
movq %rax, 0x18(%rsp)
jmp 0x298d
leaq 0x23e3c(%rip), %rax     # 0x26748
movq (%rax), %r13
testq %r13, %r13
je 0x2e8a
cmpq $0x0, 0x30(%rsp)
jne 0x2e0b
movq %r13, %rdi
callq 0x2530
movq %rax, 0x30(%rsp)
jmp 0x298d
leaq 0x23e0e(%rip), %rax     # 0x26748
movq (%rax), %r13
testq %r13, %r13
je 0x2ec8
cmpq $0x0, 0x8(%rsp)
jne 0x2e0b
movq %r13, %rdi
callq 0x2530
movq %rax, 0x8(%rsp)
jmp 0x298d
leaq 0x23de0(%rip), %rax     # 0x26748
movq (%rax), %r13
testq %r13, %r13
je 0x2ea9
cmpq $0x0, 0x28(%rsp)
jne 0x2e0b
movq %r13, %rdi
callq 0x2530
movq %rax, 0x28(%rsp)
testq %rax, %rax
jne 0x270c
jmp 0x2e10
movl %ebx, %r12d
leaq 0x23da3(%rip), %rax     # 0x26748
movq (%rax), %rbx
testq %rbx, %rbx
je 0x2e4c
cmpq $0x0, 0x10(%rsp)
jne 0x2e0b
callq 0x2040
movq %rax, %r13
andl $0x0, (%rax)
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
xorl %edx, %edx
callq 0x22e0
movq %rax, 0x10(%rsp)
movq 0x80(%rsp), %rcx
pushq $0x16
popq %rax
cmpq %rbx, %rcx
je 0x2a0c
cmpb $0x0, (%rcx)
jne 0x2a0c
movq 0x10(%rsp), %rax
leaq -0x2001(%rax), %rcx
pushq $0x22
popq %rax
cmpq $-0x1e02, %rcx          # imm = 0xE1FE
ja 0x2a10
movl %eax, (%r13)
cmpl $0x0, (%r13)
movl %r12d, %ebx
movq 0x58(%rsp), %r12
je 0x270c
leaq 0x23d1e(%rip), %rax     # 0x26748
movq (%rax), %rdx
leaq 0xb600(%rip), %rdi      # 0xe034
movq %rbp, %rsi
xorl %eax, %eax
callq 0x6ab1
andl $0x0, (%r13)
jmp 0x2dbb
leaq 0x13b29(%rip), %rax     # 0x16578
cmpl %ebx, (%rax)
jne 0x2e0b
cmpq $0x0, 0x10(%rsp)
movq 0x28(%rsp), %rbp
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %r15
je 0x2e0b
testq %rbp, %rbp
je 0x2e0b
cmpq $0x0, 0x8(%rsp)
je 0x2e0b
testq %r15, %r15
je 0x2e0b
testq %r14, %r14
je 0x2e0b
movq 0x10(%rsp), %rax
shlq $0x36, %rax
je 0x2abf
leaq 0xb60e(%rip), %rdi      # 0xe0b9
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x6c40
callq 0x2040
andl $0x0, (%rax)
leaq 0xb625(%rip), %rsi      # 0xe0eb
leaq 0x48(%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x49e0
cmpl $-0x1, %eax
je 0x2ee7
movq 0x48(%rsp), %rdi
callq 0x5bbc
testq %rax, %rax
je 0x2f01
movq %rax, %rbx
leaq 0x38(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %rbp, %rdi
callq 0x3554
testl %eax, %eax
jne 0x2f1d
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
callq 0x30f4
testl %eax, %eax
jne 0x2f39
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq 0x8(%rsp), %r8
callq 0x30f4
testl %eax, %eax
jne 0x2f55
leaq 0x60(%rsp), %rdi
pushq $0x20
popq %rsi
callq 0x4cc0
testl %eax, %eax
jne 0x2f7b
movq 0x38(%rsp), %r15
movq 0x20(%rsp), %r12
movq 0x1346a(%rip), %r13     # 0x15fe0
movq (%r13), %rcx
leaq 0xb8f3(%rip), %rdi      # 0xe474
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
callq 0x2570
leaq 0xb8f4(%rip), %rsi      # 0xe487
leaq 0x60(%rsp), %rdx
pushq $0x20
popq %rcx
movq %r14, %rdi
callq 0x7112
testq %rax, %rax
je 0x2f95
movq %rax, %r14
leaq 0xb8ec(%rip), %r8       # 0xe4a2
movq %r15, %rdi
movq %r12, %rsi
movq 0x30(%rsp), %rdx
movq %rbx, %rcx
movq %rax, %r9
callq 0x3369
testq %rax, %rax
je 0x2fb9
movq %rax, %rdi
callq 0x23d0
movq %r14, %rdi
callq 0x23d0
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0x2400
movq 0x38(%rsp), %r15
movq 0x20(%rsp), %r12
movq (%r13), %rcx
leaq 0xb8c0(%rip), %rdi      # 0xe4c6
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x2570
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
orq $-0x1, 0x18(%rdx)
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x30(%rdx)
movq 0x10(%rsp), %rax
bswapq %rax
movq %rax, 0x40(%rdx)
movaps 0x60(%rsp), %xmm0
movaps 0x70(%rsp), %xmm1
movups %xmm0, 0x48(%rdx)
movups %xmm1, 0x58(%rdx)
leaq 0xb564(%rip), %rsi      # 0xe1ba
pushq $0x68
popq %rcx
movq 0x8(%rsp), %rdi
callq 0x7112
testq %rax, %rax
jne 0x2c88
callq 0x2040
movq %rax, %rbx
cmpl $0x0, (%rax)
jne 0x2cd7
leaq 0xb813(%rip), %rdi      # 0xe48f
xorl %eax, %eax
callq 0x6c40
jmp 0x2d95
movq %rax, %r14
leaq 0xb810(%rip), %r8       # 0xe4a2
movq %r15, %rdi
movq %r12, %rsi
movq 0x30(%rsp), %r15
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r9
callq 0x3369
testq %rax, %rax
jne 0x2ced
callq 0x2040
movq %rax, %rbx
cmpl $0x0, (%rax)
jne 0x2d79
leaq 0xb817(%rip), %rdi      # 0xe4df
movq %r14, %rsi
xorl %eax, %eax
callq 0x6c40
jmp 0x2d8d
leaq 0xb7b1(%rip), %rdi      # 0xe48f
xorl %eax, %eax
callq 0x6ab1
andl $0x0, (%rbx)
jmp 0x2d95
movq %rax, %rdi
callq 0x23d0
movq %r14, %rdi
callq 0x23d0
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0x2400
movq %rbx, %rdi
callq 0x61bb
movq 0x48(%rsp), %rdi
callq 0x23d0
movq 0x38(%rsp), %rdi
callq 0x23d0
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x2140
leaq 0x13857(%rip), %rcx     # 0x16590
movq (%rcx), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *%rcx
movq 0x20(%rsp), %rdi
callq 0x23d0
movq %rbp, %rdi
callq 0x23d0
movq 0x8(%rsp), %rdi
callq 0x23d0
movq %r15, %rdi
callq 0x23d0
movq 0x18(%rsp), %rdi
callq 0x23d0
xorl %edi, %edi
callq 0x23f0
leaq 0xb75f(%rip), %rdi      # 0xe4df
movq %r14, %rsi
xorl %eax, %eax
callq 0x6ab1
andl $0x0, (%rbx)
movq %r14, %rdi
callq 0x23d0
cmpl $0x0, (%rbx)
jne 0x2daa
leaq 0xb409(%rip), %rdi      # 0xe1aa
xorl %eax, %eax
callq 0x6c40
jmp 0x2dbb
leaq 0xb3f9(%rip), %rdi      # 0xe1aa
xorl %eax, %eax
callq 0x6ab1
andl $0x0, (%rbx)
pushq $0x1
popq %rdi
callq 0x23f0
leaq 0xb2da(%rip), %rdi      # 0xe0a4
jmp 0x2dd3
leaq 0xb2ba(%rip), %rdi      # 0xe08d
movq %rbp, %rsi
xorl %eax, %eax
callq 0x6c40
callq 0x2040
andl $0x0, (%rax)
callq 0x3093
movq 0x131ef(%rip), %rax     # 0x15fe0
movq (%rax), %rcx
leaq 0xb26d(%rip), %rdi      # 0xe068
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x2570
jmp 0x2d72
callq 0x3093
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2e30
leaq 0xb213(%rip), %rdi      # 0xe034
movq %rbp, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x6c40
jmp 0x2dbb
movq %rax, %rbx
leaq 0xb1fa(%rip), %rdi      # 0xe034
movq %rbp, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x6ab1
jmp 0x2db8
leaq 0xb1b1(%rip), %rdi      # 0xe004
leaq 0xb1b9(%rip), %rsi      # 0xe013
leaq 0xb1b9(%rip), %rcx      # 0xe01a
movl $0x14e, %edx            # imm = 0x14E
callq 0x21e0
leaq 0xb192(%rip), %rdi      # 0xe004
leaq 0xb19a(%rip), %rsi      # 0xe013
leaq 0xb19a(%rip), %rcx      # 0xe01a
movl $0x166, %edx            # imm = 0x166
callq 0x21e0
leaq 0xb173(%rip), %rdi      # 0xe004
leaq 0xb17b(%rip), %rsi      # 0xe013
leaq 0xb17b(%rip), %rcx      # 0xe01a
movl $0x160, %edx            # imm = 0x160
callq 0x21e0
leaq 0xb154(%rip), %rdi      # 0xe004
leaq 0xb15c(%rip), %rsi      # 0xe013
leaq 0xb15c(%rip), %rcx      # 0xe01a
movl $0x154, %edx            # imm = 0x154
callq 0x21e0
leaq 0xb135(%rip), %rdi      # 0xe004
leaq 0xb13d(%rip), %rsi      # 0xe013
leaq 0xb13d(%rip), %rcx      # 0xe01a
movl $0x15a, %edx            # imm = 0x15A
callq 0x21e0
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2fe0
leaq 0xb20d(%rip), %rdi      # 0xe109
jmp 0x2da1
callq 0x2040
cmpl $0x0, (%rax)
movq 0x48(%rsp), %rsi
jne 0x2fef
leaq 0xb1f7(%rip), %rdi      # 0xe112
jmp 0x2f6f
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2ffb
leaq 0xb202(%rip), %rdi      # 0xe134
movq 0x28(%rsp), %rsi
jmp 0x2f6f
callq 0x2040
cmpl $0x0, (%rax)
jne 0x300c
leaq 0xb205(%rip), %rdi      # 0xe153
movq 0x18(%rsp), %rsi
jmp 0x2f6f
callq 0x2040
cmpl $0x0, (%rax)
jne 0x301d
leaq 0xb1e9(%rip), %rdi      # 0xe153
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x6c40
jmp 0x2dbb
callq 0x2040
cmpl $0x0, (%rax)
jne 0x3038
leaq 0xb1e7(%rip), %rdi      # 0xe177
jmp 0x2da1
callq 0x2040
movq %rax, %rbx
cmpl $0x0, (%rax)
jne 0x3047
leaq 0xb4e2(%rip), %rdi      # 0xe48f
xorl %eax, %eax
callq 0x6c40
jmp 0x3076
callq 0x2040
movq %rax, %rbx
cmpl $0x0, (%rax)
jne 0x305a
leaq 0xb4d9(%rip), %rdi      # 0xe4aa
movq %r14, %rsi
xorl %eax, %eax
callq 0x6c40
jmp 0x306e
movq %rax, %rbx
leaq 0xb11f(%rip), %rdi      # 0xe109
jmp 0x2db1
movq %rax, %rbx
leaq 0xb119(%rip), %rdi      # 0xe112
jmp 0x302c
movq %rax, %rbx
leaq 0xb12f(%rip), %rdi      # 0xe134
movq 0x28(%rsp), %rsi
jmp 0x302c
movq %rax, %rbx
leaq 0xb13d(%rip), %rdi      # 0xe153
movq 0x18(%rsp), %rsi
jmp 0x302c
movq %rax, %rbx
leaq 0xb12c(%rip), %rdi      # 0xe153
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x6ab1
jmp 0x2db8
movq %rax, %rbx
leaq 0xb135(%rip), %rdi      # 0xe177
jmp 0x2db1
leaq 0xb441(%rip), %rdi      # 0xe48f
xorl %eax, %eax
callq 0x6ab1
andl $0x0, (%rbx)
jmp 0x307b
leaq 0xb449(%rip), %rdi      # 0xe4aa
movq %r14, %rsi
xorl %eax, %eax
callq 0x6ab1
andl $0x0, (%rbx)
movq %r14, %rdi
callq 0x23d0
cmpl $0x0, (%rbx)
jne 0x3087
leaq 0xb10f(%rip), %rdi      # 0xe191
jmp 0x2da1
leaq 0xb103(%rip), %rdi      # 0xe191
jmp 0x2db1