// File: /workspace/github_c_makefile_star2_O0/Encryptr[P]O-plus-plus/opp/ir/ir-linux.c
// Function: write_elf64
void write_elf64(struct OppIr* ir, OppIO* io)
{
	// Header
	fwrite(&elf_info.elf64_hdr, sizeof(elf_info.elf64_hdr), 1, io->file);

	// Sections
	for (unsigned int i = 0; i < sizeof(struct Elf64_SHDR); i++) 
		fwrite(((char[1]){0}), 1, 1, io->file);
	fwrite(elf_info.sect_list, sizeof(struct Elf64_SHDR), elf_info.sect_amount-1, io->file);
	
	// Text
	fwrite(ir->code.bytes, 1, ir->code.idx, io->file);

	// Data
	fwrite(ir->data_seg.data, 1, ir->data_seg.idx, io->file);

	// Sym / Rela
	for (unsigned int i = 0; i < elf_info.symbols.sym_idx; i++)
		fwrite(&elf_info.symbols.pairs[i].syms, sizeof(struct Elf64_Symbol), 1, io->file);

	// Rela Text
	fwrite(elf_info.relocs, sizeof(struct Elf64_Reloc), elf_info.r_idx, io->file);

	// Shstrtab
	fwrite(shstrtab, 1, elf_info.sect_list[SECT_SHSTRTAB].sh_size, io->file);

	// Strtab
	fwrite(elf_info.strtable.str, 1, elf_info.strtable.str_idx, io->file);
	char z = 0;
	while (elf_info.strtable.str_idx % 16 != 0) {
		fwrite(&z, 1, 1, io->file);
		elf_info.strtable.str_idx++;
	}
	fwrite(&z, 1, 1, io->file);
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0xb2ea(%rip), %rdi      # 0x19218
addq $0x8, %rdi
movl $0x40, %esi
movl $0x1, %edx
callq 0x1200
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpq $0x40, %rax
jae 0xdf80
movb $0x0, 0x13(%rsp)
leaq 0x13(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1200
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xdf49
movq 0xb2d9(%rip), %rdi      # 0x19260
movl 0xb28b(%rip), %eax      # 0x19218
subl $0x1, %eax
movslq %eax, %rdx
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x40, %esi
callq 0x1200
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdx
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %esi
callq 0x1200
movq 0x20(%rsp), %rax
movq 0x90(%rax), %rdi
movq 0x20(%rsp), %rax
movq 0x88(%rax), %rdx
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %esi
callq 0x1200
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0xb289(%rip), %eax      # 0x19290
jae 0xe040
movq 0xb278(%rip), %rdi      # 0x19288
movl 0xc(%rsp), %eax
shlq $0x5, %rax
addq %rax, %rdi
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x18, %esi
movl $0x1, %edx
callq 0x1200
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0xdffd
movq 0xb251(%rip), %rdi      # 0x19298
movl 0xb253(%rip), %eax      # 0x192a0
movl %eax, %edx
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x18, %esi
callq 0x1200
movq 0xb1f7(%rip), %rax      # 0x19260
movq 0x120(%rax), %rdx
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0xb140(%rip), %rdi      # 0x191c0
movl $0x1, %esi
callq 0x1200
movq 0xb1df(%rip), %rdi      # 0x19270
movl 0xb1e1(%rip), %eax      # 0x19278
movl %eax, %edx
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %esi
callq 0x1200
movb $0x0, 0xb(%rsp)
movl 0xb1c1(%rip), %eax      # 0x19278
andl $0xf, %eax
cmpl $0x0, %eax
je 0xe0eb
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0xb(%rsp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1200
movl 0xb198(%rip), %eax      # 0x19278
addl $0x1, %eax
movl %eax, 0xb18f(%rip)      # 0x19278
jmp 0xe0b1
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0xb(%rsp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1200
addq $0x28, %rsp
retq
nop
nopl (%rax)