// File: /workspace/github_c_makefile_star2_O1/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 $0x98, %rsp
movq %rsi, %r15
movl %edi, %ebx
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x306f
callq 0x7370
movl %ebx, %edi
movq %r15, %rsi
callq 0x5630
movq %rax, %rbp
movq $0x0, 0x20(%rsp)
movl $0x0, %eax
movq %rax, 0x28(%rsp)
movl $0x0, %eax
movq %rax, 0x48(%rsp)
movl $0x0, %r12d
movl $0x0, %eax
movq %rax, 0x18(%rsp)
testq %rbp, %rbp
je 0x3484
movq $0x0, 0x18(%rsp)
leaq 0x2567e(%rip), %r13     # 0x28740
leaq 0xcf68(%rip), %r14      # 0x10031
xorl %r12d, %r12d
movq $0x0, 0x48(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq %r15, 0x60(%rsp)
movq $0x14d, 0x10(%rsp)      # imm = 0x14D
movq 0x10(%rsp), %rax
decq %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x44(%rsp)
cmpl $0x0, (%r13)
je 0x3120
movq %rbp, %rdi
callq 0x595b
addq 0x10(%rsp), %rax
jmp 0x312e
movq 0x58(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x58(%rsp)
cmpq $0x165, %rax            # imm = 0x165
jg 0x317b
cmpq $0x159, %rax            # imm = 0x159
jg 0x31c3
cmpq $0x14e, %rax            # imm = 0x14E
je 0x3242
cmpq $0x154, %rax            # imm = 0x154
jne 0x328f
cmpl $0x0, (%r13)
jne 0x32ce
movl $0x154, %esi            # imm = 0x154
subq 0x10(%rsp), %rsi
leaq 0xcedc(%rip), %rdi      # 0x10052
jmp 0x3278
cmpq $0x16e, %rax            # imm = 0x16E
jg 0x31f9
cmpq $0x166, %rax            # imm = 0x166
je 0x3224
cmpq $0x16c, %rax            # imm = 0x16C
jne 0x328f
cmpl $0x0, (%r13)
jne 0x369e
movl $0x16c, %esi            # imm = 0x16C
subq 0x10(%rsp), %rsi
leaq 0xcea7(%rip), %rdi      # 0x1005e
xorl %edx, %edx
callq 0x5a18
jmp 0x310a
cmpq $0x15a, %rax            # imm = 0x15A
je 0x325c
cmpq $0x160, %rax            # imm = 0x160
jne 0x328f
cmpl $0x0, (%r13)
jne 0x33d7
movl $0x160, %esi            # imm = 0x160
subq 0x10(%rsp), %rsi
leaq 0xce61(%rip), %rdi      # 0x10058
jmp 0x3278
cmpq $0x16f, %rax            # imm = 0x16F
jne 0x3287
cmpl $0x0, (%r13)
jne 0x3695
movl $0x16f, %edi            # imm = 0x16F
subq 0x10(%rsp), %rdi
callq 0x5b2f
jmp 0x310a
cmpl $0x0, (%r13)
jne 0x3415
movl $0x166, %esi            # imm = 0x166
subq 0x10(%rsp), %rsi
leaq 0xce1b(%rip), %rdi      # 0x1005b
jmp 0x3278
cmpl $0x0, (%r13)
jne 0x3307
movl $0x14e, %esi            # imm = 0x14E
subq 0x10(%rsp), %rsi
movq %r14, %rdi
jmp 0x3278
cmpl $0x0, (%r13)
jne 0x33a1
movl $0x15a, %esi            # imm = 0x15A
subq 0x10(%rsp), %rsi
leaq 0xcddd(%rip), %rdi      # 0x10055
movl $0x1, %edx
callq 0x5a18
jmp 0x310a
cmpq $0x172, %rax            # imm = 0x172
je 0x32c1
cmpl $0x0, (%r13)
jne 0x36c0
cmpl $0x0, 0x44(%rsp)
jne 0x310a
movl $0x172, %edi            # imm = 0x172
subq 0x10(%rsp), %rdi
callq 0x5b6f
movl $0x1, 0x44(%rsp)
jmp 0x310a
movl $0x1, (%r13)
jmp 0x346e
leaq 0x25463(%rip), %rax     # 0x28738
cmpq $0x0, (%rax)
je 0x3799
cmpq $0x0, 0x20(%rsp)
jne 0x36dc
leaq 0x25446(%rip), %rax     # 0x28738
movq (%rax), %r14
movq %r14, %rdi
callq 0x2520
movq %rax, 0x20(%rsp)
jmp 0x340b
leaq 0x2542a(%rip), %rax     # 0x28738
cmpq $0x0, (%rax)
je 0x377a
cmpq $0x0, 0x18(%rsp)
jne 0x36dc
movl %ebx, %r15d
movq %r12, %rbx
callq 0x2040
movq %rax, %r14
movl $0x0, (%rax)
leaq 0x253f9(%rip), %rax     # 0x28738
movq (%rax), %r12
testq %r12, %r12
je 0x373c
movq %r12, %rdi
leaq 0x68(%rsp), %rsi
xorl %edx, %edx
callq 0x22d0
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rcx
movl $0x16, %eax
cmpq %r12, %rcx
je 0x344f
cmpb $0x0, (%rcx)
movq %rbx, %r12
jne 0x3452
movq 0x18(%rsp), %rax
leaq -0x2001(%rax), %rcx
movl $0x22, %eax
cmpq $-0x1e02, %rcx          # imm = 0xE1FE
jbe 0x3452
jmp 0x3455
leaq 0x25390(%rip), %rax     # 0x28738
cmpq $0x0, (%rax)
je 0x375b
cmpq $0x0, 0x28(%rsp)
jne 0x36dc
leaq 0x25373(%rip), %rax     # 0x28738
movq (%rax), %r14
movq %r14, %rdi
callq 0x2520
movq %rax, 0x28(%rsp)
jmp 0x340b
leaq 0x2535a(%rip), %rax     # 0x28738
cmpq $0x0, (%rax)
je 0x371d
cmpq $0x0, 0x48(%rsp)
jne 0x36dc
leaq 0x2533d(%rip), %rax     # 0x28738
movq (%rax), %r14
movq %r14, %rdi
callq 0x2520
movq %rax, 0x48(%rsp)
testq %rax, %rax
jne 0x3467
jmp 0x36e1
leaq 0x2531c(%rip), %rax     # 0x28738
cmpq $0x0, (%rax)
je 0x37b8
testq %r12, %r12
jne 0x36dc
leaq 0x25302(%rip), %rax     # 0x28738
movq (%rax), %r14
movq %r14, %rdi
callq 0x2520
testq %rax, %rax
je 0x36e1
movq %rax, %r12
jmp 0x3467
movq %rbx, %r12
movl %eax, (%r14)
cmpl $0x0, (%r14)
jne 0x37d7
movl %r15d, %ebx
movq 0x60(%rsp), %r15
leaq 0xcbc3(%rip), %r14      # 0x10031
movl %ebx, %edi
movq %r15, %rsi
callq 0x5630
movq %rax, %rbp
testq %rax, %rax
jne 0x30ec
leaq 0x150dd(%rip), %rax     # 0x18568
cmpl %ebx, (%rax)
jne 0x36dc
cmpq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %r13
movq 0x48(%rsp), %rbp
je 0x36dc
testq %r13, %r13
je 0x36dc
testq %r15, %r15
je 0x36dc
testq %rbp, %rbp
je 0x36dc
testq %r12, %r12
je 0x36dc
movq 0x18(%rsp), %rax
shlq $0x36, %rax
je 0x34fb
leaq 0xcbd5(%rip), %rdi      # 0x100b9
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x750f
callq 0x2040
movl $0x0, (%rax)
leaq 0xcbe9(%rip), %rsi      # 0x100eb
leaq 0x50(%rsp), %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x5260
cmpl $-0x1, %eax
je 0x37fe
movq 0x50(%rsp), %rdi
callq 0x6348
testq %rax, %rax
je 0x3818
movq %rax, %rbx
leaq 0x38(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %r13, %rdi
callq 0x3b50
testl %eax, %eax
jne 0x3834
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq %r12, %r8
callq 0x25b0
testl %eax, %eax
jne 0x3850
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x25b0
testl %eax, %eax
jne 0x386a
leaq 0x70(%rsp), %rdi
movl $0x20, %esi
callq 0x557b
testl %eax, %eax
jne 0x388c
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %r14
movq %rbp, %rdx
movq %rbx, %rcx
movq %r12, %r8
movq %r14, %r9
callq 0x283f
testl %eax, %eax
jne 0x38a2
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %r14, (%rsp)
movq %rbp, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq 0x18(%rsp), %r9
callq 0x295a
testl %eax, %eax
jne 0x365a
movq %rbx, %rdi
callq 0x6a5f
movq 0x50(%rsp), %rdi
callq 0x23c0
movq 0x38(%rsp), %rdi
callq 0x23c0
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x2140
leaq 0x14f62(%rip), %rcx     # 0x18580
movq (%rcx), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *%rcx
movq 0x30(%rsp), %rdi
callq 0x23c0
movq %r13, %rdi
callq 0x23c0
movq %r15, %rdi
callq 0x23c0
movq %rbp, %rdi
callq 0x23c0
movq %r12, %rdi
callq 0x23c0
xorl %edi, %edi
callq 0x23e0
callq 0x2040
cmpl $0x0, (%rax)
jne 0x3674
leaq 0xcb3f(%rip), %rdi      # 0x101aa
xorl %eax, %eax
callq 0x750f
jmp 0x368b
movq %rax, %rbx
leaq 0xcb2c(%rip), %rdi      # 0x101aa
xorl %eax, %eax
callq 0x73f0
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x23e0
leaq 0xc9f1(%rip), %rdi      # 0x1008d
jmp 0x36c7
movq 0x1493b(%rip), %rax     # 0x17fe0
movq (%rax), %rcx
leaq 0xc9b9(%rip), %rdi      # 0x10068
movl $0x24, %esi
movl $0x1, %edx
callq 0x2560
jmp 0x3653
leaq 0xc9dd(%rip), %rdi      # 0x100a4
movq %rbp, %rsi
xorl %eax, %eax
callq 0x750f
callq 0x2040
movl $0x0, (%rax)
callq 0x392c
callq 0x2040
cmpl $0x0, (%rax)
jne 0x3701
leaq 0xc942(%rip), %rdi      # 0x10034
movq %rbp, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x750f
jmp 0x368b
movq %rax, %rbx
leaq 0xc929(%rip), %rdi      # 0x10034
movq %rbp, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x73f0
jmp 0x3685
leaq 0xc8e0(%rip), %rdi      # 0x10004
leaq 0xc8e8(%rip), %rsi      # 0x10013
leaq 0xc8e8(%rip), %rcx      # 0x1001a
movl $0x160, %edx            # imm = 0x160
callq 0x21d0
leaq 0xd490(%rip), %rdi      # 0x10bd3
leaq 0xcb2c(%rip), %rsi      # 0x10276
leaq 0xcb44(%rip), %rcx      # 0x10295
movl $0xbb, %edx
callq 0x21d0
leaq 0xc8a2(%rip), %rdi      # 0x10004
leaq 0xc8aa(%rip), %rsi      # 0x10013
leaq 0xc8aa(%rip), %rcx      # 0x1001a
movl $0x15a, %edx            # imm = 0x15A
callq 0x21d0
leaq 0xc883(%rip), %rdi      # 0x10004
leaq 0xc88b(%rip), %rsi      # 0x10013
leaq 0xc88b(%rip), %rcx      # 0x1001a
movl $0x14e, %edx            # imm = 0x14E
callq 0x21d0
leaq 0xc864(%rip), %rdi      # 0x10004
leaq 0xc86c(%rip), %rsi      # 0x10013
leaq 0xc86c(%rip), %rcx      # 0x1001a
movl $0x154, %edx            # imm = 0x154
callq 0x21d0
leaq 0xc845(%rip), %rdi      # 0x10004
leaq 0xc84d(%rip), %rsi      # 0x10013
leaq 0xc84d(%rip), %rcx      # 0x1001a
movl $0x166, %edx            # imm = 0x166
callq 0x21d0
leaq 0x24f5a(%rip), %rax     # 0x28738
movq (%rax), %rdx
leaq 0xc84c(%rip), %rdi      # 0x10034
movq %rbp, %rsi
xorl %eax, %eax
callq 0x73f0
movl $0x0, (%r14)
jmp 0x368b
callq 0x2040
cmpl $0x0, (%rax)
jne 0x38b8
leaq 0xc8f6(%rip), %rdi      # 0x10109
jmp 0x366b
callq 0x2040
cmpl $0x0, (%rax)
movq 0x50(%rsp), %rsi
jne 0x38c7
leaq 0xc8e0(%rip), %rdi      # 0x10112
jmp 0x3880
callq 0x2040
cmpl $0x0, (%rax)
jne 0x38d3
leaq 0xc8eb(%rip), %rdi      # 0x10134
movq 0x20(%rsp), %rsi
jmp 0x3880
callq 0x2040
cmpl $0x0, (%rax)
jne 0x38e4
leaq 0xc8ee(%rip), %rdi      # 0x10153
movq %r12, %rsi
jmp 0x3880
callq 0x2040
cmpl $0x0, (%rax)
jne 0x38f3
leaq 0xc8d8(%rip), %rdi      # 0x10153
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x750f
jmp 0x368b
callq 0x2040
cmpl $0x0, (%rax)
jne 0x390e
leaq 0xc8da(%rip), %rdi      # 0x10177
jmp 0x366b
callq 0x2040
cmpl $0x0, (%rax)
jne 0x391d
leaq 0xc8de(%rip), %rdi      # 0x10191
jmp 0x366b
movq %rax, %rbx
leaq 0xc847(%rip), %rdi      # 0x10109
jmp 0x367e
movq %rax, %rbx
leaq 0xc841(%rip), %rdi      # 0x10112
jmp 0x3902
movq %rax, %rbx
leaq 0xc857(%rip), %rdi      # 0x10134
movq 0x20(%rsp), %rsi
jmp 0x3902
movq %rax, %rbx
leaq 0xc865(%rip), %rdi      # 0x10153
movq %r12, %rsi
jmp 0x3902
movq %rax, %rbx
leaq 0xc856(%rip), %rdi      # 0x10153
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x73f0
jmp 0x3685
movq %rax, %rbx
leaq 0xc85f(%rip), %rdi      # 0x10177
jmp 0x367e
movq %rax, %rbx
leaq 0xc86a(%rip), %rdi      # 0x10191
jmp 0x367e