// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-fax.c
// Function: fmtutil_fax34_codectype1
void fmtutil_fax34_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
	struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
	void *codec_private_params)
{
	struct fax_ctx *fc = NULL;
	struct fax34_huffman_tree *f34ht = NULL;

	fc = de_malloc(c, sizeof(struct fax_ctx));
	fc->modname = "fax_decode";
	fc->fax34params = (struct de_fax34_params*)codec_private_params;
	fc->dcmpri = dcmpri;
	fc->dcmpro = dcmpro;
	fc->dres = dres;
	fc->image_width = fc->fax34params->image_width;
	fc->image_height = fc->fax34params->image_height;

	if((fc->fax34params->tiff_cmpr_meth==3 && (fc->fax34params->t4options & 0x1)) ||
		(fc->fax34params->tiff_cmpr_meth==4))
	{
		fc->is_2d = 1;
	}

	if(fc->fax34params->tiff_cmpr_meth==2) {
		fc->has_eol_codes = 0;
		fc->rows_padded_to_next_byte = 1;
	}
	else if(fc->fax34params->tiff_cmpr_meth==3) {
		fc->has_eol_codes = 1;
	}

	if(fc->image_width < 1 ||
		fc->image_width > c->max_image_dimension)
	{
		goto done;
	}

	fc->rowspan_final = (fc->image_width+7)/8;
	if(fc->rowspan_final < fc->fax34params->out_rowspan) {
		fc->rowspan_final = fc->fax34params->out_rowspan;
	}

	fc->curr_row = de_malloc(c, fc->image_width);
	fc->prev_row = de_malloc(c, fc->image_width);
	fc->tmp_row_packed = de_malloc(c, fc->rowspan_final);

	f34ht = create_fax34_huffman_tree(c, (int)fc->is_2d);
	do_decompress_fax34(c, fc, f34ht);

done:
	destroy_fax34_huffman_tree(c, f34ht);
	if(fc) {
		de_free(c, fc->curr_row);
		de_free(c, fc->prev_row);
		de_free(c, fc->tmp_row_packed);
		de_free(c, fc);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl $0xd0, %esi
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
leaq 0x590b7(%rip), %rcx     # 0x1d6a20
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
cmpl $0x3, 0x18(%rax)
jne 0x17d9e4
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x17d9f2
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
cmpl $0x4, 0x18(%rax)
jne 0x17d9fa
movq -0x30(%rbp), %rax
movb $0x1, 0x2a(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
cmpl $0x2, 0x18(%rax)
jne 0x17da1a
movq -0x30(%rbp), %rax
movb $0x0, 0x28(%rax)
movq -0x30(%rbp), %rax
movb $0x1, 0x29(%rax)
jmp 0x17da32
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
cmpl $0x3, 0x18(%rax)
jne 0x17da30
movq -0x30(%rbp), %rax
movb $0x1, 0x28(%rax)
jmp 0x17da32
movq -0x30(%rbp), %rax
cmpq $0x1, 0x30(%rax)
jl 0x17da52
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0xa8(%rcx), %rax
jle 0x17da57
jmp 0x17db2e
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
addq $0x7, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jge 0x17daab
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x15b780
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x15b780
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rsi
callq 0x15b780
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movzbl 0x2a(%rax), %esi
callq 0x17db90
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x17dd00
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x17e490
cmpq $0x0, -0x30(%rbp)
je 0x17db88
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x90(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nop