// File: /workspace/github_c_makefile_star2_O0/sTeeLM[P]dwipe/method.c
// Function: dwipe_ops2
int dwipe_ops2( DWIPE_METHOD_SIGNATURE )
{
/**
 *  Royal Canadian Mounted Police
 *  Technical Security Standard for Information Technology
 *  Appendix OPS-II: Media Sanitization
 *
 *  NOTE: The last pass of this method is specially handled by dwipe_runmethod. 
 *
 */

	/* A generic array index. */
	int i;

	/* A generic result buffer. */
	int r;

	/* A buffer for random characters. */
	char* s;

	/* A buffer for the bitwise complements of 's'. */
	char* t;

	/* The element count of 's' and 't'. */
	u32 u;

	/* The pattern array for this method is dynamically allocated. */
	dwipe_pattern_t* patterns;

	/* The element count of 'patterns'. */
	u32 q;


	/* We need one random character per round. */
	u = 1 * dwipe_options.rounds;

	/* Allocate the array of random characters. */
	s = malloc( sizeof( char ) * u );

	if( s == NULL )
	{
		dwipe_perror( errno, __FUNCTION__, "malloc" );
		dwipe_log( DWIPE_LOG_FATAL, "Unable to allocate the random character array." );
		return -1;
	}

	/* Allocate the array of complement characters. */
	t = malloc( sizeof( char ) * u );

	if( s == NULL )
	{
		dwipe_perror( errno, __FUNCTION__, "malloc" );
		dwipe_log( DWIPE_LOG_FATAL, "Unable to allocate the complement character array." );
		return -1;
	}


	/* We need eight pattern elements per round, plus one for padding. */
	q = 8 * u + 1;

	/* Allocate the pattern array. */
	patterns = malloc( sizeof( dwipe_pattern_t ) * q );

	if( patterns == NULL )
	{
		dwipe_perror( errno, __FUNCTION__, "malloc" );
		dwipe_log( DWIPE_LOG_FATAL, "Unable to allocate the pattern array." );
		return -1;
	}


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

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


	for( i = 0 ; i < u ; i += 1 )
	{
		/* Populate the array of complements. */
		t[i] = ~s[i];
	}


	for( i = 0 ; i < u ; i += 8 )
	{
		/* Populate the array of patterns. */

		/* Even elements point to the random characters. */
		patterns[i*4 +0].length = 1;
		patterns[i*4 +0].s = &s[i];
		patterns[i*4 +2].length = 1;
		patterns[i*4 +2].s = &s[i];
		patterns[i*4 +4].length = 1;
		patterns[i*4 +4].s = &s[i];
		patterns[i*4 +6].length = 1;
		patterns[i*4 +6].s = &s[i];

		/* Odd elements point to the complement characters. */
		patterns[i*4 +1].length = 1;
		patterns[i*4 +1].s = &t[i];
		patterns[i*4 +3].length = 1;
		patterns[i*4 +3].s = &t[i];
		patterns[i*4 +5].length = 1;
		patterns[i*4 +5].s = &t[i];
		patterns[i*4 +7].length = 1;
		patterns[i*4 +7].s = &t[i];
	}

	/* Ensure that the array is terminated. */
	patterns[q-1].length = 0;
	patterns[q-1].s = NULL;
	
	/* Run the TSSIT OPS-II method. */
	r = dwipe_runmethod( c, patterns );

	/* Release the random character buffer. */
	free( s );

	/* Release the complement character buffer */
	free( t );

	/* Release the pattern buffer. */
	free( patterns );

	/* We're done. */
	return r;

}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
leaq 0x90b0(%rip), %rax      # 0x14830
movl 0x20(%rax), %eax
shll $0x0, %eax
cltq
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
shlq $0x0, %rdi
callq 0x32f0
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0xb7e2
callq 0x3070
movl (%rax), %edi
leaq 0x5d29(%rip), %rsi      # 0x114df
leaq 0x440c(%rip), %rdx      # 0xfbc9
callq 0xb160
movl $0x6, %edi
leaq 0x5d1c(%rip), %rsi      # 0x114ea
movb $0x0, %al
callq 0xade0
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0xbc47
movq 0x18(%rsp), %rdi
shlq $0x0, %rdi
callq 0x32f0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0xb837
callq 0x3070
movl (%rax), %edi
leaq 0x5cd4(%rip), %rsi      # 0x114df
leaq 0x43b7(%rip), %rdx      # 0xfbc9
callq 0xb160
movl $0x6, %edi
leaq 0x5cf6(%rip), %rsi      # 0x11519
movb $0x0, %al
callq 0xade0
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0xbc47
movq 0x18(%rsp), %rax
shlq $0x3, %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
shlq $0x4, %rdi
callq 0x32f0
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0xb89e
callq 0x3070
movl (%rax), %edi
leaq 0x5c6d(%rip), %rsi      # 0x114df
leaq 0x4350(%rip), %rdx      # 0xfbc9
callq 0xb160
movl $0x6, %edi
leaq 0x5cc2(%rip), %rsi      # 0x1154c
movb $0x0, %al
callq 0xade0
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0xbc47
movq 0x38(%rsp), %rax
movl 0x2d8(%rax), %edi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x3230
movl %eax, 0x30(%rsp)
movslq 0x30(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0xb925
callq 0x3070
movl (%rax), %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %edi
leaq 0x5c01(%rip), %rsi      # 0x114df
leaq 0x5b3a(%rip), %rdx      # 0x1141f
callq 0xb160
movq 0x8d87(%rip), %rdx      # 0x14678
movl $0x6, %edi
leaq 0x5b27(%rip), %rsi      # 0x11424
movb $0x0, %al
callq 0xade0
cmpl $0x0, 0x30(%rsp)
jge 0xb918
movl 0x30(%rsp), %eax
movl %eax, 0x44(%rsp)
jmp 0xbc47
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0xbc47
movl $0x0, 0x34(%rsp)
movslq 0x34(%rsp), %rax
cmpq 0x18(%rsp), %rax
jae 0xb966
movq 0x28(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
xorl $-0x1, %eax
movb %al, %dl
movq 0x20(%rsp), %rax
movslq 0x34(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0xb92d
movl $0x0, 0x34(%rsp)
movslq 0x34(%rsp), %rax
cmpq 0x18(%rsp), %rax
jae 0xbbd6
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq 0x28(%rsp), %rcx
movslq 0x34(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %edx
shll $0x2, %edx
addl $0x0, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq 0x28(%rsp), %rcx
movslq 0x34(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %edx
shll $0x2, %edx
addl $0x2, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %ecx
shll $0x2, %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq 0x28(%rsp), %rcx
movslq 0x34(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %edx
shll $0x2, %edx
addl $0x4, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %ecx
shll $0x2, %ecx
addl $0x6, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq 0x28(%rsp), %rcx
movslq 0x34(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %edx
shll $0x2, %edx
addl $0x6, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq 0x20(%rsp), %rcx
movslq 0x34(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %edx
shll $0x2, %edx
addl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq 0x20(%rsp), %rcx
movslq 0x34(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %edx
shll $0x2, %edx
addl $0x3, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %ecx
shll $0x2, %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq 0x20(%rsp), %rcx
movslq 0x34(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %edx
shll $0x2, %edx
addl $0x5, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %ecx
shll $0x2, %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq 0x20(%rsp), %rcx
movslq 0x34(%rsp), %rax
addq %rax, %rcx
movq 0x10(%rsp), %rax
movl 0x34(%rsp), %edx
shll $0x2, %edx
addl $0x7, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl 0x34(%rsp), %eax
addl $0x8, %eax
movl %eax, 0x34(%rsp)
jmp 0xb96e
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
subq $0x1, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
subq $0x1, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xbcd0
movl %eax, 0x30(%rsp)
movq 0x28(%rsp), %rdi
callq 0x3060
movq 0x20(%rsp), %rdi
callq 0x3060
movq 0x10(%rsp), %rdi
callq 0x3060
movl 0x30(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq