// File: /workspace/github_cpp_makefile_star2_O2/minirop[P]JDecomqiler/src/ClassFile.cpp
// Function: ClassFile::ClassFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
ClassFile::ClassFile(std::string filename)
{
	std::ifstream file(filename, std::ios::in | std::ios::binary);
	if(!file.is_open())
		return;
	
	stream.setStream(&file);
	
	std::uint32_t magic;
	stream >> magic;
	if(magic != 0xcafebabe)
	{
		cout << "magic number is " << std::hex << magic << endl;
		return;
	}
	
	std::uint16_t major, minor;
	stream >> minor >> major;
	cout << "JAVA " << major << "." << minor << endl;
	
	std::uint16_t constant_pool_count;
	stream >> constant_pool_count;
	cout << constant_pool_count << " constants" << endl;
	
	constant_pool.push_back(CPinfo()); // index 0 is invalid
	for(std::size_t i = 1;i < constant_pool_count;i++)
	{
		if(parseConstant()) // return true if double or bigint
		{
			constant_pool.push_back(CPinfo()); // double and bigint use 2 indexes
			i++;
		}
	}
	
	std::uint16_t access_flags, this_class, super_class;
	stream >> access_flags >> this_class >> super_class;
	
	if(access_flags & ACC_PUBLIC)
		output.isPublic = true;
	if(access_flags & ACC_FINAL)
		output.isFinal = true;
	if(access_flags & ACC_SUPER)
		cout << "is super, ignored." << endl;
	if(access_flags & ACC_INTERFACE)
		output.isInterface = true;
	if(access_flags & ACC_ABSTRACT)
		output.isAbstract = true;
	if(access_flags & ACC_ANNOTATION)
		output.isAnnotation = true;
	if(access_flags & ACC_ENUM)
		output.isEnum = true;
	if(access_flags & (~0x0631))
		cout << "ERROR: unrecognized flag(s)" << endl;
	
	output.name = getName(constant_pool[this_class].ClassInfo.name_index);
	output.extends = checkClassName(getName(constant_pool[super_class].ClassInfo.name_index));
	
	std::uint16_t interfaces_count;
	stream >> interfaces_count;
	cout << interfaces_count << " interfaces" << endl;
	for(std::uint16_t i = 0;i < interfaces_count;i++)
	{
		output.interfaces.push_back(parseInterface());
	}
	
	std::uint16_t fields_count;
	stream >> fields_count;
	cout << fields_count << " fields" << endl;
	for(std::uint16_t i = 0;i < fields_count;i++)
	{
		output.fields.push_back(parseField());
	}
	
	std::uint16_t methods_count;
	stream >> methods_count;
	cout << methods_count << " methods" << endl;
	for(std::uint16_t i = 0;i < methods_count;i++)
	{
		output.methods.push_back(parseMethod());
	}
	
	std::uint16_t attributes_count;
	stream >> attributes_count;
	cout << attributes_count << " attributes" << endl;
	for(std::uint16_t i = 0;i < attributes_count;i++)
	{
		parseAttribute();
	}
	
	file.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
xorl %eax, %eax
movb %al, 0x10(%rdi)
leaq 0x30(%rdi), %rcx
movq %rcx, 0x20(%rdi)
andq $0x0, 0x28(%rdi)
movb %al, 0x30(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x50(%rdi)
movups %xmm0, 0x60(%rdi)
movups %xmm0, 0x70(%rdi)
movups %xmm0, 0x7e(%rdi)
movups %xmm0, 0x90(%rdi)
andq $0x0, 0xa0(%rdi)
leaq -0x378(%rbp), %r14
pushq $0xc
popq %rdx
movq %r14, %rdi
callq 0x2350
leaq -0x300(%rbp), %rdi
callq 0x2090
testb %al, %al
je 0x2d97
leaq 0xa8(%rbx), %rdi
movq %r14, (%rdi)
leaq -0x48(%rbp), %rsi
movq %rdi, -0x30(%rbp)
callq 0x284c
movl -0x48(%rbp), %r14d
movl $0xcafebabe, %eax       # imm = 0xCAFEBABE
cmpq %rax, %r14
jne 0x2a6c
leaq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
leaq -0x42(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
movq 0x16646(%rip), %rdi     # 0x18fd0
leaq 0xf6f8(%rip), %rsi      # 0x12089
callq 0x2230
movzwl -0x42(%rbp), %esi
movq %rax, %rdi
callq 0x2380
leaq 0xf702(%rip), %rsi      # 0x120ab
movq %rax, %rdi
callq 0x2230
movzwl -0x40(%rbp), %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
callq 0x2150
leaq -0x3e(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
movzwl -0x3e(%rbp), %r12d
movq 0x165f2(%rip), %rdi     # 0x18fd0
movl %r12d, %esi
callq 0x2380
leaq 0xf6a2(%rip), %rsi      # 0x1208f
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2150
xorps %xmm0, %xmm0
leaq -0x130(%rbp), %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
leaq 0x1681a(%rip), %rdi     # 0x19230
callq 0x3a44
leaq 0x20(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0x40(%rbx), %r15
pushq $0x1
popq %r13
leaq -0x130(%rbp), %r14
cmpq %r12, %r13
jae 0x2aac
movq %rbx, %rdi
callq 0x2e42
testb %al, %al
je 0x2a67
xorps %xmm0, %xmm0
movaps %xmm0, -0x130(%rbp)
andq $0x0, -0x120(%rbp)
leaq 0x167d4(%rip), %rdi     # 0x19230
movq %r14, %rsi
callq 0x3a44
incq %r13
incq %r13
jmp 0x2a32
movq 0x1655d(%rip), %rdi     # 0x18fd0
leaq 0xf5fe(%rip), %rsi      # 0x12078
callq 0x2230
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movq %r14, %rsi
callq 0x21a0
movq %rax, %rdi
callq 0x2150
jmp 0x2d97
leaq -0x3c(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
leaq -0x3a(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
leaq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
movzwl -0x3c(%rbp), %r14d
testb $0x1, %r14b
je 0x2ae5
movb $0x1, 0x8b(%rbx)
testb $0x10, %r14b
je 0x2af2
movb $0x1, 0x88(%rbx)
testb $0x20, %r14b
je 0x2b13
movq 0x164d1(%rip), %rdi     # 0x18fd0
leaq 0xf594(%rip), %rsi      # 0x1209a
callq 0x2230
movq %rax, %rdi
callq 0x2150
btl $0x9, %r14d
jae 0x2b21
movb $0x1, 0x8a(%rbx)
btl $0xa, %r14d
jae 0x2b2f
movb $0x1, 0x89(%rbx)
btl $0xd, %r14d
jae 0x2b3d
movb $0x1, 0x8c(%rbx)
btl $0xe, %r14d
jae 0x2b4b
movb $0x1, 0x8d(%rbx)
testw $0xf9ce, %r14w          # imm = 0xF9CE
je 0x2b6e
movq 0x16476(%rip), %rdi     # 0x18fd0
leaq 0xf54c(%rip), %rsi      # 0x120ad
callq 0x2230
movq %rax, %rdi
callq 0x2150
movzwl -0x3a(%rbp), %eax
leaq 0x166b7(%rip), %r12     # 0x19230
movq (%r12), %rcx
imulq $0x18, %rax, %rax
movzwl 0x8(%rcx,%rax), %esi
leaq -0x130(%rbp), %rdi
callq 0x119f9
leaq -0x130(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22b0
movq %r14, %rdi
callq 0x2140
movzwl -0x38(%rbp), %eax
movq (%r12), %rcx
imulq $0x18, %rax, %rax
movzwl 0x8(%rcx,%rax), %esi
leaq -0x70(%rbp), %rdi
callq 0x119f9
leaq -0x130(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x11a78
movq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x22b0
movq %r14, %rdi
callq 0x2140
leaq -0x70(%rbp), %rdi
callq 0x2140
leaq -0x36(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
movzwl -0x36(%rbp), %r12d
movzwl %r12w, %esi
movq 0x163c0(%rip), %rdi     # 0x18fd0
callq 0x2380
leaq 0xf4ad(%rip), %rsi      # 0x120c9
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2150
subw $0x1, %r12w
jb 0x2c53
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2f74
movq %r15, %rdi
movq %r14, %rsi
callq 0x3be2
movq %r14, %rdi
callq 0x2140
jmp 0x2c2c
leaq -0x34(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
movzwl -0x34(%rbp), %r12d
movzwl %r12w, %esi
movq 0x16360(%rip), %rdi     # 0x18fd0
callq 0x2380
leaq 0xf459(%rip), %rsi      # 0x120d5
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2150
leaq 0x70(%rbx), %r14
leaq -0x130(%rbp), %r15
subw $0x1, %r12w
jb 0x2cbe
movq %r15, %rdi
movq %rbx, %rsi
callq 0x303e
movq %r14, %rdi
movq %r15, %rsi
callq 0x3dc0
movq %r15, %rdi
callq 0x36a2
jmp 0x2c97
leaq -0x32(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
movzwl -0x32(%rbp), %r12d
movzwl %r12w, %esi
movq 0x162f5(%rip), %rdi     # 0x18fd0
callq 0x2380
leaq 0xf3f6(%rip), %rsi      # 0x120dd
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2150
leaq 0x58(%rbx), %r14
leaq -0x130(%rbp), %r15
subw $0x1, %r12w
jb 0x2d29
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3290
movq %r14, %rdi
movq %r15, %rsi
callq 0x4006
movq %r15, %rdi
callq 0x36cc
jmp 0x2d02
leaq -0x130(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x280c
movzwl -0x130(%rbp), %r15d
movzwl %r15w, %esi
movq 0x16284(%rip), %rdi     # 0x18fd0
callq 0x2380
leaq 0xf38e(%rip), %rsi      # 0x120e6
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2150
leaq -0x170(%rbp), %r14
subw $0x1, %r15w
jb 0x2d8b
movq %r14, %rdi
movq %rbx, %rsi
callq 0x34a8
movq %r14, %rdi
callq 0x3716
jmp 0x2d6f
leaq -0x378(%rbp), %rdi
callq 0x2070
leaq -0x378(%rbp), %rdi
callq 0x20b0
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x70(%rbp), %rdi
jmp 0x2e0f
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
movq %rax, %r14
jmp 0x2e25
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
jmp 0x2e16
movq %rax, %r14
leaq -0x130(%rbp), %rdi
callq 0x36cc
jmp 0x2e19
jmp 0x2e16
movq %rax, %r14
leaq -0x130(%rbp), %rdi
callq 0x36a2
jmp 0x2e19
jmp 0x2e16
movq %rax, %r14
leaq -0x130(%rbp), %rdi
callq 0x2140
jmp 0x2e19
movq %rax, %r14
leaq -0x378(%rbp), %rdi
callq 0x20b0
leaq 0x90(%rbx), %rdi
callq 0x3a30
movq %rbx, %rdi
callq 0x3736
movq %r14, %rdi
callq 0x23b0
nop