// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-util.c
// Function: de_puts_advanced
static void de_puts_advanced(deark *c, unsigned int flags, const char *s)
{
	size_t s_len;
	size_t s_pos = 0;
	char *tmps = NULL;
	size_t tmps_pos = 0;
	int hlmode = 0;
	unsigned int special_code;
	u32 param1 = 0;

	s_len = de_strlen(s);
	tmps = de_malloc(c, (i64)s_len+1);

	// Search for characters that enable/disable highlighting,
	// and split the string at them.
	while(s_pos < s_len) {
		if(s[s_pos]=='\x01' || s[s_pos]=='\x02' || s[s_pos]=='\x03') {
			// Found a special code

			if(s[s_pos]=='\x02' && s[s_pos+1]=='\x01' && hlmode) {
				// Optimization: UNHL followed immediately by HL is a no-op.
				special_code = 0;
			}
			else if(s[s_pos]=='\x01') {
				special_code = DE_MSGCODE_HL;
				hlmode = 1;
			}
			else if(s[s_pos]=='\x03') {
				special_code = DE_MSGCODE_RGBSAMPLE;
				if(s_pos + 7 <= s_len) {
					param1 = DE_MAKE_RGB(
						((s[s_pos+1]&0x0f)<<4) | (s[s_pos+2]&0x0f),
						((s[s_pos+3]&0x0f)<<4) | (s[s_pos+4]&0x0f),
						((s[s_pos+5]&0x0f)<<4) | (s[s_pos+6]&0x0f));
				}
			}
			else {
				special_code = DE_MSGCODE_UNHL;
				hlmode = 0;
			}

			// Print what we have of the string before the special code
			if(tmps_pos>0) {
				tmps[tmps_pos] = '\0';
				c->msgfn(c, flags, tmps);
			}
			tmps_pos = 0;

			// "Print" the special code
			if(special_code && c->specialmsgfn) {
				c->specialmsgfn(c, flags, special_code, param1);
			}

			// Advance past the special code
			if(special_code==0)
				s_pos += 2;
			else if(special_code==DE_MSGCODE_RGBSAMPLE)
				s_pos += 7;
			else
				s_pos += 1;
		}
		else {
			tmps[tmps_pos++] = s[s_pos++];
		}
	}

	// Unset highlight, if it somehow got left on.
	if(hlmode && c->specialmsgfn) {
		c->specialmsgfn(c, flags, DE_MSGCODE_UNHL, 0);
	}

	tmps[tmps_pos] = '\0';
	c->msgfn(c, flags, tmps);
	de_free(c, tmps);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x18(%rbp), %rdi
callq 0x190e0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x15af79
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
je 0x15ad90
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2, %eax
je 0x15ad90
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3, %eax
jne 0x15af48
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2, %eax
jne 0x15adc5
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x15adc5
cmpl $0x0, -0x3c(%rbp)
je 0x15adc5
movl $0x0, -0x40(%rbp)
jmp 0x15aeac
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x15ade9
movl $0x1000, -0x40(%rbp)    # imm = 0x1000
movl $0x1, -0x3c(%rbp)
jmp 0x15aeaa
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3, %eax
jne 0x15ae9a
movl $0x2000, -0x40(%rbp)    # imm = 0x2000
movq -0x28(%rbp), %rax
addq $0x7, %rax
cmpq -0x20(%rbp), %rax
ja 0x15ae98
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
andl $0xf, %eax
shll $0x4, %eax
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rdx
movsbl 0x2(%rcx,%rdx), %ecx
andl $0xf, %ecx
orl %ecx, %eax
shll $0x10, %eax
orl $0xff000000, %eax       # imm = 0xFF000000
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rdx
movsbl 0x3(%rcx,%rdx), %ecx
andl $0xf, %ecx
shll $0x4, %ecx
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rsi
movsbl 0x4(%rdx,%rsi), %edx
andl $0xf, %edx
orl %edx, %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rdx
movsbl 0x5(%rcx,%rdx), %ecx
andl $0xf, %ecx
shll $0x4, %ecx
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rsi
movsbl 0x6(%rdx,%rsi), %edx
andl $0xf, %edx
orl %edx, %ecx
orl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x15aea8
movl $0x1100, -0x40(%rbp)    # imm = 0x1100
movl $0x0, -0x3c(%rbp)
jmp 0x15aeaa
jmp 0x15aeac
cmpq $0x0, -0x38(%rbp)
jbe 0x15aed7
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq 0x108(%rax), %rax
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x30(%rbp), %rdx
callq *%rax
movq $0x0, -0x38(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x15af0d
movq -0x8(%rbp), %rax
cmpq $0x0, 0x110(%rax)
je 0x15af0d
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x40(%rbp), %edx
movl -0x44(%rbp), %ecx
callq *%rax
cmpl $0x0, -0x40(%rbp)
jne 0x15af21
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x15af46
cmpl $0x2000, -0x40(%rbp)    # imm = 0x2000
jne 0x15af38
movq -0x28(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x28(%rbp)
jmp 0x15af44
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x15af46
jmp 0x15af74
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movb (%rax,%rcx), %dl
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x38(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x15ad4b
cmpl $0x0, -0x3c(%rbp)
je 0x15afa8
movq -0x8(%rbp), %rax
cmpq $0x0, 0x110(%rax)
je 0x15afa8
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0x1100, %edx           # imm = 0x1100
xorl %ecx, %ecx
callq *%rax
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq 0x108(%rax), %rax
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x30(%rbp), %rdx
callq *%rax
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
addq $0x50, %rsp
popq %rbp
retq
nop