// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc.c
// Function: de_run_bytefreq
static void de_run_bytefreq(deark *c, de_module_params *mparams)
{
	struct bytefreqctx_struct *bfctx = NULL;
	de_ucstring *s = NULL;
	unsigned int k;
	de_encoding input_encoding;
	struct de_encconv_state es;

	bfctx = de_malloc(c, sizeof(struct bytefreqctx_struct));
	input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);
	if(input_encoding==DE_ENCODING_UTF8) {
		input_encoding=DE_ENCODING_ASCII;
	}
	de_encconv_init(&es, input_encoding);

	dbuf_buffered_read(c->infile, 0, c->infile->len, bytefreq_cbfn, (void*)bfctx);

	de_msg(c, "====Byte==== ===Count=== ==Locations==");
	s = ucstring_create(c);
	for(k=0; k<256; k++) {
		i32 ch;
		int cflag;
		unsigned int z;
		struct bytefreqentry *bf = &bfctx->e[k];

		if(bf->count==0) continue;
		ucstring_empty(s);

		ucstring_printf(s, DE_ENCODING_LATIN1, "%3u 0x%02x ", k, k);

		ch = de_char_to_unicode_ex((i32)k, &es);
		if(ch==DE_CODEPOINT_INVALID) {
			cflag = 0;
		}
		else {
			cflag = de_is_printable_uchar(ch);
		}

		if(cflag) {
			ucstring_append_sz(s, "'", DE_ENCODING_LATIN1);
			ucstring_append_char(s, ch);
			ucstring_append_sz(s, "'", DE_ENCODING_LATIN1);
		}
		else {
			ucstring_append_sz(s, "   ", DE_ENCODING_LATIN1);
		}

		ucstring_printf(s, DE_ENCODING_LATIN1, " %11"I64_FMT" ", bf->count);

		for(z=0; z<DE_BYTEFREQ_NUMLOC && z<bf->count; z++) {
			ucstring_printf(s, DE_ENCODING_LATIN1, "%"I64_FMT, bf->locations[z]);
			if(z<bf->count-1) {
				ucstring_append_sz(s, ",", DE_ENCODING_LATIN1);
			}
		}
		if(bf->count>DE_BYTEFREQ_NUMLOC) {
			ucstring_append_sz(s, "...", DE_ENCODING_LATIN1);
		}

		de_msg(c, "%s", ucstring_getpsz(s));
	}
	de_msg(c, "      Total: %11"I64_FMT, c->infile->len);
	ucstring_destroy(s);
	de_free(c, bfctx);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x9, %edx
callq 0x15e4a0
movl %eax, -0x28(%rbp)
cmpl $0x2, -0x28(%rbp)
jne 0x92014
movl $0x1, -0x28(%rbp)
movl -0x28(%rbp), %esi
leaq -0x48(%rbp), %rdi
callq 0x160150
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
movq -0x18(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
leaq 0x25ad(%rip), %rcx      # 0x945f0
callq 0x166260
movq -0x8(%rbp), %rdi
leaq 0x11e0db(%rip), %rsi    # 0x1b012e
movb $0x0, %al
callq 0x15c190
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jae 0x92236
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x9209c
jmp 0x92228
movq -0x20(%rbp), %rdi
callq 0x171210
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %ecx
movl -0x24(%rbp), %r8d
movl $0x5, %esi
leaq 0x11e099(%rip), %rdx    # 0x1b0155
movb $0x0, %al
callq 0x171660
movl -0x24(%rbp), %edi
leaq -0x48(%rbp), %rsi
callq 0x160a30
movl %eax, -0x4c(%rbp)
cmpl $0xfffffff, -0x4c(%rbp) # imm = 0xFFFFFFF
jne 0x920e4
movl $0x0, -0x50(%rbp)
jmp 0x920ef
movl -0x4c(%rbp), %edi
callq 0x172490
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x9212d
movq -0x20(%rbp), %rdi
leaq 0x11053f(%rip), %rsi    # 0x1a263f
movl $0x5, %edx
callq 0x1715e0
movq -0x20(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x1714c0
movq -0x20(%rbp), %rdi
leaq 0x11051e(%rip), %rsi    # 0x1a263f
movl $0x5, %edx
callq 0x1715e0
jmp 0x92142
movq -0x20(%rbp), %rdi
leaq 0x12666f(%rip), %rsi    # 0x1b87a7
movl $0x5, %edx
callq 0x1715e0
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rax
movq (%rax), %rcx
movl $0x5, %esi
leaq 0x11e008(%rip), %rdx    # 0x1b0161
movb $0x0, %al
callq 0x171660
movl $0x0, -0x54(%rbp)
xorl %eax, %eax
cmpl $0x3, -0x54(%rbp)
movb %al, -0x61(%rbp)
jae 0x92182
movl -0x54(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpq (%rcx), %rax
setl %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x9218b
jmp 0x921e3
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rax
movl -0x54(%rbp), %ecx
movq 0x8(%rax,%rcx,8), %rcx
movl $0x5, %esi
leaq 0x122f68(%rip), %rdx    # 0x1b510f
movb $0x0, %al
callq 0x171660
movl -0x54(%rbp), %eax
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x921d6
movq -0x20(%rbp), %rdi
leaq 0x11df9d(%rip), %rsi    # 0x1b0169
movl $0x5, %edx
callq 0x1715e0
jmp 0x921d8
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x92167
movq -0x60(%rbp), %rax
cmpq $0x3, (%rax)
jle 0x92202
movq -0x20(%rbp), %rdi
leaq 0x13fe51(%rip), %rsi    # 0x1d2049
movl $0x5, %edx
callq 0x1715e0
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
callq 0x172500
movq -0x70(%rbp), %rdi
movq %rax, %rdx
leaq 0x10e90e(%rip), %rsi    # 0x1a0b2f
movb $0x0, %al
callq 0x15c190
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x9206e
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
leaq 0x11df1e(%rip), %rsi    # 0x1b016b
movb $0x0, %al
callq 0x15c190
movq -0x20(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x70, %rsp
popq %rbp
retq