// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movabsq $0x3a653a76733a72, %rax # imm = 0x3A653A76733A72
leaq 0x8(%rsp), %r14
movq %rax, 0x6(%r14)
movabsq $0x3a723a703a6d6861, %rax # imm = 0x3A723A703A6D6861
movq %rax, (%r14)
movl $0x51, %edi
callq 0x3300
movq %rax, 0x8ab4(%rip)      # 0x11848
leaq 0x4f48(%rip), %rdx      # 0xdce3
leaq 0x4f85(%rip), %rcx      # 0xdd27
movl $0x51, %esi
movq %rax, %rdi
xorl %eax, %eax
callq 0x3180
movl $0x0, 0x8a85(%rip)      # 0x11840
leaq -0xf2f(%rip), %rax      # 0x7e93
movq %rax, 0x8a87(%rip)      # 0x11850
leaq 0x8a00(%rip), %rax      # 0x117d0
movq %rax, 0x8a81(%rip)      # 0x11858
movq $0x1, 0x8a7e(%rip) # 0x11860
movl $0x1, 0x8a7c(%rip)      # 0x11868
movq $0x0, 0x8a79(%rip) # 0x11870
leaq 0x88b2(%rip), %rcx      # 0x116b0
leaq 0x4(%rsp), %r8
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3170
testl %eax, %eax
js 0x914d
movq 0x8191(%rip), %r15      # 0x10fb0
leaq 0x888a(%rip), %r12      # 0x116b0
leaq 0x8(%rsp), %r14
leaq 0x4(%rsp), %r13
leal -0x68(%rax), %ecx
cmpl $0xe, %ecx
ja 0x8f54
leaq 0x4b1d(%rip), %rdx      # 0xd960
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq (%r15), %r13
movq %r13, %rdi
leaq 0x4623(%rip), %rsi      # 0xd47c
callq 0x3270
testl %eax, %eax
je 0x9055
movq %r13, %rdi
leaq 0x4ebd(%rip), %rsi      # 0xdd2d
callq 0x3270
testl %eax, %eax
je 0x9055
movq %r13, %rdi
leaq 0x4629(%rip), %rsi      # 0xd4b0
callq 0x3270
testl %eax, %eax
je 0x909f
movq %r13, %rdi
leaq 0x4e93(%rip), %rsi      # 0xdd31
callq 0x3270
testl %eax, %eax
je 0x909f
movq %r13, %rdi
leaq 0x465e(%rip), %rsi      # 0xd513
callq 0x3270
testl %eax, %eax
je 0x9129
movq %r13, %rdi
leaq 0x4681(%rip), %rsi      # 0xd54d
callq 0x3270
testl %eax, %eax
je 0x9141
movq %r13, %rdi
leaq 0x2c43(%rip), %rsi      # 0xbb26
callq 0x3270
testl %eax, %eax
je 0x9135
movq %r13, %rdi
leaq 0x4dd5(%rip), %rsi      # 0xdccf
callq 0x3270
testl %eax, %eax
je 0x9135
movq %r13, %rdi
leaq 0x4e29(%rip), %rsi      # 0xdd3a
callq 0x3270
testl %eax, %eax
je 0x9135
movq %r13, %rdi
leaq 0x4e19(%rip), %rsi      # 0xdd41
callq 0x3270
testl %eax, %eax
je 0x8f48
movq %r13, %rdi
leaq 0x4e0b(%rip), %rsi      # 0xdd46
callq 0x3270
testl %eax, %eax
jne 0x9184
leaq -0xc84(%rip), %rax      # 0x82cb
jmp 0x90a6
cmpl $0x65, %eax
je 0x9033
cmpl $0x61, %eax
jne 0x9165
movl $0x1, 0x88d0(%rip)      # 0x11840
jmp 0x910c
movq (%r15), %rdi
leaq 0x4f39(%rip), %rsi      # 0xdeb8
leaq 0x88da(%rip), %rdx      # 0x11860
xorl %eax, %eax
callq 0x3310
cmpl $0x1, %eax
jne 0x916f
cmpl $0x0, 0x88c3(%rip)      # 0x11860
jg 0x910c
jmp 0x916f
movq (%r15), %r13
movq %r13, %rdi
leaq 0x4db9(%rip), %rsi      # 0xdd6e
callq 0x3270
testl %eax, %eax
je 0x9042
movq %r13, %rdi
leaq 0x4dab(%rip), %rsi      # 0xdd77
callq 0x3270
testl %eax, %eax
je 0x9042
movq %r13, %rdi
leaq 0x4da0(%rip), %rsi      # 0xdd7f
callq 0x3270
testl %eax, %eax
jne 0x9174
leaq 0x87f5(%rip), %rax      # 0x117e8
jmp 0x9049
movl $0x1, 0x8865(%rip)      # 0x11864
jmp 0x910c
movq %r12, %r14
movq %r15, %r12
movq (%r15), %r13
movb (%r13), %r15b
cmpb $0x30, %r15b
jne 0x905e
cmpb $0x0, 0x1(%r13)
je 0x9093
movq %r13, %rdi
leaq 0x4daf(%rip), %rsi      # 0xddd7
callq 0x3270
testl %eax, %eax
jne 0x907e
jmp 0x9093
movq (%r15), %rax
movq %rax, 0x8833(%rip)      # 0x11870
jmp 0x910c
leaq 0x8787(%rip), %rax      # 0x117d0
movq %rax, 0x8808(%rip)      # 0x11858
jmp 0x9107
leaq -0x12db(%rip), %rax     # 0x7d81
jmp 0x90a6
movq %r13, %rdi
leaq 0x4d6f(%rip), %rsi      # 0xddd7
callq 0x3270
testl %eax, %eax
je 0x9093
cmpb $0x31, %r15b
jne 0x90af
cmpb $0x0, 0x1(%r13)
je 0x90f2
movq %r13, %rdi
leaq 0x4d53(%rip), %rsi      # 0xdddb
callq 0x3270
testl %eax, %eax
jne 0x90cf
jmp 0x90f2
movl $0x0, 0x87cb(%rip)      # 0x11868
jmp 0x90fc
leaq -0x1213(%rip), %rax     # 0x7e93
movq %rax, 0x87a3(%rip)      # 0x11850
jmp 0x9107
movq %r13, %rdi
leaq 0x4d22(%rip), %rsi      # 0xdddb
callq 0x3270
testl %eax, %eax
je 0x90f2
cmpb $0x32, %r15b
jne 0x90cf
cmpb $0x0, 0x1(%r13)
je 0x90e6
movq %r13, %rdi
leaq 0x4d07(%rip), %rsi      # 0xdde0
callq 0x3270
testl %eax, %eax
jne 0x917c
movl $0x2, 0x8778(%rip)      # 0x11868
jmp 0x90fc
movl $0x1, 0x876c(%rip)      # 0x11868
movq %r12, %r15
movq %r14, %r12
leaq 0x8(%rsp), %r14
leaq 0x4(%rsp), %r13
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
movq %r13, %r8
callq 0x3170
testl %eax, %eax
jns 0x8e30
jmp 0x914d
leaq -0x11da(%rip), %rax     # 0x7f56
jmp 0x90a6
leaq -0xe97(%rip), %rax      # 0x82a5
jmp 0x90a6
leaq -0x1078(%rip), %rax     # 0x80d0
jmp 0x90a6
movq 0x7e3c(%rip), %rax      # 0x10f90
movl (%rax), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3737
callq 0x372a
callq 0x36bd
movq %r13, %rdi
callq 0x36e2
movq %r13, %rdi
callq 0x3699
movq %r13, %rdi
callq 0x3706