// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/src/deark-util.c
// Function: de_crcobj_create
struct de_crcobj *de_crcobj_create(deark *c, UI type_and_flags)
{
	struct de_crcobj *crco;

	crco = de_malloc(c, sizeof(struct de_crcobj));
	crco->c = c;
	crco->crctype = type_and_flags;

	switch(crco->crctype) {
	case DE_CRCOBJ_CRC32_IEEE:
	case DE_CRCOBJ_CRC32_JAMCRC:
		// "PL" is a placeholder name. I don't know a good name for this variant.
	case DE_CRCOBJ_CRC32_PL:
		crco->table32s = get_crc32_table(crco->c);
		crco->continue_fn = de_crc32_continue;
		break;
	case DE_CRCOBJ_ADLER32:
		crco->continue_fn = adler32_continue;
		break;
	case DE_CRCOBJ_CRC16_XMODEM:
		// "XMODEM" is the CRC-16 algorithm used in MacBinary.
		// The CRC RevEng catalogue calls it "CRC-16/XMODEM".
	case DE_CRCOBJ_CRC16_IBM3740:
		crco->table16s = get_crc16xmodem_table(crco->c);
		crco->continue_fn = de_crc16xmodem_continue;
		break;
	case DE_CRCOBJ_CRC16_ARC:
		// This is the CRC-16 algorithm used in ARC, LHA, ZOO, etc.
		// The CRC RevEng catalogue calls it "CRC-16/ARC".
		crco->table16s = get_crc16arc_table(crco->c, 0xa001);
		crco->continue_fn = de_crc16arc_continue;
		break;
	case DE_CRCOBJ_CRC16_IBMSDLC:
		// This is the CRC-16 algorithm used in ar001.
		// I'm pretty sure it is equivalent to the one the CRC RevEng catalogue
		// calls "CRC-16/IBM-SDLC".
		crco->table16s = get_crc16arc_table(crco->c, 0x8408);
		crco->continue_fn = de_crc16arc_continue;
		break;
	case DE_CRCOBJ_SUM_BYTES:
		crco->is_64bit = 1;
		crco->continue_fn = cksum_bytes_continue;
		break;
	case DE_CRCOBJ_SUM_U16LE:
	case DE_CRCOBJ_SUM_U16BE:
		crco->is_64bit = 1;
		crco->continue_fn = cksum_u16_continue;
		break;
	}

	de_crcobj_reset(crco);
	return crco;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %r15d
movq %rdi, %r14
movl $0x38, %esi
callq 0xe8b2b
movq %rax, %rbx
movq %r14, 0x18(%rax)
movl %r15d, 0x4(%rax)
leal -0x10(%r15), %eax
cmpl $0x13, %eax
ja 0xeb536
leaq 0x5ad97(%rip), %rcx     # 0x146260
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x2c0(%r14), %rax
testq %rax, %rax
jne 0xeb526
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
callq 0xe8b2b
movq %rax, 0x2c0(%r14)
xorl %ecx, %ecx
movl $0x8, %edx
movl %ecx, %esi
movl %esi, %edi
shrl %edi
movl %edi, %r8d
xorl $0xedb88320, %r8d       # imm = 0xEDB88320
testb $0x1, %sil
movl %r8d, %esi
cmovel %edi, %esi
decl %edx
jne 0xeb4fb
movl %esi, (%rax,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xeb4f4
movq %rax, 0x28(%rbx)
leaq 0xd7(%rip), %rax        # 0xeb608
jmp 0xeb5f3
leal -0x31(%r15), %eax
cmpl $0x2, %eax
jae 0xeb5b5
movb $0x1, 0x14(%rbx)
leaq 0x274(%rip), %rax       # 0xeb7be
jmp 0xeb5f3
movq 0x2d0(%r14), %rax
testq %rax, %rax
jne 0xeb5a8
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0xe8b2b
movq %rax, 0x2d0(%r14)
xorl %ecx, %ecx
movzwl (%rax,%rcx), %edx
leal (%rdx,%rdx), %esi
movl %esi, %edi
xorl $0x1021, %edi           # imm = 0x1021
xorl %r8d, %r8d
testw %dx, %dx
setns %r8b
addl %ecx, %r8d
movw %di, (%rax,%r8,2)
shrl $0xf, %edx
addl %ecx, %edx
movw %si, (%rax,%rdx,2)
addq $0x2, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xeb571
movq %rax, 0x20(%rbx)
leaq 0xfa(%rip), %rax        # 0xeb6ad
jmp 0xeb5f3
cmpl $0x30, %r15d
jne 0xeb5f7
movb $0x1, 0x14(%rbx)
leaq 0x1d8(%rip), %rax       # 0xeb79e
jmp 0xeb5f3
movq %r14, %rdi
movl $0x8408, %esi           # imm = 0x8408
jmp 0xeb5e3
leaq 0x70(%rip), %rax        # 0xeb649
jmp 0xeb5f3
movq %r14, %rdi
movl $0xa001, %esi           # imm = 0xA001
callq 0xeb6f3
movq %rax, 0x20(%rbx)
leaq 0x16d(%rip), %rax       # 0xeb760
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
callq 0xeb7fe
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq