// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x38
popq %rsi
callq 0xdecaf
movq %rax, %rbx
movq %r14, 0x18(%rax)
movl %r15d, 0x4(%rax)
leal -0x10(%r15), %eax
cmpl $0x13, %eax
ja 0xe0b3c
leaq 0x58279(%rip), %rcx     # 0x138d90
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x2c0(%r14), %rax
testq %rax, %rax
je 0xe0b8c
movq %rax, 0x28(%rbx)
leaq 0x13c(%rip), %rax       # 0xe0c73
jmp 0xe0c0b
leal -0x31(%r15), %eax
cmpl $0x2, %eax
jae 0xe0b75
movb $0x1, 0x14(%rbx)
leaq 0x2bb(%rip), %rax       # 0xe0e0b
jmp 0xe0c0b
movq 0x2d0(%r14), %rax
testq %rax, %rax
je 0xe0c20
movq %rax, 0x20(%rbx)
leaq 0x18e(%rip), %rax       # 0xe0cfe
jmp 0xe0c0b
cmpl $0x30, %r15d
jne 0xe0c0f
movb $0x1, 0x14(%rbx)
leaq 0x265(%rip), %rax       # 0xe0def
jmp 0xe0c0b
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
callq 0xdecaf
movq %rax, 0x2c0(%r14)
xorl %ecx, %ecx
pushq $0x8
popq %rdx
cmpq $0x100, %rcx            # imm = 0x100
je 0xe0b2c
movl %edx, %esi
movl %ecx, %edi
subl $0x1, %esi
jb 0xe0bd8
movl %edi, %r8d
shrl %r8d
movl %r8d, %r9d
xorl $0xedb88320, %r9d       # imm = 0xEDB88320
testb $0x1, %dil
cmovel %r8d, %r9d
movl %r9d, %edi
jmp 0xe0bb6
movl %edi, (%rax,%rcx,4)
incq %rcx
jmp 0xe0ba5
movq %r14, %rdi
movl $0x8408, %esi           # imm = 0x8408
jmp 0xe0bfb
leaq 0xb9(%rip), %rax        # 0xe0caa
jmp 0xe0c0b
movq %r14, %rdi
movl $0xa001, %esi           # imm = 0xA001
callq 0xe0d40
movq %rax, 0x20(%rbx)
leaq 0x1aa(%rip), %rax       # 0xe0db5
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
callq 0xe0e44
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq
movl $0x200, %esi            # imm = 0x200
movq %r14, %rdi
callq 0xdecaf
movq %rax, 0x2d0(%r14)
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0xe0b65
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
jmp 0xe0c36