// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/misc.c
// Function: de_run_xor
static void de_run_xor(deark *c, de_module_params *mparams)
{
	struct xorctx_struct *xorctx = NULL;
	int badkey_flag = 0;
	const char *opt_key;

	xorctx = de_malloc(c, sizeof(struct xorctx_struct));
	xorctx->key[0] = 0xff;
	xorctx->key_len = 1;

	opt_key = de_get_ext_option(c, "xor:key");
	if(opt_key) {
		UI key_strlen;
		UI k;

		key_strlen = (UI)de_strlen(opt_key);
		if(key_strlen%2) { badkey_flag = 1; goto done; }
		xorctx->key_len = key_strlen/2;
		if(xorctx->key_len<1 || (size_t)xorctx->key_len>sizeof(xorctx->key)) {
			badkey_flag = 1;
			goto done;
		}
		for(k=0; k<xorctx->key_len; k++) {
			u8 d1, d2;
			int errflag1 = 0;
			int errflag2 = 0;

			d1 = de_decode_hex_digit(opt_key[k*2], &errflag1);
			d2 = de_decode_hex_digit(opt_key[k*2+1], &errflag2);
			if(errflag1 || errflag2) { badkey_flag = 1; goto done; }
			xorctx->key[k] = (d1<<4) | d2;
		}
	}

	xorctx->outf = dbuf_create_output_file(c, "bin", NULL, 0);
	dbuf_enable_wbuffer(xorctx->outf);
	dbuf_buffered_read(c->infile, 0, c->infile->len, xor_cbfn, (void*)xorctx);

done:
	if(badkey_flag) {
		de_err(c, "Bad XOR key");
	}
	if(xorctx) {
		dbuf_close(xorctx->outf);
		de_free(c, xorctx);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movl $0x78, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movb $-0x1, 0x10(%rax)
movq -0x18(%rbp), %rax
movl $0x1, 0x8(%rax)
movq -0x8(%rbp), %rdi
leaq 0x11e9ec(%rip), %rsi    # 0x1affab
callq 0x15cb30
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x916c2
movq -0x28(%rbp), %rdi
callq 0x190e0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x915f6
movl $0x1, -0x1c(%rbp)
jmp 0x91716
movl -0x2c(%rbp), %ecx
shrl %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jb 0x91619
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
cmpq $0x64, %rax
jbe 0x91625
movl $0x1, -0x1c(%rbp)
jmp 0x91716
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x916c0
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
shll %ecx
movl %ecx, %ecx
leaq -0x38(%rbp), %rsi
movzbl (%rax,%rcx), %edi
callq 0x1600b0
movb %al, -0x31(%rbp)
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
leaq -0x3c(%rbp), %rsi
movzbl (%rax,%rcx), %edi
callq 0x1600b0
movb %al, -0x32(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x9168f
cmpl $0x0, -0x3c(%rbp)
je 0x91698
movl $0x1, -0x1c(%rbp)
jmp 0x91716
movzbl -0x31(%rbp), %eax
shll $0x4, %eax
movzbl -0x32(%rbp), %ecx
orl %ecx, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
movb %dl, 0x10(%rax,%rcx)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x9162c
jmp 0x916c2
movq -0x8(%rbp), %rdi
leaq 0x12fb3a(%rip), %rsi    # 0x1c1207
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x166c60
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x167b90
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 0x2bcf(%rip), %rcx      # 0x942e0
callq 0x166260
cmpl $0x0, -0x1c(%rbp)
je 0x9172e
movq -0x8(%rbp), %rdi
leaq 0x11e88c(%rip), %rsi    # 0x1affb3
movb $0x0, %al
callq 0x15bfb0
cmpq $0x0, -0x18(%rbp)
je 0x9174e
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)