// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/rpm.c
// Function: do_header_structure
static int do_header_structure(deark *c, lctx *d, int is_sig, i64 pos1,
	i64 *section_size)
{
	i64 pos;
	i64 indexcount;
	i64 storesize;
	u8 buf[4];
	u8 header_ver;
	i64 i;
	i64 tag_id, tag_type, tag_offset, tag_count;
	i64 data_store_pos;
	const char *hdrname;
	int retval = 0;

	hdrname = is_sig?"sig":"hdr";
	pos = pos1;
	de_dbg(c, "%s section at %d", hdrname, (int)pos1);
	de_dbg_indent(c, 1);

	de_read(buf, pos, 4);
	if(buf[0]!=0x8e || buf[1]!=0xad || buf[2]!=0xe8) {
		de_err(c, "Bad header signature at %d", (int)pos);
		goto done;
	}
	header_ver = buf[3];
	if(header_ver != 1) {
		de_err(c, "Unsupported header version");
		goto done;
	}
	pos += 8;

	indexcount = de_getu32be(pos);
	storesize = de_getu32be(pos+4);
	de_dbg(c, "%s: pos=%d indexcount=%d storesize=%d", hdrname,
		(int)pos, (int)indexcount, (int)storesize);
	pos += 8;

	if(indexcount>1000) goto done;

	data_store_pos = pos + 16*indexcount;

	de_dbg(c, "%s: tag table at %d", hdrname, (int)pos);
	de_dbg_indent(c, 1);

	for(i=0; i<indexcount; i++) {
		tag_id = de_getu32be(pos);
		tag_type = de_getu32be(pos+4);
		tag_offset = de_getu32be(pos+8);
		tag_count = de_getu32be(pos+12);

		de_dbg2(c, "tag #%d type=%d offset=%d count=%d", (int)tag_id,
			(int)tag_type, (int)tag_offset, (int)tag_count);


		if(is_sig==0 && tag_id==DE_RPMTAG_PAYLOADCOMPRESSOR && tag_type==DE_RPM_STRING_TYPE) {
			read_compression_type(c, d, data_store_pos+tag_offset);
		}
		else if(is_sig==0 && tag_id==DE_RPMTAG_NAME && tag_type==DE_RPM_STRING_TYPE) {
			if(!d->name_srd) {
				d->name_srd = dbuf_read_string(c->infile, data_store_pos+tag_offset,
					DE_DBG_MAX_STRLEN, DE_DBG_MAX_STRLEN,
					DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_ASCII);
				de_dbg(c, "name: \"%s\"", ucstring_getpsz(d->name_srd->str));
			}
		}
		else if(is_sig==0 && tag_id==DE_RPMTAG_VERSION && tag_type==DE_RPM_STRING_TYPE) {
			if(!d->version_srd) {
				d->version_srd = dbuf_read_string(c->infile, data_store_pos+tag_offset,
					DE_DBG_MAX_STRLEN, DE_DBG_MAX_STRLEN,
					DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_ASCII);
				de_dbg(c, "version: \"%s\"", ucstring_getpsz(d->version_srd->str));
			}
		}
		else if(is_sig==0 && tag_id==DE_RPMTAG_RELEASE && tag_type==DE_RPM_STRING_TYPE) {
			if(!d->release_srd) {
				d->release_srd = dbuf_read_string(c->infile, data_store_pos+tag_offset,
					DE_DBG_MAX_STRLEN, DE_DBG_MAX_STRLEN,
					DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_ASCII);
				de_dbg(c, "release: \"%s\"", ucstring_getpsz(d->release_srd->str));
			}
		}

		pos += 16;
	}

	de_dbg_indent(c, -1);

	pos = data_store_pos;
	de_dbg(c, "%s: data store at %d", hdrname, (int)pos);
	pos += storesize;

	*section_size = pos - pos1;
	retval = 1;
done:
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x84(%rbp)
movl -0x14(%rbp), %edx
leaq 0x99d8b(%rip), %rax     # 0x1bc35d
leaq 0xa3e0c(%rip), %rcx     # 0x1c63e5
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq 0xa3de8(%rip), %rsi     # 0x1c63e9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x44(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl $0x4, %ecx
callq 0x164d10
movzbl -0x44(%rbp), %eax
cmpl $0x8e, %eax
jne 0x122651
movzbl -0x43(%rbp), %eax
cmpl $0xad, %eax
jne 0x122651
movzbl -0x42(%rbp), %eax
cmpl $0xe8, %eax
je 0x12266e
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0xa3d98(%rip), %rsi     # 0x1c63fa
movb $0x0, %al
callq 0x15bfb0
jmp 0x122a4a
movb -0x41(%rbp), %al
movb %al, -0x45(%rbp)
movzbl -0x45(%rbp), %eax
cmpl $0x1, %eax
je 0x122694
movq -0x8(%rbp), %rdi
leaq 0xa3d8d(%rip), %rsi     # 0x1c6415
movb $0x0, %al
callq 0x15bfb0
jmp 0x122a4a
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x165470
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x4, %rsi
callq 0x165470
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %eax, %r8d
movq -0x40(%rbp), %rax
movl %eax, %r9d
leaq 0xa3d3f(%rip), %rsi     # 0x1c6430
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
cmpq $0x3e8, -0x38(%rbp)     # imm = 0x3E8
jle 0x122713
jmp 0x122a4a
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x30(%rbp), %rax
movl %eax, %ecx
leaq 0xa3d1b(%rip), %rsi     # 0x1c6456
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x1229f3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x165470
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x4, %rsi
callq 0x165470
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
callq 0x165470
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
addq $0xc, %rsi
callq 0x165470
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x60(%rbp), %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %eax, %r8d
movq -0x70(%rbp), %rax
movl %eax, %r9d
leaq 0xa3c7f(%rip), %rsi     # 0x1c646a
movb $0x0, %al
callq 0x15b350
cmpl $0x0, -0x14(%rbp)
jne 0x122823
cmpq $0x465, -0x58(%rbp)     # imm = 0x465
jne 0x122823
cmpq $0x6, -0x60(%rbp)
jne 0x122823
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq -0x68(%rbp), %rdx
callq 0x122a70
jmp 0x1229d6
cmpl $0x0, -0x14(%rbp)
jne 0x1228b3
cmpq $0x3e8, -0x58(%rbp)     # imm = 0x3E8
jne 0x1228b3
cmpq $0x6, -0x60(%rbp)
jne 0x1228b3
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x1228ae
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x78(%rbp), %rsi
addq -0x68(%rbp), %rsi
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x1, %r9d
movq %rcx, %rdx
movl %r9d, %r8d
callq 0x1664c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0x90(%rbp), %rdi
movq %rax, %rdx
leaq 0x8b929(%rip), %rsi     # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
jmp 0x1229d4
cmpl $0x0, -0x14(%rbp)
jne 0x122943
cmpq $0x3e9, -0x58(%rbp)     # imm = 0x3E9
jne 0x122943
cmpq $0x6, -0x60(%rbp)
jne 0x122943
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x12293e
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x78(%rbp), %rsi
addq -0x68(%rbp), %rsi
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x1, %r9d
movq %rcx, %rdx
movl %r9d, %r8d
callq 0x1664c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0x98(%rbp), %rdi
movq %rax, %rdx
leaq 0x9a52f(%rip), %rsi     # 0x1bce66
movb $0x0, %al
callq 0x15b0d0
jmp 0x1229d2
cmpl $0x0, -0x14(%rbp)
jne 0x1229d0
cmpq $0x3ea, -0x58(%rbp)     # imm = 0x3EA
jne 0x1229d0
cmpq $0x6, -0x60(%rbp)
jne 0x1229d0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x1229ce
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x78(%rbp), %rsi
addq -0x68(%rbp), %rsi
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x1, %r9d
movq %rcx, %rdx
movl %r9d, %r8d
callq 0x1664c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0xa0(%rbp), %rdi
movq %rax, %rdx
leaq 0xa3ac6(%rip), %rsi     # 0x1c648d
movb $0x0, %al
callq 0x15b0d0
jmp 0x1229d0
jmp 0x1229d2
jmp 0x1229d4
jmp 0x1229d6
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x122758
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x30(%rbp), %rax
movl %eax, %ecx
leaq 0xa3a7d(%rip), %rsi     # 0x1c649b
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
subq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x84(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x84(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)