// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/binhex.c
// Function: find_start
static int find_start(deark *c, i64 *foundpos)
{
	i64 pos;
	u8 b;
	int ret;

	*foundpos = 0;

	ret = dbuf_search(c->infile, g_binhex_intro1, INTRO1_LEN, 0, 8192, &pos);
	if(ret) pos += INTRO1_LEN;
	if(!ret) {
		ret = dbuf_search(c->infile, g_binhex_intro2, INTRO2_LEN, 0, 8192, &pos);
		if(ret) pos += INTRO2_LEN;
	}
	if(!ret) {
		ret = dbuf_search(c->infile, g_binhex_intro3, INTRO3_LEN, 0, 8192, &pos);
		if(ret) pos += INTRO3_LEN;
	}
	if(!ret) {
		if(de_getbyte(0)==':') {
			*foundpos = 1;
			return 1;
		}
	}
	if(!ret) {
		return 0;
	}

	// Find the next CR/LF byte
	while(1) {
		if(pos>=c->infile->len) return 0;
		b = de_getbyte(pos);
		pos++;
		if(b=='\x0a' || b=='\x0d') {
			break;
		}
	}

	// Skip any number of additional whitespace
	while(1) {
		b = de_getbyte(pos);
		if(b=='\x0a' || b=='\x0d' || b==' ' || b=='\t') {
			pos++;
		}
		else {
			break;
		}
	}

	// Current byte should be a colon (:)
	b = de_getbyte(pos);
	if(b==':') {
		*foundpos = pos+1;
		return 1;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq 0x1e7b3e(%rip), %rsi    # 0x2254e8
movl $0x28, %edx
xorl %eax, %eax
movl %eax, %ecx
movl $0x2000, %r8d           # imm = 0x2000
leaq -0x20(%rbp), %r9
callq 0x169370
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x3d9d7
movq -0x20(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x20(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x3da1b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq 0x1e7b04(%rip), %rsi    # 0x2254f0
movl $0x17, %edx
xorl %eax, %eax
movl %eax, %ecx
movl $0x2000, %r8d           # imm = 0x2000
leaq -0x20(%rbp), %r9
callq 0x169370
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x3da19
movq -0x20(%rbp), %rax
addq $0x17, %rax
movq %rax, -0x20(%rbp)
jmp 0x3da1b
cmpl $0x0, -0x28(%rbp)
jne 0x3da5f
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq 0x1e7ac8(%rip), %rsi    # 0x2254f8
movl $0x2a, %edx
xorl %eax, %eax
movl %eax, %ecx
movl $0x2000, %r8d           # imm = 0x2000
leaq -0x20(%rbp), %r9
callq 0x169370
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x3da5d
movq -0x20(%rbp), %rax
addq $0x2a, %rax
movq %rax, -0x20(%rbp)
jmp 0x3da5f
cmpl $0x0, -0x28(%rbp)
jne 0x3da97
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165060
movzbl %al, %eax
cmpl $0x3a, %eax
jne 0x3da95
movq -0x18(%rbp), %rax
movq $0x1, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x3db87
jmp 0x3da97
cmpl $0x0, -0x28(%rbp)
jne 0x3daa9
movl $0x0, -0x4(%rbp)
jmp 0x3db87
jmp 0x3daab
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x3dac9
movl $0x0, -0x4(%rbp)
jmp 0x3db87
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, -0x21(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0xa, %eax
je 0x3dafb
movzbl -0x21(%rbp), %eax
cmpl $0xd, %eax
jne 0x3dafd
jmp 0x3daff
jmp 0x3daab
jmp 0x3db01
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0xa, %eax
je 0x3db39
movzbl -0x21(%rbp), %eax
cmpl $0xd, %eax
je 0x3db39
movzbl -0x21(%rbp), %eax
cmpl $0x20, %eax
je 0x3db39
movzbl -0x21(%rbp), %eax
cmpl $0x9, %eax
jne 0x3db47
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x3db49
jmp 0x3db4b
jmp 0x3db01
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0x3a, %eax
jne 0x3db80
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x3db87
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq