// File: /workspace/github_c_makefile_star2_O0/sTeeLM[P]dwipe/method.c
// Function: dwipe_gutmann
int dwipe_gutmann( DWIPE_METHOD_SIGNATURE )
{
/**
 * Peter Gutmann's wipe.
 *
 */

	/* A result buffer. */
	int r;

	/* The number of patterns in the Guttman Wipe, also used to index the 'patterns' array. */
	int i = 35;

	/* An index into the 'book' array. */
	int j;

	/* The N-th element that has not been used. */
	int n;

	/* Define the Gutmann method. */
	dwipe_pattern_t book [] =
	{
		{ -1, ""             }, /* Random pass.                                      */
		{ -1, ""             }, /* Random pass.                                      */
		{ -1, ""             }, /* Random pass.                                      */
		{ -1, ""             }, /* Random pass.                                      */
		{  3, "\x55\x55\x55" }, /* Static pass: 0x555555  01010101 01010101 01010101 */
		{  3, "\xAA\xAA\xAA" }, /* Static pass: 0XAAAAAA  10101010 10101010 10101010 */
		{  3, "\x92\x49\x24" }, /* Static pass: 0x924924  10010010 01001001 00100100 */
		{  3, "\x49\x24\x92" }, /* Static pass: 0x492492  01001001 00100100 10010010 */
		{  3, "\x24\x92\x49" }, /* Static pass: 0x249249  00100100 10010010 01001001 */
		{  3, "\x00\x00\x00" }, /* Static pass: 0x000000  00000000 00000000 00000000 */
		{  3, "\x11\x11\x11" }, /* Static pass: 0x111111  00010001 00010001 00010001 */
		{  3, "\x22\x22\x22" }, /* Static pass: 0x222222  00100010 00100010 00100010 */
		{  3, "\x33\x33\x33" }, /* Static pass: 0x333333  00110011 00110011 00110011 */
		{  3, "\x44\x44\x44" }, /* Static pass: 0x444444  01000100 01000100 01000100 */
		{  3, "\x55\x55\x55" }, /* Static pass: 0x555555  01010101 01010101 01010101 */
		{  3, "\x66\x66\x66" }, /* Static pass: 0x666666  01100110 01100110 01100110 */
		{  3, "\x77\x77\x77" }, /* Static pass: 0x777777  01110111 01110111 01110111 */
		{  3, "\x88\x88\x88" }, /* Static pass: 0x888888  10001000 10001000 10001000 */
		{  3, "\x99\x99\x99" }, /* Static pass: 0x999999  10011001 10011001 10011001 */
		{  3, "\xAA\xAA\xAA" }, /* Static pass: 0xAAAAAA  10101010 10101010 10101010 */
		{  3, "\xBB\xBB\xBB" }, /* Static pass: 0xBBBBBB  10111011 10111011 10111011 */
		{  3, "\xCC\xCC\xCC" }, /* Static pass: 0xCCCCCC  11001100 11001100 11001100 */
		{  3, "\xDD\xDD\xDD" }, /* Static pass: 0xDDDDDD  11011101 11011101 11011101 */
		{  3, "\xEE\xEE\xEE" }, /* Static pass: 0xEEEEEE  11101110 11101110 11101110 */
		{  3, "\xFF\xFF\xFF" }, /* Static pass: 0xFFFFFF  11111111 11111111 11111111 */
		{  3, "\x92\x49\x24" }, /* Static pass: 0x924924  10010010 01001001 00100100 */
		{  3, "\x49\x24\x92" }, /* Static pass: 0x492492  01001001 00100100 10010010 */
		{  3, "\x24\x92\x49" }, /* Static pass: 0x249249  00100100 10010010 01001001 */
		{  3, "\x6D\xB6\xDB" }, /* Static pass: 0x6DB6DB  01101101 10110110 11011011 */
		{  3, "\xB6\xDB\x6D" }, /* Static pass: 0xB6DB6D  10110110 11011011 01101101 */
		{  3, "\xDB\x6D\xB6" }, /* Static pass: 0XDB6DB6  11011011 01101101 10110110 */
		{ -1, ""             }, /* Random pass.                                      */
		{ -1, ""             }, /* Random pass.                                      */
		{ -1, ""             }, /* Random pass.                                      */
		{ -1, ""             }, /* Random pass.                                      */
		{ 0, NULL }
	};

	/* Put the book array into this array in random order. */
	dwipe_pattern_t patterns [36];

	/* An entropy buffer. */
	u16 s [i];

	/* Load the array with random characters. */
	r = read( c->entropy_fd, &s, sizeof( s ) );

	if( r != sizeof( s ) )
	{
		r = errno;
		dwipe_perror( r, __FUNCTION__, "read" );
		dwipe_log( DWIPE_LOG_FATAL, "Unable to seed the %s method.", dwipe_gutmann_label );
		
		/* Ensure a negative return. */
		if( r < 0 ) { return  r; }
		else        { return -1; }
	}


	while( --i >= 0 )
	{

		/* Get a random integer that is less than the first index 'i'. */
		n = (int)( (double)( s[i] ) / (double)( 0x0000FFFF + 1 ) * (double)( i + 1 ) );

		/* Initialize the secondary index. */
		j = -1;

		while( n-- >= 0 )
		{
			/* Advance 'j' by 'n' positions... */
			j += 1;

			/* ... but don't count 'book' elements that have already been copied. */
			while( book[j].length == 0 ) { j += 1; }
		}

		/* Copy the element. */
		patterns[i] = book[j];

		/* Mark this element as having been used. */
		book[j].length = 0;

		dwipe_log( DWIPE_LOG_DEBUG, "dwipe_gutmann: Set patterns[%i] = book[%i].", i, j );
	}

	/* Ensure that the array is terminated. */
	patterns[35].length = 0;
	patterns[35].s = NULL;

	/* Run the Gutmann method. */
	return dwipe_runmethod( c, patterns );

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4d0, %rsp            # imm = 0x4D0
movq %rdi, -0x10(%rbp)
movl $0x23, -0x18(%rbp)
leaq 0x85d3(%rip), %rsi      # 0x13b30
leaq -0x260(%rbp), %rdi
movl $0x240, %edx            # imm = 0x240
callq 0x3290
movl -0x18(%rbp), %eax
movl %eax, %edx
movq %rdx, -0x4c0(%rbp)
movq %rsp, %rax
movq %rax, -0x4a8(%rbp)
leaq 0xf(%rdx,%rdx), %rax
andq $-0x10, %rax
movq %rsp, %rsi
subq %rax, %rsi
movq %rsi, -0x4c8(%rbp)
movq %rsi, %rsp
movq %rdx, -0x4b0(%rbp)
movq -0x10(%rbp), %rax
movl 0x2d8(%rax), %edi
shlq %rdx
callq 0x3230
movq -0x4c0(%rbp), %rcx
movl %eax, -0x14(%rbp)
movslq -0x14(%rbp), %rax
shlq %rcx
cmpq %rcx, %rax
je 0xb637
callq 0x3070
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edi
leaq 0x5ec5(%rip), %rsi      # 0x114a5
leaq 0x5e38(%rip), %rdx      # 0x1141f
callq 0xb160
movq 0x907d(%rip), %rdx      # 0x14670
movl $0x6, %edi
leaq 0x5e25(%rip), %rsi      # 0x11424
movb $0x0, %al
callq 0xade0
cmpl $0x0, -0x14(%rbp)
jge 0xb621
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x4b4(%rbp)
jmp 0xb75d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x4b4(%rbp)
jmp 0xb75d
jmp 0xb639
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
jl 0xb72b
movq -0x4c8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
cvtsi2sd %eax, %xmm0
movsd 0x5d3a(%rip), %xmm1     # 0x113a0
divsd %xmm1, %xmm0
movl -0x18(%rbp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x20(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl -0x20(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x20(%rbp)
cmpl $0x0, %eax
jl 0xb6c3
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movslq -0x1c(%rbp), %rcx
leaq -0x260(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0xb6c1
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xb69f
jmp 0xb686
movslq -0x18(%rbp), %rcx
leaq -0x4a0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x1c(%rbp), %rdx
leaq -0x260(%rbp), %rcx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movslq -0x1c(%rbp), %rcx
leaq -0x260(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x1, %edi
leaq 0x5d94(%rip), %rsi      # 0x114b3
movb $0x0, %al
callq 0xade0
jmp 0xb639
movl $0x0, -0x270(%rbp)
movq $0x0, -0x268(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x4a0(%rbp), %rsi
callq 0xbcd0
movl %eax, -0x4(%rbp)
movl $0x1, -0x4b4(%rbp)
movq -0x4a8(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nop