// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/xfer.c
// Function: parse_begin_line
static void parse_begin_line(deark *c,
	struct uu_hdr_parser *uuhp, de_finfo *fi, const u8 *buf, i64 buf_len)
{
	i64 beginsize;
	de_ucstring *fn = NULL;
	i64 mode;
	size_t nbytes_to_copy;
	char tmpbuf[32];

	if(!fi) goto done;

	if(uuhp->hdr_line_type==HDR_UUENCODE_OR_XXENCODE) {
		beginsize = 5; // "begin" has 5 letters
	}
	else if(uuhp->hdr_line_type==HDR_UUENCODE_BASE64) {
		beginsize = 12; // "begin-base64"
	}
	else {
		goto done;
	}

	if(buf_len<beginsize+6 || buf[beginsize]!=' ' || buf[beginsize+4]!=' ') {
		goto done;
	}

	// Make a NUL-terminated copy of the file permissions mode.
	nbytes_to_copy = (size_t)(buf_len - (beginsize+1));
	if(nbytes_to_copy>sizeof(tmpbuf)) nbytes_to_copy = sizeof(tmpbuf);
	de_strlcpy(tmpbuf, (const char*)&buf[beginsize+1], nbytes_to_copy);
	mode = de_strtoll(tmpbuf, NULL, 8);
	de_dbg(c, "mode: %03o", (unsigned int)mode);
	if((mode & 0111)!=0) {
		fi->mode_flags |= DE_MODEFLAG_EXE;
	}
	else {
		fi->mode_flags |= DE_MODEFLAG_NONEXE;
	}

	fn = ucstring_create(c);
	ucstring_append_bytes(fn, &buf[beginsize+5], buf_len-(beginsize+5), 0, DE_ENCODING_ASCII);
	de_dbg(c, "filename: \"%s\"", ucstring_getpsz_d(fn));
	de_finfo_set_name_from_ucstring(c, fi, fn, 0);
	fi->original_filename_flag = 1;

done:
	ucstring_destroy(fn);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1465c3
jmp 0x14673c
movq -0x10(%rbp), %rax
cmpl $0xb, (%rax)
jne 0x1465d6
movq $0x5, -0x30(%rbp)
jmp 0x1465f0
movq -0x10(%rbp), %rax
cmpl $0xc, (%rax)
jne 0x1465e9
movq $0xc, -0x30(%rbp)
jmp 0x1465ee
jmp 0x14673c
jmp 0x1465f0
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $0x6, %rcx
cmpq %rcx, %rax
jl 0x146624
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x146624
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl 0x4(%rax,%rcx), %eax
cmpl $0x20, %eax
je 0x146629
jmp 0x14673c
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
cmpq $0x20, -0x48(%rbp)
jbe 0x14664b
movq $0x20, -0x48(%rbp)
leaq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rax
addq $0x1, %rax
addq %rax, %rsi
movq -0x48(%rbp), %rdx
callq 0x15aa30
leaq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x8, %edx
callq 0x18fa00
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x885cf(%rip), %rsi     # 0x1cec5d
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
andq $0x49, %rax
cmpq $0x0, %rax
je 0x1466b2
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x14(%rax)
jmp 0x1466bf
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rax
addq $0x5, %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rax
addq $0x5, %rax
subq %rax, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x171fa0
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rdi
callq 0x172650
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x80e69(%rip), %rsi     # 0x1c7583
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x18(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x38(%rbp), %rdi
callq 0x171750
addq $0x80, %rsp
popq %rbp
retq
nop