// File: /workspace/github_c_makefile_star2_O3/uobikiemukot[P]yaft/./ctrlseq/osc.h
// Function: glyph_width_report
void glyph_width_report(struct terminal_t *term, void *arg)
{
	/*
	glyph width report
		* request *
		OSC 8900 ; Ps ; Pw ; ? : Pf : Pt ST
			Ps: reserved
			Pw: width (0 or 1 or 2)
			Pfrom: beginning of unicode code point
			Pto: end of unicode code point
			ST: BEL(0x07) or ESC(0x1B) BACKSLASH(0x5C)
		* answer *
		OSC 8900 ; Ps ; Pv ; Pw ; Pf : Pt ; Pf : Pt ; ... ST
			Ps: responce code
				0: ok (default)
				1: recognized but not supported
				2: not recognized
			Pv: reserved (maybe East Asian Width Version)
			Pw: width (0 or 1 or 2)
			Pfrom: beginning of unicode code point
			Pto: end of unicode code point
			ST: BEL(0x07) or ESC(0x1B) BACKSLASH(0x5C)
	ref
		http://uobikiemukot.github.io/yaft/glyph_width_report.html
		https://gist.github.com/saitoha/8767268
	*/
	struct parm_t *pt = (struct parm_t *) arg, sub_parm;
	int i, argc = pt->argc, width, from, to, left, right, w, wcw; //reserved
	char **argv = pt->argv, buf[BUFSIZE];

	if (argc < 4)
		return;

	reset_parm(&sub_parm);
	parse_arg(argv[3], &sub_parm, ':', isdigit_or_questionmark);

	if (sub_parm.argc != 3 || *sub_parm.argv[0] != '?')
		return;

	//reserved = dec2num(argv[1]);
	width = dec2num(argv[2]);
	from  = dec2num(sub_parm.argv[1]);
	to    = dec2num(sub_parm.argv[2]);

	if ((width < 0) || (width > 2))
		return;

	/* unicode private area: plane 16 (DRCSMMv1) is always half */
	if ((from < 0) || (to >= UCS2_CHARS))
		return;

	snprintf(buf, BUFSIZE, "\033]8900;0;0;%d;", width); /* OSC 8900 ; Ps; Pv ; Pw ; */
	ewrite(term->fd, buf, strlen(buf));

	left = right = -1;
	for (i = from; i <= to; i++) {
		wcw = wcwidth(i);
		if (wcw <= 0) /* zero width */
			w = 0;
		else if (term->glyph[i] == NULL) /* missing glyph */
			w = wcw;
		else
			w = term->glyph[i]->width;

		if (w != width) {
			if (right != -1) {
				snprintf(buf, BUFSIZE, "%d:%d;", left, right);
				ewrite(term->fd, buf, strlen(buf));
			} else if (left != -1) {
				snprintf(buf, BUFSIZE, "%d:%d;", left, left);
				ewrite(term->fd, buf, strlen(buf));
			}
			left = right = -1;
		} else {
			if (left == -1)
				left = i;
			else
				right = i;
		}
	}

	if (right != -1) {
		snprintf(buf, BUFSIZE, "%d:%d;", left, right);
		ewrite(term->fd, buf, strlen(buf));
	} else if (left != -1) {
		snprintf(buf, BUFSIZE, "%d:%d;", left, left);
		ewrite(term->fd, buf, strlen(buf));
	}

	ewrite(term->fd, "\033\\", 2); /* ST (ESC BACKSLASH) */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4a8, %rsp            # imm = 0x4A8
cmpl $0x4, (%rsi)
jl 0x5cef
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x18(%rsp), %r15
movl $0x0, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r15)
movups %xmm0, 0x18(%r15)
movups %xmm0, 0x28(%r15)
movups %xmm0, 0x38(%r15)
movups %xmm0, 0x48(%r15)
movups %xmm0, 0x58(%r15)
movups %xmm0, 0x68(%r15)
movups %xmm0, 0x78(%r15)
movq 0x20(%rsi), %rdi
leaq -0x86(%rip), %rcx       # 0x5be6
movq %r15, %rsi
movl $0x3a, %edx
callq 0x2dbf
cmpl $0x3, (%r15)
jne 0x5cef
movq 0x20(%rsp), %rax
cmpb $0x3f, (%rax)
jne 0x5cef
movq 0x18(%r14), %rdi
xorl %r14d, %r14d
movl $0x0, %r15d
testq %rdi, %rdi
je 0x5caa
xorl %esi, %esi
movl $0xa, %edx
callq 0x2d12
movq %rax, %r15
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x5cc3
xorl %esi, %esi
movl $0xa, %edx
callq 0x2d12
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x5ce0
xorl %esi, %esi
movl $0xa, %edx
callq 0x2d12
movq %rax, 0x8(%rsp)
jmp 0x5ce9
movq $0x0, 0x8(%rsp)
cmpl $0x2, %r15d
jbe 0x5d01
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r14d, %r14d
js 0x5cef
cmpl $0xffff, 0x8(%rsp)      # imm = 0xFFFF
jg 0x5cef
leaq 0x4cf29(%rip), %rdx     # 0x52c40
leaq 0xa0(%rsp), %r13
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2120
movl (%rbx), %ebp
movq %r13, %rdi
callq 0x20d0
movl %ebp, %edi
movq %r13, %rsi
movq %rax, %rdx
callq 0x286e
cmpl 0x8(%rsp), %r14d
jg 0x5eab
movl %r14d, %eax
leaq (%rbx,%rax,8), %r12
addq $0x488, %r12            # imm = 0x488
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %r15, 0x10(%rsp)
movl %r14d, %edi
callq 0x21f0
movl $0x0, %ecx
testl %eax, %eax
jle 0x5d93
movq (%r12), %rcx
testq %rcx, %rcx
je 0x5d91
movzbl 0x4(%rcx), %ecx
jmp 0x5d93
movl %eax, %ecx
cmpl %r15d, %ecx
jne 0x5da9
cmpl $-0x1, %r13d
cmovnel %r14d, %ebp
cmovel %r14d, %r13d
jmp 0x5e4c
cmpl $-0x1, %ebp
jne 0x5e01
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %r13d
je 0x5e46
movl $0x400, %esi            # imm = 0x400
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
leaq 0x4ce7b(%rip), %rdx     # 0x52c4f
movl %r13d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2120
movl (%rbx), %r13d
movq %r15, %rdi
callq 0x20d0
movl %r13d, %edi
movq %r15, %rsi
movq 0x10(%rsp), %r15
movq %rax, %rdx
callq 0x286e
jmp 0x5e46
movl $0x400, %esi            # imm = 0x400
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
leaq 0x4ce37(%rip), %rdx     # 0x52c4f
movl %r13d, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x2120
movl (%rbx), %ebp
movq %r15, %rdi
callq 0x20d0
movl %ebp, %edi
movq %r15, %rsi
movq 0x10(%rsp), %r15
movq %rax, %rdx
callq 0x286e
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
addq $0x8, %r12
leal 0x1(%r14), %eax
cmpl %r14d, 0x8(%rsp)
movl %eax, %r14d
jg 0x5d71
cmpl $-0x1, %ebp
jne 0x5e70
movl %r13d, %ebp
cmpl $-0x1, %r13d
je 0x5eab
leaq 0x4cdd8(%rip), %rdx     # 0x52c4f
leaq 0xa0(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
movl %r13d, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x2120
movl (%rbx), %ebp
movq %r14, %rdi
callq 0x20d0
movl %ebp, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x286e
movl (%rbx), %edi
leaq 0x4cd89(%rip), %rsi     # 0x52c3d
movl $0x2, %edx
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x286e