// File: stacksmith[P]picoasm/cassembler.cpp
// Function: CAssembler::exportVHDL(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
bool CAssembler::exportVHDL( string templateFile, string outputDir, string entityName, bool bVHDL)
{
	int addr, i, j, k, l, n ;
	unsigned char INIT[ 32 ][ 64 ] ;		/* 32 * 64 = 2048 bytes */
	unsigned char INITP[ 32 ][ 8 ] ;		/* 32 * 8 =   256 bytes */
	unsigned int d ;                        /*			 2304 Bytes Total = (18b * 1024 ) / 8 (1 instr = 18 bits )*/
	
	CInstruction *instr ;
	
	// ajg112 - Open Mem file
	string memFileName = outputDir + "/" + entityName + ".mem";
	FILE * memFile = fopen( memFileName.c_str(), "w" ) ;		
	if (memFile == NULL) {
		error(NO_LINE_NR, string( "Unable to open mem file '" + memFileName + "'" ).c_str());
		return FALSE ;
	}

	// ajg112 - Specify start address
	fprintf(memFile, "@0\n");

	for ( i = 0 ; i < 32 ; i++ )
		for( j = 0 ; j < 32 ; j++ )
			INIT[ i ][ j ] = 0 ;
			
	for ( i = 0 ; i < 32 ; i++ )
		for ( j = 0 ; j < 8 ; j++ )
			INITP[ i ][ j ] = 0 ;
	
	for ( addr = i = j = k = l = 0, n = 0 ; addr < 1024 ; addr++ ) {			
		instr = m_code->getInstruction( addr ) ;
		
		if ( instr == NULL ) d = 0 ;
		else d = instr->getHexCode() ;

		//cout << d <<"\n";

		// ajg112 - Output memory value
		fprintf(memFile, "%05X\n", d);
						
		INIT[ i++ ][ j ] =  d ;		// instruction( 15 downto 0 )
		INIT[ i++ ][ j ] =  d >> 8;
		
		INITP[ k ][ l ] |= ( ( d >> 16 ) & 0x3 ) << n ;	// instruction( 17 downto 16 ) ;
		n += 2 ;
				
		if ( n >= 8 ) {
			n = 0 ;
			k++ ;
			if ( k >= 32 ) {
				l++ ;
				k = 0 ;
			}
		}
		
		if ( i >= 32 ) {
			i = 0 ;
			j++ ;
		}
	}

	// ajg112 - Close Mem File
	fclose(memFile);
	
	FILE * infile = fopen( templateFile.c_str(), "r" ) ;
	if ( infile == NULL ) {
		error( NO_LINE_NR, string( "Unable to open template file '" + templateFile + "'" ).c_str() ) ;
		return FALSE ;
	}

	// RDC 02/02/2007 set VHDL or verilog file extension
	string exportExt;
	if (bVHDL){
	  exportExt = ".vhd"; 
	} else {
	  exportExt = ".v"; 
	}

	// RDC 02/02/2007 set VHDL or verilog file extension
	// string exportFile = outputDir + "/" + entityName + ".vhd" ;
	string exportFile = outputDir + "/" + entityName + exportExt;

	FILE * outfile = fopen( exportFile.c_str(), "w" ) ;		
	if ( outfile == NULL ) {
	  // RDC 02/02/2007 set VHDL or verilog file extension
	  // error( NO_LINE_NR , string( "Unable to open output file '" + exportFile + ".vhd'").c_str() ) ;
	  error( NO_LINE_NR , string( "Unable to open output file '" + exportFile + exportExt + "'").c_str() ) ;
	  return FALSE ;
	}
		
	bool store = false, copy = false;
	char varname[ 64 ] ;
	int p = 0 ;
	int line, c ;
	while ( ( c = fgetc( infile ) ) != EOF ) {
		if ( store && p < 64 )
			varname[ p++ ] = c ;
		
		if ( c == '{' ) {
			store = true ;		
			p = 0 ;
		}
		
		if ( !store && copy )
			fputc( c, outfile ) ;
		
		if ( c == '}' ) {
			store = false ;
			if ( p > 0 )
				varname[ p - 1 ] = '\0' ;
			else
				varname[ 0 ] = '\0' ;
			if ( strncmp( "INIT_", varname, 5 ) == 0 ) {
				sscanf( varname, "INIT_%02X", &line ) ;
				if ( line >= 0 && line < 64 ) {
					for( j = 31 ; j >= 0 ; j-- ) 
						fprintf( outfile, "%02X", INIT[ j ][ line ] ) ;
				}
			} else if ( strncmp( "INITP_", varname, 6 ) == 0 ) {
				sscanf( varname, "INITP_%02X", &line ) ;
				if ( line >= 0 && line < 8 ) 
					for( j = 31 ; j >= 0 ; j-- )
		 				fprintf( outfile, "%02X", INITP[ j ][ line ] ) ;
			} else if ( strcmp( "name", varname ) == 0 ) {
				fprintf( outfile, entityName.c_str() ) ;				
			} else if ( strcmp( "begin template", varname ) == 0 ) {
				copy = true ;
			}
		}
	}
		
	fclose( infile ) ;
	fclose( outfile ) ;
	
	return TRUE ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc10, %rsp            # imm = 0xC10
movq %rcx, -0xbb8(%rbp)
movq %rdx, -0xbd8(%rbp)
movq %rsi, %rdx
movq -0xbd8(%rbp), %rsi
movq %rdx, -0xbd0(%rbp)
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xbc8(%rbp)
leaq 0x189368(%rip), %rdx    # 0x5921dc
leaq -0x9c0(%rbp), %rdi
movq %rdi, -0xbc0(%rbp)
callq 0x40abd0
movq -0xbc0(%rbp), %rsi
movq -0xbb8(%rbp), %rdx
leaq -0x9a0(%rbp), %rdi
callq 0x40ab80
jmp 0x408ea3
leaq 0x1829fe(%rip), %rdx    # 0x58b8a8
leaq -0x980(%rbp), %rdi
leaq -0x9a0(%rbp), %rsi
callq 0x40a730
jmp 0x408ebf
leaq -0x9a0(%rbp), %rdi
callq 0x485ad0
leaq -0x9c0(%rbp), %rdi
callq 0x485ad0
leaq -0x980(%rbp), %rdi
callq 0x487510
movq %rax, %rdi
leaq 0x186c5c(%rip), %rsi    # 0x58fb49
callq 0x4ed120
movq %rax, -0xbe0(%rbp)
jmp 0x408efb
movq -0xbe0(%rbp), %rax
movq %rax, -0x9d8(%rbp)
cmpq $0x0, -0x9d8(%rbp)
jne 0x409039
leaq 0x18298f(%rip), %rsi    # 0x58b8ad
leaq -0xa18(%rbp), %rdi
leaq -0x980(%rbp), %rdx
callq 0x40ac50
jmp 0x408f33
leaq 0x18242f(%rip), %rdx    # 0x58b369
leaq -0x9f8(%rbp), %rdi
leaq -0xa18(%rbp), %rsi
callq 0x40a730
jmp 0x408f4f
leaq -0x9f8(%rbp), %rdi
callq 0x487510
movq -0xbc8(%rbp), %rdi
movq %rax, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x405dc0
jmp 0x408f71
leaq -0x9f8(%rbp), %rdi
callq 0x485ad0
leaq -0xa18(%rbp), %rdi
callq 0x485ad0
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa1c(%rbp)
jmp 0x4098f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x408fce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
leaq -0x9a0(%rbp), %rdi
callq 0x485ad0
leaq -0x9c0(%rbp), %rdi
callq 0x485ad0
jmp 0x40991f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x409913
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x409028
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
leaq -0x9f8(%rbp), %rdi
callq 0x485ad0
leaq -0xa18(%rbp), %rdi
callq 0x485ad0
jmp 0x409913
movq -0x9d8(%rbp), %rdi
leaq 0x182880(%rip), %rsi    # 0x58b8c7
movb $0x0, %al
callq 0x4de2a0
movl $0x0, -0x34(%rbp)
cmpl $0x20, -0x34(%rbp)
jge 0x40909a
movl $0x0, -0x38(%rbp)
cmpl $0x20, -0x38(%rbp)
jge 0x40908d
movslq -0x34(%rbp), %rcx
leaq -0x850(%rbp), %rax
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x409062
jmp 0x40908f
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x409055
movl $0x0, -0x34(%rbp)
cmpl $0x20, -0x34(%rbp)
jge 0x4090e6
movl $0x0, -0x38(%rbp)
cmpl $0x8, -0x38(%rbp)
jge 0x4090d9
movslq -0x34(%rbp), %rcx
leaq -0x950(%rbp), %rax
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4090ae
jmp 0x4090db
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4090a1
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x400, -0x30(%rbp)     # imm = 0x400
jge 0x409282
movq -0xbc8(%rbp), %rax
movq 0x80(%rax), %rdi
movzwl -0x30(%rbp), %esi
callq 0x413a30
movq %rax, -0xbe8(%rbp)
jmp 0x40913d
movq -0xbe8(%rbp), %rax
movq %rax, -0x960(%rbp)
cmpq $0x0, -0x960(%rbp)
jne 0x409161
movl $0x0, -0x954(%rbp)
jmp 0x409181
movq -0x960(%rbp), %rdi
callq 0x405960
movl %eax, -0xbec(%rbp)
jmp 0x409175
movl -0xbec(%rbp), %eax
movl %eax, -0x954(%rbp)
movq -0x9d8(%rbp), %rdi
movl -0x954(%rbp), %edx
leaq 0x182736(%rip), %rsi    # 0x58b8cb
movb $0x0, %al
callq 0x4de2a0
movl -0x954(%rbp), %eax
movb %al, %dl
movl -0x34(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp)
movslq %eax, %rcx
leaq -0x850(%rbp), %rax
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x954(%rbp), %eax
shrl $0x8, %eax
movb %al, %dl
movl -0x34(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp)
movslq %eax, %rcx
leaq -0x850(%rbp), %rax
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x954(%rbp), %esi
shrl $0x10, %esi
andl $0x3, %esi
movl -0x44(%rbp), %ecx
shll %cl, %esi
movslq -0x3c(%rbp), %rcx
leaq -0x950(%rbp), %rax
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x44(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x44(%rbp)
cmpl $0x8, -0x44(%rbp)
jl 0x40925c
movl $0x0, -0x44(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x20, -0x3c(%rbp)
jl 0x40925a
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
jmp 0x40925c
cmpl $0x20, -0x34(%rbp)
jl 0x409272
movl $0x0, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x409274
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x409110
movq -0x9d8(%rbp), %rdi
callq 0x4ec890
jmp 0x409290
movq -0xbd0(%rbp), %rdi
callq 0x487510
movq %rax, %rdi
leaq 0x1872f9(%rip), %rsi    # 0x59059f
callq 0x4ed120
movq %rax, -0xbf8(%rbp)
jmp 0x4092b4
movq -0xbf8(%rbp), %rax
movq %rax, -0xa28(%rbp)
cmpq $0x0, -0xa28(%rbp)
jne 0x409398
movq -0xbd0(%rbp), %rdx
leaq 0x1825f3(%rip), %rsi    # 0x58b8d1
leaq -0xa68(%rbp), %rdi
callq 0x40ac50
jmp 0x4092ec
leaq 0x182076(%rip), %rdx    # 0x58b369
leaq -0xa48(%rbp), %rdi
leaq -0xa68(%rbp), %rsi
callq 0x40a730
jmp 0x409308
leaq -0xa48(%rbp), %rdi
callq 0x487510
movq -0xbc8(%rbp), %rdi
movq %rax, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x405dc0
jmp 0x40932a
leaq -0xa48(%rbp), %rdi
callq 0x485ad0
leaq -0xa68(%rbp), %rdi
callq 0x485ad0
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa1c(%rbp)
jmp 0x4098f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x409387
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
leaq -0xa48(%rbp), %rdi
callq 0x485ad0
leaq -0xa68(%rbp), %rdi
callq 0x485ad0
jmp 0x409913
leaq -0xa88(%rbp), %rdi
callq 0x4859c0
testb $0x1, -0x29(%rbp)
je 0x4093d8
leaq 0x181f30(%rip), %rsi    # 0x58b2e1
leaq -0xa88(%rbp), %rdi
callq 0x486b20
jmp 0x4093bf
jmp 0x4093ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x4098eb
leaq 0x181dc6(%rip), %rsi    # 0x58b1a5
leaq -0xa88(%rbp), %rdi
callq 0x486b20
jmp 0x4093ed
jmp 0x4093ef
movq -0xbd8(%rbp), %rsi
leaq 0x188ddf(%rip), %rdx    # 0x5921dc
leaq -0xae8(%rbp), %rdi
callq 0x40abd0
jmp 0x40940b
movq -0xbb8(%rbp), %rdx
leaq -0xac8(%rbp), %rdi
leaq -0xae8(%rbp), %rsi
callq 0x40ab80
jmp 0x409427
leaq -0xaa8(%rbp), %rdi
leaq -0xac8(%rbp), %rsi
leaq -0xa88(%rbp), %rdx
callq 0x40ab80
jmp 0x409443
leaq -0xac8(%rbp), %rdi
callq 0x485ad0
leaq -0xae8(%rbp), %rdi
callq 0x485ad0
leaq -0xaa8(%rbp), %rdi
callq 0x487510
movq %rax, %rdi
leaq 0x1866d8(%rip), %rsi    # 0x58fb49
callq 0x4ed120
movq %rax, -0xc00(%rbp)
jmp 0x40947f
movq -0xc00(%rbp), %rax
movq %rax, -0xaf0(%rbp)
cmpq $0x0, -0xaf0(%rbp)
jne 0x409605
leaq 0x18244e(%rip), %rsi    # 0x58b8f0
leaq -0xb50(%rbp), %rdi
leaq -0xaa8(%rbp), %rdx
callq 0x40ac50
jmp 0x4094b7
leaq -0xb30(%rbp), %rdi
leaq -0xb50(%rbp), %rsi
leaq -0xa88(%rbp), %rdx
callq 0x40ab80
jmp 0x4094d3
leaq 0x181e8f(%rip), %rdx    # 0x58b369
leaq -0xb10(%rbp), %rdi
leaq -0xb30(%rbp), %rsi
callq 0x40a730
jmp 0x4094ef
leaq -0xb10(%rbp), %rdi
callq 0x487510
movq -0xbc8(%rbp), %rdi
movq %rax, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x405dc0
jmp 0x409511
leaq -0xb10(%rbp), %rdi
callq 0x485ad0
leaq -0xb30(%rbp), %rdi
callq 0x485ad0
leaq -0xb50(%rbp), %rdi
callq 0x485ad0
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa1c(%rbp)
jmp 0x4098c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x40957a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
leaq -0xac8(%rbp), %rdi
callq 0x485ad0
leaq -0xae8(%rbp), %rdi
callq 0x485ad0
jmp 0x4098eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x4098df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x4095f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
jmp 0x4095e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x9c8(%rbp)
movl %eax, -0x9cc(%rbp)
leaq -0xb10(%rbp), %rdi
callq 0x485ad0
leaq -0xb30(%rbp), %rdi
callq 0x485ad0
leaq -0xb50(%rbp), %rdi
callq 0x485ad0
jmp 0x4098df
movb $0x0, -0xb51(%rbp)
movb $0x0, -0xb52(%rbp)
movl $0x0, -0xba4(%rbp)
movq -0xa28(%rbp), %rdi
callq 0x4f17e0
movl %eax, -0xc04(%rbp)
jmp 0x409631
movl -0xc04(%rbp), %eax
movl %eax, -0xbac(%rbp)
cmpl $-0x1, %eax
je 0x40989b
testb $0x1, -0xb51(%rbp)
je 0x40967a
cmpl $0x40, -0xba4(%rbp)
jge 0x40967a
movl -0xbac(%rbp), %eax
movb %al, %cl
movl -0xba4(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0xba4(%rbp)
cltq
movb %cl, -0xba0(%rbp,%rax)
cmpl $0x7b, -0xbac(%rbp)
jne 0x409694
movb $0x1, -0xb51(%rbp)
movl $0x0, -0xba4(%rbp)
testb $0x1, -0xb51(%rbp)
jne 0x4096bc
testb $0x1, -0xb52(%rbp)
je 0x4096bc
movl -0xbac(%rbp), %edi
movq -0xaf0(%rbp), %rsi
callq 0x4f16a0
jmp 0x4096ba
jmp 0x4096bc
cmpl $0x7d, -0xbac(%rbp)
jne 0x409896
movb $0x0, -0xb51(%rbp)
cmpl $0x0, -0xba4(%rbp)
jle 0x4096ee
movl -0xba4(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0xba0(%rbp,%rax)
jmp 0x4096f5
movb $0x0, -0xba0(%rbp)
leaq -0xba0(%rbp), %rsi
leaq 0x18220a(%rip), %rdi    # 0x58b90d
movl $0x5, %edx
callq 0x401040
cmpl $0x0, %eax
jne 0x409791
leaq -0xba0(%rbp), %rdi
leaq 0x1821f3(%rip), %rsi    # 0x58b913
leaq -0xba8(%rbp), %rdx
movb $0x0, %al
callq 0x4de5c0
cmpl $0x0, -0xba8(%rbp)
jl 0x40978c
cmpl $0x40, -0xba8(%rbp)
jge 0x40978c
movl $0x1f, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jl 0x40978a
movq -0xaf0(%rbp), %rdi
movslq -0x38(%rbp), %rcx
leaq -0x850(%rbp), %rax
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0xba8(%rbp), %rcx
movzbl (%rax,%rcx), %edx
leaq 0x1821b2(%rip), %rsi    # 0x58b92a
movb $0x0, %al
callq 0x4de2a0
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x409747
jmp 0x40978c
jmp 0x409894
leaq -0xba0(%rbp), %rsi
leaq 0x18217e(%rip), %rdi    # 0x58b91d
movl $0x6, %edx
callq 0x401040
cmpl $0x0, %eax
jne 0x40982a
leaq -0xba0(%rbp), %rdi
leaq 0x182168(%rip), %rsi    # 0x58b924
leaq -0xba8(%rbp), %rdx
movb $0x0, %al
callq 0x4de5c0
cmpl $0x0, -0xba8(%rbp)
jl 0x409828
cmpl $0x8, -0xba8(%rbp)
jge 0x409828
movl $0x1f, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jl 0x409826
movq -0xaf0(%rbp), %rdi
movslq -0x38(%rbp), %rcx
leaq -0x950(%rbp), %rax
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0xba8(%rbp), %rcx
movzbl (%rax,%rcx), %edx
leaq 0x182116(%rip), %rsi    # 0x58b92a
movb $0x0, %al
callq 0x4de2a0
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4097e3
jmp 0x409828
jmp 0x409892
leaq -0xba0(%rbp), %rsi
leaq 0x1820f7(%rip), %rdi    # 0x58b92f
callq 0x401128
cmpl $0x0, %eax
jne 0x40986f
movq -0xbb8(%rbp), %rdi
movq -0xaf0(%rbp), %rax
movq %rax, -0xc10(%rbp)
callq 0x487510
movq -0xc10(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x4de2a0
jmp 0x409890
leaq -0xba0(%rbp), %rsi
leaq 0x1820b7(%rip), %rdi    # 0x58b934
callq 0x401128
cmpl $0x0, %eax
jne 0x40988e
movb $0x1, -0xb52(%rbp)
jmp 0x409890
jmp 0x409892
jmp 0x409894
jmp 0x409896
jmp 0x40961d
movq -0xa28(%rbp), %rdi
callq 0x4ec890
jmp 0x4098a9
movq -0xaf0(%rbp), %rdi
callq 0x4ec890
jmp 0x4098b7
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa1c(%rbp)
leaq -0xaa8(%rbp), %rdi
callq 0x485ad0
leaq -0xa88(%rbp), %rdi
callq 0x485ad0
jmp 0x4098f9
leaq -0xaa8(%rbp), %rdi
callq 0x485ad0
leaq -0xa88(%rbp), %rdi
callq 0x485ad0
jmp 0x409913
leaq -0x980(%rbp), %rdi
callq 0x485ad0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc10, %rsp            # imm = 0xC10
popq %rbp
retq
leaq -0x980(%rbp), %rdi
callq 0x485ad0
movq -0x9c8(%rbp), %rdi
callq 0x4b74e0
nopl (%rax,%rax)