// File: /workspace/github_c_makefile_star2_O2/sTeeLM[P]dwipe/options.c
// Function: dwipe_options_parse
int dwipe_options_parse( int argc, char** argv )
{
	extern char* optarg;  /* The working getopt option argument. */
	extern int   optind;  /* The working getopt index into argv. */
	extern int   optopt;  /* The last unhandled getopt option.   */
	extern int   opterr;  /* The last getopt error number.       */

	extern dwipe_prng_t dwipe_twister;
	extern dwipe_prng_t dwipe_isaac;

	/* The maximum banner size, including the null. */
	const int dwipe_banner_size = 81;

	/* The getopt() result holder. */
	int dwipe_opt;

	/* Array index variable. */
	int i;

	/* The list of acceptable short options. */
	char dwipe_options_short [] = "ahm:p:r:sv:e:";

	/* The list of acceptable long options. */
	static struct option dwipe_options_long [] =
	{
		/* Set when the user wants to wipe without a confirmation prompt. */
		{ "autonuke", no_argument, 0, 0 },

		/* A GNU standard option. Corresponds to the 'h' short option. */
		{ "help", no_argument, 0, 'h' },

		/* The wipe method. Corresponds to the 'm' short option. */
		{ "method", required_argument, 0, 'm' },

		/* The Pseudo Random Number Generator. */
		{ "prng", required_argument, 0, 'p' },

		/* The number of times to run the method. */
		{ "rounds", required_argument, 0, 'r' },

		/* A flag to indicate whether the devices whould be opened in sync mode. */
		{ "sync", no_argument, 0, 0 },

		/* Verify that wipe patterns are being written to the device. */
		{ "verify", required_argument, 0, 0 },

		/* Verify that wipe patterns are being written to the device. */
		{ "exclude", required_argument, 0, 0 },

		/* Requisite padding for getopt(). */
		{ 0, 0, 0, 0 }
	};

	/* Note that COLS isn't available until ncurses is initialized. */
	dwipe_options.banner = malloc( dwipe_banner_size );

	/* Set the default product banner. */
	snprintf( dwipe_options.banner, dwipe_banner_size, "Darik's Wipe version %s(modified by sTeeLM<steel.mental@gmail.com>)", DBAN_VERSION );


	/* Set default options. */
	dwipe_options.autonuke = 0;
	dwipe_options.method   = &dwipe_dodshort;
	dwipe_options.prng     = &dwipe_twister;
	dwipe_options.rounds   = 1;
	dwipe_options.sync     = 0;
	dwipe_options.verify   = DWIPE_VERIFY_LAST;
    dwipe_options.exclude  = NULL;


	/* Parse command line options. */
	while( 1 )
	{
		/* Get the next command line option with (3)getopt. */
		dwipe_opt = getopt_long( argc, argv, dwipe_options_short, dwipe_options_long, &i );

		/* Break when we have processed all of the given options. */
		if( dwipe_opt < 0 ) { break; }

		switch( dwipe_opt )
		{
            case 'a':
                dwipe_options.autonuke = 1;
                break;

            case 'h':
                dwipe_options_usage();
                exit( 0 );

            case 'm':  /* Method option. */

				if( strcmp( optarg, "dod522022m" ) == 0 || strcmp( optarg, "dod" ) == 0 )
				{
					dwipe_options.method = &dwipe_dod522022m;
					break;
				}

				if( strcmp( optarg, "dodshort" ) == 0 || strcmp( optarg, "dod3pass" ) == 0 )
				{
					dwipe_options.method = &dwipe_dodshort;
					break;
				}

				if( strcmp( optarg, "gutmann" ) == 0 )
				{
					dwipe_options.method = &dwipe_gutmann;
					break;
				}

				if( strcmp( optarg, "ops2" ) == 0 )
				{
					dwipe_options.method = &dwipe_ops2;
					break;
				}

				if(  strcmp( optarg, "random" ) == 0
				  || strcmp( optarg, "prng"   ) == 0
				  || strcmp( optarg, "stream" ) == 0
				  )
				{
					dwipe_options.method= &dwipe_random;
					break;
				}

				if( strcmp( optarg, "zero" ) == 0 || strcmp( optarg, "quick" ) == 0 )
				{
					dwipe_options.method = &dwipe_zero;
					break;
				}

				/* Else we do not know this wipe method. */
				fprintf( stderr, "Error: Unknown wipe method '%s'.\n", optarg );
				exit( EINVAL );


			case 'p':  /* PRNG option. */

				if(  strcmp( optarg, "mersenne" ) == 0
				  || strcmp( optarg, "twister"  ) == 0
				  )
				{
					dwipe_options.prng = &dwipe_twister;
					break;
				}

				if( strcmp( optarg, "isaac" ) == 0 )
				{
					dwipe_options.prng = &dwipe_isaac;
					break;
				}

				/* Else we do not know this PRNG. */
				fprintf( stderr, "Error: Unknown prng '%s'.\n", optarg );
				exit( EINVAL );


			case 'r':  /* Rounds option. */

				if( sscanf( optarg, " %i", &dwipe_options.rounds ) != 1 \
				    || dwipe_options.rounds < 1
				  )
				{
					fprintf( stderr, "Error: The rounds argument must be a postive integer.\n" );
					exit( EINVAL );
				}

				break;

            case 's':
                dwipe_options.sync = 1;
                break;

            case 'v':
                if( strcmp( optarg, "0" ) == 0 || strcmp( optarg, "off" ) == 0 )
                {
                        dwipe_options.verify = DWIPE_VERIFY_NONE;
                        break;
                }

                if( strcmp( optarg, "1" ) == 0 || strcmp( optarg, "last" ) == 0 )
                {
                        dwipe_options.verify = DWIPE_VERIFY_LAST;
                        break;
                }

                if( strcmp( optarg, "2" ) == 0 || strcmp( optarg, "all" ) == 0 )
                {
                        dwipe_options.verify = DWIPE_VERIFY_ALL;
                        break;
                }
                /* Else we do not know this verification level. */
                fprintf( stderr, "Error: Unknown verification level '%s'.\n", optarg );
				exit( EINVAL );

            case 'e':
                dwipe_options.exclude = optarg;
                break;

			default:

				/* Bogus command line argument. */
				/* TODO: Print usage. */
				fprintf( stderr, "Error: Unknown short option.\n" );
				exit( EINVAL );
			
		} /* method */

	} /* command line options */

	/* Return the number of options that were processed. */
	return optind;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movabsq $0x3a653a76733a72, %rax # imm = 0x3A653A76733A72
leaq 0x18(%rsp), %r14
movq %rax, 0x6(%r14)
movabsq $0x3a723a703a6d6861, %rax # imm = 0x3A723A703A6D6861
movq %rax, (%r14)
pushq $0x51
popq %r15
movq %r15, %rdi
callq 0x3300
movq %rax, 0x81ff(%rip)      # 0x10848
leaq 0x465f(%rip), %rdx      # 0xccaf
leaq 0x469c(%rip), %rcx      # 0xccf3
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %r15
xorl %eax, %eax
callq 0x3180
andl $0x0, 0x81d2(%rip)      # 0x10840
leaq -0xec0(%rip), %rax      # 0x77b5
movq %rax, 0x81d4(%rip)      # 0x10850
leaq 0x814d(%rip), %rax      # 0x107d0
movq %rax, 0x81ce(%rip)      # 0x10858
movq $0x1, 0x81cb(%rip) # 0x10860
movl $0x1, 0x81c9(%rip)      # 0x10868
andq $0x0, 0x81c9(%rip)      # 0x10870
leaq 0x8002(%rip), %r12      # 0x106b0
leaq 0x14(%rsp), %r14
movq %rbx, 0x8(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movq %r14, %r8
callq 0x3170
testl %eax, %eax
js 0x8a12
leal -0x68(%rax), %ecx
cmpl $0xe, %ecx
ja 0x8805
leaq 0x4246(%rip), %rdx      # 0xc92c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x78ba(%rip), %rax      # 0xffb0
movq (%rax), %r13
movq %r13, %rdi
leaq 0x3d79(%rip), %rsi      # 0xc47c
callq 0x3270
testl %eax, %eax
je 0x898d
movq %r13, %rdi
leaq 0x45df(%rip), %rsi      # 0xccf9
callq 0x3270
testl %eax, %eax
je 0x898d
movq %r13, %rdi
leaq 0x3d7f(%rip), %rsi      # 0xc4b0
callq 0x3270
testl %eax, %eax
je 0x89c6
movq %r13, %rdi
leaq 0x45b5(%rip), %rsi      # 0xccfd
callq 0x3270
testl %eax, %eax
je 0x89c6
movq %r13, %rdi
leaq 0x3db4(%rip), %rsi      # 0xc513
callq 0x3270
testl %eax, %eax
je 0x89d9
movq %r13, %rdi
leaq 0x3dd7(%rip), %rsi      # 0xc54d
callq 0x3270
testl %eax, %eax
je 0x89ff
movq %r13, %rdi
leaq 0x2399(%rip), %rsi      # 0xab26
callq 0x3270
testl %eax, %eax
je 0x89ec
movq %r13, %rdi
leaq 0x44f7(%rip), %rsi      # 0xcc9b
callq 0x3270
testl %eax, %eax
je 0x89ec
movq %r13, %rdi
leaq 0x454b(%rip), %rsi      # 0xcd06
callq 0x3270
testl %eax, %eax
je 0x89ec
movq %r13, %rdi
leaq 0x453b(%rip), %rsi      # 0xcd0d
callq 0x3270
testl %eax, %eax
je 0x87f2
movq %r13, %rdi
leaq 0x452d(%rip), %rsi      # 0xcd12
callq 0x3270
testl %eax, %eax
jne 0x8a9f
leaq -0xc5b(%rip), %rax      # 0x7b9e
movq %rax, 0x8050(%rip)      # 0x10850
jmp 0x86b8
cmpl $0x65, %eax
je 0x8964
cmpl $0x61, %eax
jne 0x8a2a
movl $0x1, 0x801f(%rip)      # 0x10840
jmp 0x86b8
movq 0x7783(%rip), %rax      # 0xffb0
movq (%rax), %rdi
leaq 0x464d(%rip), %rsi      # 0xce84
leaq 0x8022(%rip), %rdx      # 0x10860
xorl %eax, %eax
callq 0x3310
cmpl $0x1, %eax
jne 0x8a4b
cmpl $0x0, 0x800b(%rip)      # 0x10860
jg 0x86b8
jmp 0x8a4b
movq 0x7749(%rip), %rax      # 0xffb0
movq (%rax), %r13
movq %r13, %rdi
leaq 0x44c6(%rip), %rsi      # 0xcd3a
callq 0x3270
testl %eax, %eax
je 0x897a
movq %r13, %rdi
leaq 0x44b8(%rip), %rsi      # 0xcd43
callq 0x3270
testl %eax, %eax
je 0x897a
movq %r13, %rdi
leaq 0x44a9(%rip), %rsi      # 0xcd4b
callq 0x3270
testl %eax, %eax
jne 0x8a69
leaq 0x7f32(%rip), %rax      # 0x107e8
movq %rax, 0x7f9b(%rip)      # 0x10858
jmp 0x86b8
movl $0x1, 0x7f98(%rip)      # 0x10864
jmp 0x86b8
movq %r14, %rbx
movq %r12, %r14
movq %r15, %r12
movq 0x76cf(%rip), %rax      # 0xffb0
movq (%rax), %r13
movb (%r13), %r15b
cmpb $0x30, %r15b
jne 0x88f9
cmpb $0x0, 0x1(%r13)
je 0x89a0
movq %r13, %rdi
leaq 0x44a0(%rip), %rsi      # 0xcda3
callq 0x3270
testl %eax, %eax
je 0x89a0
cmpb $0x31, %r15b
jne 0x8921
cmpb $0x0, 0x1(%r13)
je 0x89a9
movq %r13, %rdi
leaq 0x447c(%rip), %rsi      # 0xcda7
callq 0x3270
testl %eax, %eax
je 0x89a9
cmpb $0x32, %r15b
jne 0x8941
cmpb $0x0, 0x1(%r13)
je 0x8958
movq %r13, %rdi
leaq 0x4461(%rip), %rsi      # 0xcdac
callq 0x3270
testl %eax, %eax
jne 0x8a7c
movl $0x2, 0x7f06(%rip)      # 0x10868
jmp 0x89b3
movq 0x7645(%rip), %rax      # 0xffb0
movq (%rax), %rax
movq %rax, 0x7efb(%rip)      # 0x10870
jmp 0x86b8
leaq 0x7e4f(%rip), %rax      # 0x107d0
movq %rax, 0x7ed0(%rip)      # 0x10858
jmp 0x86b8
leaq -0x12db(%rip), %rax     # 0x76b9
movq %rax, 0x7eb5(%rip)      # 0x10850
jmp 0x86b8
andl $0x0, 0x7ec1(%rip)      # 0x10868
jmp 0x89b3
movl $0x1, 0x7eb5(%rip)      # 0x10868
movq %r12, %r15
movq %r14, %r12
movq %rbx, %r14
movq 0x8(%rsp), %rbx
jmp 0x86b8
leaq -0x1218(%rip), %rax     # 0x77b5
movq %rax, 0x7e7c(%rip)      # 0x10850
jmp 0x86b8
leaq -0x1179(%rip), %rax     # 0x7867
movq %rax, 0x7e69(%rip)      # 0x10850
jmp 0x86b8
leaq -0xe7b(%rip), %rax      # 0x7b78
movq %rax, 0x7e56(%rip)      # 0x10850
jmp 0x86b8
leaq -0x1042(%rip), %rax     # 0x79c4
movq %rax, 0x7e43(%rip)      # 0x10850
jmp 0x86b8
movq 0x7577(%rip), %rax      # 0xff90
movl (%rax), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x75bf(%rip), %rax      # 0xfff0
movq (%rax), %rcx
leaq 0x439e(%rip), %rdi      # 0xcdd9
pushq $0x1d
jmp 0x8a5e
callq 0x845c
xorl %edi, %edi
callq 0x3400
movq 0x759e(%rip), %rax      # 0xfff0
movq (%rax), %rcx
leaq 0x4310(%rip), %rdi      # 0xcd6c
pushq $0x36
popq %rsi
pushq $0x1
popq %rdx
callq 0x3410
jmp 0x8a97
movq 0x7580(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x42d7(%rip), %rsi      # 0xcd51
jmp 0x8a8d
movq 0x756d(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x4323(%rip), %rsi      # 0xcdb0
movq %r13, %rdx
xorl %eax, %eax
callq 0x3280
pushq $0x16
popq %rdi
callq 0x3400
movq 0x754a(%rip), %rax      # 0xfff0
movq (%rax), %rdi
leaq 0x4268(%rip), %rsi      # 0xcd18
jmp 0x8a8d