// File: /workspace/github_c_makefile_star2_O3/mcaimi[P]st/st.c
// Function: strhandle
void
strhandle(void)
{
  char *p = NULL;
  int j, narg, par;

  const struct { int idx; char *str; } osc_table[] = {
    { defaultfg, "foreground" },
    { defaultbg, "background" },
    { defaultcs, "cursor" }
  };

  term.esc &= ~(ESC_STR_END|ESC_STR);
  strparse();
  par = (narg = strescseq.narg) ? atoi(strescseq.args[0]) : 0;

  switch (strescseq.type) {
  case ']': /* OSC -- Operating System Command */
    switch (par) {
    case 0:
      if (narg > 1) {
        xsettitle(strescseq.args[1], 0);
        xseticontitle(strescseq.args[1]);
      }
      return;
    case 1:
      if (narg > 1)
        xseticontitle(strescseq.args[1]);
      return;
    case 2:
      if (narg > 1)
        xsettitle(strescseq.args[1], 0);
      return;
    case 52:
      if (narg > 2 && allowwindowops) {
        char *dec;

        dec = base64dec(strescseq.args[2]);
        if (dec) {
          xsetsel(dec);
          xclipcopy();
        } else {
          fprintf(stderr, "erresc: invalid base64\n");
        }
      }
      return;
   case 10:
   case 11:
   case 12:
     if (narg < 2)
       break;

     p = strescseq.args[1];

     if ((j = par - 10) < 0 || j >= LEN(osc_table))
       break; // should not be possible

     if (!strcmp(p, "?")) {
       osc_color_response(par, osc_table[j].idx, 0);
     } else if (xsetcolorname(osc_table[j].idx, p)) {
       fprintf(stderr, "erresc: invalid %s color: %s\n", osc_table[j].str, p);
     } else {
       tfulldirt();
     }
     return;
    case 4: /* color set */
      if (narg < 3)
        break;
      p = strescseq.args[2];
      /* FALLTHROUGH */
    case 104: /* color reset */
      j = (narg > 1) ? atoi(strescseq.args[1]) : -1;

     if ( p && !strcmp(p, "?")) {
       osc_color_response(j, 0, 1);
     } else if (xsetcolorname(j, p)) {
        if (par == 104 && narg <= 1) {
          xloadcols();
          return; /* color reset without parameter */
        }
        fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
                j, p ? p : "(null)");
      } else {
        /*
         * TODO if defaultbg color is changed, borders
         * are dirty
         */
        tfulldirt();
      }
      return;
    }
    break;
  case 'k': /* old title set compatibility */
    xsettitle(strescseq.args[0], 0);
    return;
  case 'P': /* DCS -- Device Control String */
    /* https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec */
    if (strstr(strescseq.buf, "=1s") == strescseq.buf)
      tsync_begin(), term.mode &= ~ESC_STR;  /* BSU */
    else if (strstr(strescseq.buf, "=2s") == strescseq.buf)
      tsync_end(), term.mode &= ~ESC_STR;  /* ESU */
    return;
  case '_': /* APC -- Application Program Command */
  case '^': /* PM -- Privacy Message */
    return;
  }

  if (debug) { 
    fprintf(stderr, "erresc: unknown str "); 
    strdump();
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
leaq 0x1242f(%rip), %rax     # 0x1d5b0
movl (%rax), %eax
movl %eax, (%rsp)
leaq 0x76f3(%rip), %rax      # 0x12880
movq %rax, 0x8(%rsp)
leaq 0x12413(%rip), %rax     # 0x1d5ac
movl (%rax), %eax
movl %eax, 0x10(%rsp)
leaq 0x76e5(%rip), %rax      # 0x1288b
movq %rax, 0x18(%rsp)
leaq 0x12402(%rip), %rax     # 0x1d5b4
movl (%rax), %eax
movl %eax, 0x20(%rsp)
andb $-0x15, 0x13539(%rip)   # 0x1e6f8
leaq 0x76d0(%rip), %rax      # 0x12896
movq %rax, 0x28(%rsp)
movq 0x1556e(%rip), %r14     # 0x20740
movl $0x0, 0x155fc(%rip)     # 0x207d8
movq 0x1556d(%rip), %rax     # 0x20750
movb $0x0, (%r14,%rax)
cmpb $0x0, (%r14)
je 0xb23a
xorl %r15d, %r15d
leaq 0x15540(%rip), %rax     # 0x20738
movq %r14, %rcx
movq %rcx, 0x20(%rax,%r15,8)
incq %r15
incq %rcx
movzbl -0x1(%rcx), %edx
testl %edx, %edx
je 0xb223
cmpl $0x3b, %edx
jne 0xb203
movb $0x0, -0x1(%rcx)
cmpq $0x10, %r15
jne 0xb1fb
movl $0x10, %r15d
movl %r15d, 0x155ae(%rip)    # 0x207d8
movq 0x15527(%rip), %rdi     # 0x20758
callq 0x6520
movl %eax, %ebx
jmp 0xb23f
xorl %r15d, %r15d
xorl %ebx, %ebx
movzbl 0x154f2(%rip), %eax     # 0x20738
cmpl $0x5d, %eax
jle 0xb278
leal -0x5e(%rax), %ecx
cmpl $0x2, %ecx
jb 0xb4a5
cmpl $0x6b, %eax
jne 0xb495
movq 0x154f1(%rip), %rdi     # 0x20758
xorl %esi, %esi
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xcd63
cmpl $0x50, %eax
je 0xb409
cmpl $0x5d, %eax
jne 0xb495
cmpl $0xc, %ebx
ja 0xb459
movl %ebx, %eax
leaq 0x7028(%rip), %rcx      # 0x122c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x2, %r15d
jl 0xb495
movq 0x154aa(%rip), %r14     # 0x20760
leal -0xa(%rbx), %r15d
cmpb $0x3f, (%r14)
jne 0xb2cb
cmpb $0x0, 0x1(%r14)
je 0xb573
shlq $0x4, %r15
movl (%rsp,%r15), %edi
movq %r14, %rsi
callq 0xc6c4
testl %eax, %eax
jne 0xb6ea
movb $0x0, 0x13366(%rip)     # 0x1e650
movl 0x133a8(%rip), %eax     # 0x1e698
decl %eax
movl %eax, %ecx
sarl $0x1f, %ecx
andl %eax, %ecx
movq 0x133c0(%rip), %rdx     # 0x1e6c0
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
movslq %ecx, %rcx
leaq 0x4(%rsi), %rax
andq $-0x4, %rax
movq %rsi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq (%rdx,%rcx,4), %rcx
addq $0xc, %rcx
xorl %edx, %edx
movdqa 0x6cf2(%rip), %xmm1     # 0x12020
movdqa 0x6cfa(%rip), %xmm2     # 0x12030
movdqa 0x6d02(%rip), %xmm3     # 0x12040
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movq %rdx, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movdqa %xmm5, %xmm6
por %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0xb391
movl $0x1, -0xc(%rcx,%rdx,4)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0xb3a8
movl $0x1, -0x8(%rcx,%rdx,4)
por %xmm1, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
pxor %xmm4, %xmm5
pextrw $0x0, %xmm5, %esi
testb $0x1, %sil
je 0xb3e5
movl $0x1, -0x4(%rcx,%rdx,4)
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0xb3f7
movl $0x1, (%rcx,%rdx,4)
addq $0x4, %rdx
cmpq %rdx, %rax
jne 0xb346
jmp 0xb4a5
cmpb $0x3d, (%r14)
jne 0xb4a5
cmpb $0x31, 0x1(%r14)
jne 0xb43b
cmpb $0x73, 0x2(%r14)
jne 0xb43b
leaq 0x13230(%rip), %rsi     # 0x1e658
movl $0x1, %edi
callq 0x6150
movb $0x1, 0x13217(%rip)     # 0x1e650
jmp 0xb450
cmpb $0x32, 0x1(%r14)
jne 0xb4a5
cmpb $0x73, 0x2(%r14)
jne 0xb4a5
movb $0x0, 0x13200(%rip)     # 0x1e650
andb $-0x5, 0x1329d(%rip)    # 0x1e6f4
jmp 0xb4a5
cmpl $0x34, %ebx
je 0xb4f4
cmpl $0x68, %ebx
jne 0xb495
leaq 0x7487(%rip), %r14      # 0x128f5
cmpl $0x2, %r15d
jl 0xb56c
movq 0x152e1(%rip), %rdi     # 0x20760
callq 0x6520
movl %eax, %ebp
jmp 0xb595
cmpl $0x3, %r15d
jge 0xb53c
leaq 0x155f0(%rip), %rax     # 0x20a8c
cmpl $0x0, (%rax)
jne 0xb532
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r15d
jl 0xb4a5
movq 0x152a3(%rip), %rdi     # 0x20760
jmp 0xb267
cmpl $0x2, %r15d
jl 0xb4a5
jmp 0xb4de
cmpl $0x2, %r15d
jl 0xb4a5
movq 0x15289(%rip), %rdi     # 0x20760
xorl %esi, %esi
callq 0xcd63
movq 0x1527b(%rip), %rdi     # 0x20760
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xccac
cmpl $0x3, %r15d
jl 0xb4a5
leaq 0x155bb(%rip), %rax     # 0x20abc
cmpl $0x0, (%rax)
je 0xb4a5
movq 0x1525b(%rip), %rdi     # 0x20768
callq 0xb80c
testq %rax, %rax
je 0xb74c
movq %rax, %rdi
callq 0xc396
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xc334
callq 0x6e16
jmp 0xb4a5
movq 0x15225(%rip), %r14     # 0x20768
movq 0x15216(%rip), %rdi     # 0x20760
callq 0x6520
movl %eax, %ebp
testq %r14, %r14
je 0xb58e
cmpb $0x3f, (%r14)
jne 0xb567
cmpb $0x0, 0x1(%r14)
je 0xb717
movq %r14, %rsi
jmp 0xb597
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xb595
shlq $0x4, %r15
movl (%rsp,%r15), %esi
movl %ebx, %edi
xorl %edx, %edx
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xb913
leaq 0x7360(%rip), %r14      # 0x128f5
xorl %esi, %esi
movl %ebp, %edi
callq 0xc6c4
testl %eax, %eax
je 0xb5c4
cmpl $0x1, %r15d
jg 0xb725
cmpl $0x68, %ebx
jne 0xb725
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xc403
movb $0x0, 0x13085(%rip)     # 0x1e650
movl 0x130c7(%rip), %eax     # 0x1e698
decl %eax
movl %eax, %ecx
sarl $0x1f, %ecx
andl %eax, %ecx
movq 0x130df(%rip), %rdx     # 0x1e6c0
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
movslq %ecx, %rcx
leaq 0x4(%rsi), %rax
andq $-0x4, %rax
movq %rsi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq (%rdx,%rcx,4), %rcx
addq $0xc, %rcx
xorl %edx, %edx
movdqa 0x6a11(%rip), %xmm1     # 0x12020
movdqa 0x6a19(%rip), %xmm2     # 0x12030
movdqa 0x6a21(%rip), %xmm3     # 0x12040
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movq %rdx, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movdqa %xmm5, %xmm6
por %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0xb672
movl $0x1, -0xc(%rcx,%rdx,4)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0xb689
movl $0x1, -0x8(%rcx,%rdx,4)
por %xmm1, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
pxor %xmm4, %xmm5
pextrw $0x0, %xmm5, %esi
testb $0x1, %sil
je 0xb6c6
movl $0x1, -0x4(%rcx,%rdx,4)
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0xb6d8
movl $0x1, (%rcx,%rdx,4)
addq $0x4, %rdx
cmpq %rdx, %rax
jne 0xb627
jmp 0xb4a5
leaq (%rsp,%r15), %rax
movq 0x118fb(%rip), %rcx     # 0x1cff0
movq (%rcx), %rdi
movq 0x8(%rax), %rdx
leaq 0x71b2(%rip), %rsi      # 0x128b5
movq %r14, %rcx
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6970
movl %ebp, %edi
xorl %esi, %esi
movl $0x1, %edx
jmp 0xb57f
movq 0x118c4(%rip), %rax     # 0x1cff0
movq (%rax), %rdi
leaq 0x719d(%rip), %rsi      # 0x128d3
movl %ebp, %edx
movq %r14, %rcx
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x6970
callq 0x6dfa
jmp 0xb4a5