// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movl %edi, 0x34(%rsp)
movq %rsi, 0x28(%rsp)
movl $0x51, 0x24(%rsp)
movq 0x4d3b(%rip), %rax      # 0x11c67
movq %rax, 0xe(%rsp)
movl 0x4d38(%rip), %eax      # 0x11c6f
movl %eax, 0x16(%rsp)
movw 0x4d31(%rip), %ax       # 0x11c73
movw %ax, 0x1a(%rsp)
movl $0x51, %edi
callq 0x32f0
movq %rax, 0x78e0(%rip)      # 0x14838
movq 0x78d9(%rip), %rdi      # 0x14838
movl $0x51, %esi
leaq 0x4d2c(%rip), %rdx      # 0x11c97
leaq 0x4d69(%rip), %rcx      # 0x11cdb
movb $0x0, %al
callq 0x3180
movl $0x0, 0x78ad(%rip)      # 0x14830
leaq -0x1b4a(%rip), %rax     # 0xb440
movq %rax, 0x78af(%rip)      # 0x14840
leaq 0x7828(%rip), %rax      # 0x147c0
movq %rax, 0x78a9(%rip)      # 0x14848
movl $0x1, 0x78a7(%rip)      # 0x14850
movl $0x0, 0x78a1(%rip)      # 0x14854
movl $0x1, 0x789b(%rip)      # 0x14858
movq $0x0, 0x7898(%rip) # 0x14860
movl 0x34(%rsp), %edi
movq 0x28(%rsp), %rsi
leaq 0xe(%rsp), %rdx
leaq 0x76c3(%rip), %rcx      # 0x146a0
leaq 0x1c(%rsp), %r8
callq 0x3170
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x20(%rsp)
jge 0xcff7
jmp 0xd43f
movl 0x20(%rsp), %eax
addl $-0x61, %eax
movl %eax, %ecx
movq %rcx, (%rsp)
subl $0x15, %eax
ja 0xd418
movq (%rsp), %rax
leaq 0x48e0(%rip), %rcx      # 0x118f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, 0x7805(%rip)      # 0x14830
jmp 0xd43a
callq 0xcd30
xorl %edi, %edi
callq 0x33e0
movq 0x6f85(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x43c7(%rip), %rsi      # 0x11414
callq 0x3260
cmpl $0x0, %eax
je 0xd072
movq 0x6f6a(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4c79(%rip), %rsi      # 0x11ce1
callq 0x3260
cmpl $0x0, %eax
jne 0xd085
leaq -0x1de9(%rip), %rax     # 0xb290
movq %rax, 0x77c0(%rip)      # 0x14840
jmp 0xd43a
movq 0x6f3c(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x43b2(%rip), %rsi      # 0x11448
callq 0x3260
cmpl $0x0, %eax
je 0xd0bb
movq 0x6f21(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4c34(%rip), %rsi      # 0x11ce5
callq 0x3260
cmpl $0x0, %eax
jne 0xd0ce
leaq -0x1c82(%rip), %rax     # 0xb440
movq %rax, 0x7777(%rip)      # 0x14840
jmp 0xd43a
movq 0x6ef3(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x43cc(%rip), %rsi      # 0x114ab
callq 0x3260
cmpl $0x0, %eax
jne 0xd0fc
leaq -0x1bb0(%rip), %rax     # 0xb540
movq %rax, 0x7749(%rip)      # 0x14840
jmp 0xd43a
movq 0x6ec5(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x43d8(%rip), %rsi      # 0x114e5
callq 0x3260
cmpl $0x0, %eax
jne 0xd12a
leaq -0x19ae(%rip), %rax     # 0xb770
movq %rax, 0x771b(%rip)      # 0x14840
jmp 0xd43a
movq 0x6e97(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x2a04(%rip), %rsi      # 0xfb3f
callq 0x3260
cmpl $0x0, %eax
je 0xd17b
movq 0x6e7c(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4b2d(%rip), %rsi      # 0x11c83
callq 0x3260
cmpl $0x0, %eax
je 0xd17b
movq 0x6e61(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4b7d(%rip), %rsi      # 0x11cee
callq 0x3260
cmpl $0x0, %eax
jne 0xd18e
leaq -0x1532(%rip), %rax     # 0xbc50
movq %rax, 0x76b7(%rip)      # 0x14840
jmp 0xd43a
movq 0x6e33(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4b56(%rip), %rsi      # 0x11cf5
callq 0x3260
cmpl $0x0, %eax
je 0xd1c4
movq 0x6e18(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4b40(%rip), %rsi      # 0x11cfa
callq 0x3260
cmpl $0x0, %eax
jne 0xd1d7
leaq -0x152b(%rip), %rax     # 0xbca0
movq %rax, 0x766e(%rip)      # 0x14840
jmp 0xd43a
movq 0x6e1a(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
movq 0x6de0(%rip), %rax      # 0x13fc8
movq (%rax), %rdx
leaq 0x4b0e(%rip), %rsi      # 0x11d00
movb $0x0, %al
callq 0x3270
movl $0x16, %edi
callq 0x33e0
movq 0x6dbe(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4b0e(%rip), %rsi      # 0x11d22
callq 0x3260
cmpl $0x0, %eax
je 0xd239
movq 0x6da3(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4afc(%rip), %rsi      # 0x11d2b
callq 0x3260
cmpl $0x0, %eax
jne 0xd24c
leaq 0x7580(%rip), %rax      # 0x147c0
movq %rax, 0x7601(%rip)      # 0x14848
jmp 0xd43a
movq 0x6d75(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4ad6(%rip), %rsi      # 0x11d33
callq 0x3260
cmpl $0x0, %eax
jne 0xd27a
leaq 0x756a(%rip), %rax      # 0x147d8
movq %rax, 0x75d3(%rip)      # 0x14848
jmp 0xd43a
movq 0x6d77(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
movq 0x6d3d(%rip), %rax      # 0x13fc8
movq (%rax), %rdx
leaq 0x4aa4(%rip), %rsi      # 0x11d39
movb $0x0, %al
callq 0x3270
movl $0x16, %edi
callq 0x33e0
movq 0x6d1b(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4bb5(%rip), %rsi      # 0x11e6c
leaq 0x7572(%rip), %rdx      # 0x14830
addq $0x20, %rdx
movb $0x0, %al
callq 0x3300
cmpl $0x1, %eax
jne 0xd2d7
cmpl $0x1, 0x757b(%rip)      # 0x14850
jge 0xd2f9
movq 0x6d1a(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x4a6c(%rip), %rsi      # 0x11d54
movb $0x0, %al
callq 0x3270
movl $0x16, %edi
callq 0x33e0
jmp 0xd43a
movl $0x1, 0x754c(%rip)      # 0x14854
jmp 0xd43a
movq 0x6cb4(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x2081(%rip), %rsi      # 0xf39f
callq 0x3260
cmpl $0x0, %eax
je 0xd343
movq 0x6c99(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4a52(%rip), %rsi      # 0x11d8b
callq 0x3260
cmpl $0x0, %eax
jne 0xd352
movl $0x0, 0x750b(%rip)      # 0x14858
jmp 0xd43a
movq 0x6c6f(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x21d5(%rip), %rsi      # 0xf538
callq 0x3260
cmpl $0x0, %eax
je 0xd388
movq 0x6c54(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4a11(%rip), %rsi      # 0x11d8f
callq 0x3260
cmpl $0x0, %eax
jne 0xd397
movl $0x1, 0x74c6(%rip)      # 0x14858
jmp 0xd43a
movq 0x6c2a(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x4140(%rip), %rsi      # 0x114e8
callq 0x3260
cmpl $0x0, %eax
je 0xd3cd
movq 0x6c0f(%rip), %rax      # 0x13fc8
movq (%rax), %rdi
leaq 0x49d1(%rip), %rsi      # 0x11d94
callq 0x3260
cmpl $0x0, %eax
jne 0xd3d9
movl $0x2, 0x7481(%rip)      # 0x14858
jmp 0xd43a
movq 0x6c18(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
movq 0x6bde(%rip), %rax      # 0x13fc8
movq (%rax), %rdx
leaq 0x49a4(%rip), %rsi      # 0x11d98
movb $0x0, %al
callq 0x3270
movl $0x16, %edi
callq 0x33e0
movq 0x6bbc(%rip), %rax      # 0x13fc8
movq (%rax), %rax
movq %rax, 0x744a(%rip)      # 0x14860
jmp 0xd43a
movq 0x6bd9(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x4998(%rip), %rsi      # 0x11dc1
movb $0x0, %al
callq 0x3270
movl $0x16, %edi
callq 0x33e0
jmp 0xcfc8
movq 0x6b6a(%rip), %rax      # 0x13fb0
movl (%rax), %eax
addq $0x38, %rsp
retq
nopl (%rax)