// File: /workspace/github_c_makefile_star2_O0/giometti[P]mastering_UNIX_programming/chapter_09/scdu.c
// Function: main
int main(int argc, char *argv[ ])
{
	bool do_decrypt = false;
	int errflg = 0;
	char *module = NULL, *text;
	func_t crypt, decrypt;
	int c, n;

	/* Parse the command line */
	while ((c = getopt(argc, argv, ":hdf:")) != -1) {
		switch(c) {
		case 'h':
			usage(argv[0], EXIT_SUCCESS);

		case 'd':
			do_decrypt = true;
			break;

		case 'f':
			module = optarg;
			break;

		case ':':       /* missing operand? */
			fprintf(stderr,
				"option -%c requires an operand\n",
				optopt);
			errflg++;
			break;

		case '?':	/* invalid option? */
			fprintf(stderr,
				"unrecognized option: '-%c'\n",

				optopt);
			errflg++;
		}
	}
	if (errflg)
		usage(argv[0], EXIT_FAILURE);
	if (optind == argc) {
		fprintf(stderr, "no input text\n");
		exit(EXIT_FAILURE);
	}
	text = argv[optind];

	/* Load standard or external function within a module */
	load_funcs(module, &crypt, &decrypt);

	/* Do the job */
	n = strlen(text);
	if (do_decrypt)
		decrypt(text, n);
	else
		crypt(text, n);

	/* Print the result */
	printf("%*s\n", n, text);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
movl $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xc67(%rip), %rdx       # 0x215e
callq 0x1080
movl %eax, -0x3c(%rbp)
cmpl $-0x1, %eax
je 0x15b0
movl -0x3c(%rbp), %eax
addl $-0x3a, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x2e, %eax
ja 0x15ab
movq -0x48(%rbp), %rax
leaq 0xadc(%rip), %rcx       # 0x2004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x1480
movb $0x1, -0x11(%rbp)
jmp 0x15ab
movq 0x2a84(%rip), %rax      # 0x3fd0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x15ab
movq 0x2a9c(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq 0x2a7a(%rip), %rax      # 0x3fe0
movl (%rax), %edx
leaq 0xbf5(%rip), %rsi       # 0x2164
movb $0x0, %al
callq 0x1070
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x15ab
movq 0x2a70(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq 0x2a4e(%rip), %rax      # 0x3fe0
movl (%rax), %edx
leaq 0xbe9(%rip), %rsi       # 0x2184
movb $0x0, %al
callq 0x1070
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x14e9
cmpl $0x0, -0x18(%rbp)
je 0x15c7
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x1480
movq 0x29fa(%rip), %rax      # 0x3fc8
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jne 0x15f7
movq 0x2a1c(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xbba(%rip), %rsi       # 0x21a0
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x10a0
movq -0x10(%rbp), %rax
movq 0x29c6(%rip), %rcx      # 0x3fc8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x1350
movq -0x28(%rbp), %rdi
callq 0x1040
movl %eax, -0x40(%rbp)
testb $0x1, -0x11(%rbp)
je 0x1640
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq *%rax
jmp 0x164e
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq *%rax
movl -0x40(%rbp), %esi
movq -0x28(%rbp), %rdx
leaq 0xb53(%rip), %rdi       # 0x21af
movb $0x0, %al
callq 0x1050
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq