// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %rbx
movq %r14, 0x18(%rax)
movl %r15d, 0x4(%rax)
leal -0x10(%r15), %eax
cmpl $0x13, %eax
ja 0xebaf8
leaq 0x5a26a(%rip), %rcx     # 0x145cf0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpq $0x0, 0x2c0(%r14)
jne 0xebae1
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
callq 0xe969b
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 0xebab6
movl %esi, (%rax,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xebaaf
movq 0x2c0(%r14), %rax
movq %rax, 0x28(%rbx)
leaq 0xdd(%rip), %rax        # 0xebbd0
jmp 0xebbbb
leal -0x31(%r15), %eax
cmpl $0x2, %eax
jae 0xebb7d
movb $0x1, 0x14(%rbx)
leaq 0x283(%rip), %rax       # 0xebd8f
jmp 0xebbbb
cmpq $0x0, 0x2d0(%r14)
jne 0xebb69
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0xe969b
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
addq %rcx, %r8
movw %di, (%rax,%r8,2)
shrl $0xf, %edx
addq %rcx, %rdx
movw %si, (%rax,%rdx,2)
addq $0x2, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xebb31
movq 0x2d0(%r14), %rax
movq %rax, 0x20(%rbx)
leaq 0xfa(%rip), %rax        # 0xebc75
jmp 0xebbbb
cmpl $0x30, %r15d
jne 0xebbbf
movb $0x1, 0x14(%rbx)
leaq 0x1e1(%rip), %rax       # 0xebd6f
jmp 0xebbbb
movq %r14, %rdi
movl $0x8408, %esi           # imm = 0x8408
jmp 0xebbab
leaq 0x70(%rip), %rax        # 0xebc11
jmp 0xebbbb
movq %r14, %rdi
movl $0xa001, %esi           # imm = 0xA001
callq 0xebcbb
movq %rax, 0x20(%rbx)
leaq 0x176(%rip), %rax       # 0xebd31
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
callq 0xebdc3
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq