// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc3.c
// Function: do_ain_main
static void do_ain_main(deark *c, de_arch_lctx *d)
{
	struct de_timestamp archive_timestamp;
	UI hdr_checksum_reported;
	UI hdr_checksum_calc;
	i64 member_hdrs_pos;
	i64 member_hdrs_len;
	u8 b;
	UI upd_speed;
	UI cmpr_meth;
	UI member_hdrs_checksum_reported;
	UI member_hdrs_checksum_calc = 0;
	UI volume;
	i64 pos;

	de_declare_fmt(c, "AIN archive");
	if(c->module_disposition==DE_MODDISP_AUTODETECT) {
		de_info(c, "Note: AIN support is limited to decoding the header");
	}

	pos = 1;
	b = de_getbyte_p(&pos);
	upd_speed = b >> 4;
	de_dbg(c, "update speed: /u%u", upd_speed);
	cmpr_meth = b & 0x0f;
	de_dbg(c, "cmpr. method: /m%u", cmpr_meth);

	pos += 1; // ?
	b = de_getbyte_p(&pos);
	de_dbg(c, "flags: 0x%02x", b);
	pos += 2; // password-related
	volume = (UI)de_getu16le_p(&pos);
	de_dbg(c, "volume: %u", volume);

	pos = 8;
	d->num_members = de_getu16le_p(&pos);
	de_dbg(c, "number of members: %"I64_FMT, d->num_members);

	de_arch_read_field_dttm_p(d, &archive_timestamp, "archive",
		DE_ARCH_TSTYPE_DOS_TD, &pos);

	member_hdrs_pos = de_getu32le_p(&pos);
	de_dbg(c, "member hdrs pos: %"I64_FMT, member_hdrs_pos);
	member_hdrs_len = c->infile->len - member_hdrs_pos;

	member_hdrs_checksum_reported = (UI)de_getu16le_p(&pos);
	de_dbg(c, "member hdrs checksum (reported): 0x%04x", member_hdrs_checksum_reported);
	member_hdrs_checksum_calc = (UI)de_calccrc_oneshot(c->infile, member_hdrs_pos,
		member_hdrs_len, DE_CRCOBJ_SUM_BYTES);
	member_hdrs_checksum_calc &= 0xffff;
	de_dbg(c, "member hdrs checksum (calculated): 0x%04x", member_hdrs_checksum_calc);

	pos += 2; // ?

	hdr_checksum_reported = (UI)de_getu16le_p(&pos);
	de_dbg(c, "archive hdr checksum (reported): 0x%04x", hdr_checksum_reported);

	ain_calc_hdr_checksum(c, &hdr_checksum_calc);
	de_dbg(c, "archive hdr checksum (calculated): 0x%04x", hdr_checksum_calc);

	de_dbg(c, "file data at %"I64_FMT", len=%"I64_FMT, pos, member_hdrs_pos-pos);
	de_dbg(c, "member hdrs at %"I64_FMT", len=%"I64_FMT, member_hdrs_pos, member_hdrs_len);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x10d83f(%rip), %rsi    # 0x1b1531
callq 0x15e380
movq -0x8(%rbp), %rax
cmpl $0x1, 0x24(%rax)
jne 0xa3d13
movq -0x8(%rbp), %rdi
leaq 0x10dfb5(%rip), %rsi    # 0x1b1cc1
movb $0x0, %al
callq 0x15c0c0
movq $0x1, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x165170
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %edx
leaq 0x10dfae(%rip), %rsi    # 0x1b1cf5
movb $0x0, %al
callq 0x15b0d0
movzbl -0x39(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %edx
leaq 0x10dfa2(%rip), %rsi    # 0x1b1d08
movb $0x0, %al
callq 0x15b0d0
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x165170
movb %al, -0x39(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x39(%rbp), %edx
leaq 0x117d7d(%rip), %rsi    # 0x1bbb19
movb $0x0, %al
callq 0x15b0d0
movq -0x58(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl -0x50(%rbp), %edx
leaq 0x11a4dd(%rip), %rsi    # 0x1be2ae
movb $0x0, %al
callq 0x15b0d0
movq $0x8, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xfc6f4(%rip), %rsi     # 0x1a0503
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq 0xfed7e(%rip), %rdx     # 0x1a2ba3
movl $0x4, %ecx
leaq -0x58(%rbp), %r8
callq 0x17c580
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x165580
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x10dec4(%rip), %rsi    # 0x1b1d1b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl -0x48(%rbp), %edx
leaq 0x10de9c(%rip), %rsi    # 0x1b1d30
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x30, %ecx
callq 0x15f580
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %edx
leaq 0x10de87(%rip), %rsi    # 0x1b1d58
movb $0x0, %al
callq 0x15b0d0
movq -0x58(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %edx
leaq 0x10de7c(%rip), %rsi    # 0x1b1d82
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xa3f70
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %edx
leaq 0x10de82(%rip), %rsi    # 0x1b1daa
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x30(%rbp), %rcx
subq -0x58(%rbp), %rcx
leaq 0x11f41d(%rip), %rsi    # 0x1c3363
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x10de74(%rip), %rsi    # 0x1b1dd4
movb $0x0, %al
callq 0x15b0d0
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)