// File: /workspace/github_c_makefile_star2_O1/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 0x32f0
movq %rax, 0x8b2c(%rip)      # 0x11848
leaq 0x4fc0(%rip), %rdx      # 0xdce3
leaq 0x4ffd(%rip), %rcx      # 0xdd27
movl $0x51, %esi
movq %rax, %rdi
xorl %eax, %eax
callq 0x3180
movl $0x0, 0x8afd(%rip)      # 0x11840
leaq -0xf3b(%rip), %rax      # 0x7e0f
movq %rax, 0x8aff(%rip)      # 0x11850
leaq 0x8a78(%rip), %rax      # 0x117d0
movq %rax, 0x8af9(%rip)      # 0x11858
movq $0x1, 0x8af6(%rip) # 0x11860
movl $0x1, 0x8af4(%rip)      # 0x11868
movq $0x0, 0x8af1(%rip) # 0x11870
leaq 0x892a(%rip), %rcx      # 0x116b0
leaq 0x4(%rsp), %r8
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3170
testl %eax, %eax
js 0x90ce
leaq 0x8909(%rip), %r13      # 0x116b0
leaq 0x8(%rsp), %r15
leaq 0x4(%rsp), %r12
leaq 0x4ba8(%rip), %r14      # 0xd960
leal -0x68(%rax), %ecx
cmpl $0xe, %ecx
ja 0x8edc
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x81dc(%rip), %rax      # 0x10fb0
movq (%rax), %r13
movq %r13, %rdi
leaq 0x469b(%rip), %rsi      # 0xd47c
callq 0x3260
testl %eax, %eax
je 0x9060
movq %r13, %rdi
leaq 0x4f35(%rip), %rsi      # 0xdd2d
callq 0x3260
testl %eax, %eax
je 0x9060
movq %r13, %rdi
leaq 0x46a1(%rip), %rsi      # 0xd4b0
callq 0x3260
testl %eax, %eax
je 0x9075
movq %r13, %rdi
leaq 0x4f0b(%rip), %rsi      # 0xdd31
callq 0x3260
testl %eax, %eax
je 0x9075
movq %r13, %rdi
leaq 0x46d6(%rip), %rsi      # 0xd513
callq 0x3260
testl %eax, %eax
je 0x90b3
movq %r13, %rdi
leaq 0x46f9(%rip), %rsi      # 0xd54d
callq 0x3260
testl %eax, %eax
je 0x90c5
movq %r13, %rdi
leaq 0x2cbb(%rip), %rsi      # 0xbb26
callq 0x3260
testl %eax, %eax
je 0x90bc
movq %r13, %rdi
leaq 0x4e4d(%rip), %rsi      # 0xdccf
callq 0x3260
testl %eax, %eax
je 0x90bc
movq %r13, %rdi
leaq 0x4ea1(%rip), %rsi      # 0xdd3a
callq 0x3260
testl %eax, %eax
je 0x90bc
movq %r13, %rdi
leaq 0x4e91(%rip), %rsi      # 0xdd41
callq 0x3260
testl %eax, %eax
je 0x8ed0
movq %r13, %rdi
leaq 0x4e83(%rip), %rsi      # 0xdd46
callq 0x3260
testl %eax, %eax
jne 0x9105
leaq -0xc98(%rip), %rax      # 0x823f
jmp 0x907c
cmpl $0x65, %eax
je 0x903d
cmpl $0x61, %eax
jne 0x90e6
movl $0x1, 0x8948(%rip)      # 0x11840
jmp 0x908a
movq 0x80ac(%rip), %rax      # 0x10fb0
movq (%rax), %rdi
leaq 0x4faa(%rip), %rsi      # 0xdeb8
leaq 0x894b(%rip), %rdx      # 0x11860
xorl %eax, %eax
callq 0x3300
cmpl $0x1, %eax
jne 0x90f0
cmpl $0x0, 0x8934(%rip)      # 0x11860
jg 0x908a
jmp 0x90f0
movq 0x8072(%rip), %rax      # 0x10fb0
movq (%rax), %r13
movq %r13, %rdi
leaq 0x4e23(%rip), %rsi      # 0xdd6e
callq 0x3260
testl %eax, %eax
je 0x9050
movq %r13, %rdi
leaq 0x4e15(%rip), %rsi      # 0xdd77
callq 0x3260
testl %eax, %eax
je 0x9050
movq %r13, %rdi
leaq 0x4e06(%rip), %rsi      # 0xdd7f
callq 0x3260
testl %eax, %eax
jne 0x90f5
leaq 0x885b(%rip), %rax      # 0x117e8
jmp 0x9057
movl $0x1, 0x88c8(%rip)      # 0x11864
jmp 0x908a
movq 0x8008(%rip), %rax      # 0x10fb0
movq (%rax), %r13
movq %r13, %rdi
leaq 0x23d2(%rip), %rsi      # 0xb387
callq 0x3260
testl %eax, %eax
je 0x9069
movq %r13, %rdi
leaq 0x4e0b(%rip), %rsi      # 0xddd7
callq 0x3260
testl %eax, %eax
je 0x9069
movq %r13, %rdi
leaq 0x253d(%rip), %rsi      # 0xb520
callq 0x3260
testl %eax, %eax
je 0x90a7
movq %r13, %rdi
leaq 0x4de1(%rip), %rsi      # 0xdddb
callq 0x3260
testl %eax, %eax
je 0x90a7
movq %r13, %rdi
leaq 0x453f(%rip), %rsi      # 0xd550
callq 0x3260
testl %eax, %eax
je 0x9031
movq %r13, %rdi
leaq 0x4dbc(%rip), %rsi      # 0xdde0
callq 0x3260
testl %eax, %eax
jne 0x90fd
movl $0x2, 0x882d(%rip)      # 0x11868
jmp 0x9083
movq 0x7f6c(%rip), %rax      # 0x10fb0
movq (%rax), %rax
movq %rax, 0x8822(%rip)      # 0x11870
jmp 0x908a
leaq 0x8779(%rip), %rax      # 0x117d0
movq %rax, 0x87fa(%rip)      # 0x11858
jmp 0x9083
leaq -0x136a(%rip), %rax     # 0x7cfd
jmp 0x907c
movl $0x0, 0x87f5(%rip)      # 0x11868
jmp 0x9083
leaq -0x126d(%rip), %rax     # 0x7e0f
movq %rax, 0x87cd(%rip)      # 0x11850
leaq 0x8626(%rip), %r13      # 0x116b0
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x3170
testl %eax, %eax
jns 0x8db8
jmp 0x90ce
movl $0x1, 0x87b7(%rip)      # 0x11868
jmp 0x9083
leaq -0x11e8(%rip), %rax     # 0x7ed2
jmp 0x907c
leaq -0xeaa(%rip), %rax      # 0x8219
jmp 0x907c
leaq -0x1080(%rip), %rax     # 0x804c
jmp 0x907c
movq 0x7ebb(%rip), %rax      # 0x10f90
movl (%rax), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3727
callq 0x371a
callq 0x36ad
movq %r13, %rdi
callq 0x36d2
movq %r13, %rdi
callq 0x3689
movq %r13, %rdi
callq 0x36f6