// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movl $0x38, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0xc(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
addl $-0x10, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x22, %eax
ja 0x15ec1c
movq -0x20(%rbp), %rax
leaq 0x73165(%rip), %rcx     # 0x1d1c80
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15ec30
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
leaq 0x1b9(%rip), %rcx       # 0x15ed00
movq %rcx, 0x30(%rax)
jmp 0x15ec1c
movq -0x18(%rbp), %rax
leaq 0x225(%rip), %rcx       # 0x15ed80
movq %rcx, 0x30(%rax)
jmp 0x15ec1c
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15ee10
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
leaq 0x3a9(%rip), %rcx       # 0x15ef30
movq %rcx, 0x30(%rax)
jmp 0x15ec1c
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0xa001, %esi           # imm = 0xA001
callq 0x15efc0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
leaq 0x538(%rip), %rcx       # 0x15f0f0
movq %rcx, 0x30(%rax)
jmp 0x15ec1c
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x8408, %esi           # imm = 0x8408
callq 0x15efc0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
leaq 0x50a(%rip), %rcx       # 0x15f0f0
movq %rcx, 0x30(%rax)
jmp 0x15ec1c
movq -0x18(%rbp), %rax
movb $0x1, 0x14(%rax)
movq -0x18(%rbp), %rax
leaq 0x571(%rip), %rcx       # 0x15f170
movq %rcx, 0x30(%rax)
jmp 0x15ec1c
movq -0x18(%rbp), %rax
movb $0x1, 0x14(%rax)
movq -0x18(%rbp), %rax
leaq 0x5a8(%rip), %rcx       # 0x15f1c0
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rdi
callq 0x15f250
movq -0x18(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nop