// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x30, %rsp
leaq 0x12920(%rip), %rax     # 0x1d5b0
movl (%rax), %eax
movl %eax, (%rsp)
leaq 0x7bb6(%rip), %rax      # 0x12852
movq %rax, 0x8(%rsp)
leaq 0x12904(%rip), %rax     # 0x1d5ac
movl (%rax), %eax
movl %eax, 0x10(%rsp)
leaq 0x7ba8(%rip), %rax      # 0x1285d
movq %rax, 0x18(%rsp)
leaq 0x128f3(%rip), %rax     # 0x1d5b4
movl (%rax), %eax
movl %eax, 0x20(%rsp)
andb $-0x15, 0x13a2a(%rip)   # 0x1e6f8
leaq 0x7b93(%rip), %rax      # 0x12868
movq %rax, 0x28(%rsp)
movq 0x15a5f(%rip), %r14     # 0x20740
movl $0x0, 0x15aed(%rip)     # 0x207d8
movq 0x15a5e(%rip), %rax     # 0x20750
movb $0x0, (%r14,%rax)
cmpb $0x0, (%r14)
je 0xad36
xorl %eax, %eax
leaq 0x15a32(%rip), %rcx     # 0x20738
movq %r14, %rdx
movq %rdx, 0x20(%rcx,%rax,8)
incq %rax
incq %rdx
movzbl -0x1(%rdx), %esi
testl %esi, %esi
je 0xad30
cmpl $0x3b, %esi
jne 0xad11
movb $0x0, -0x1(%rdx)
cmpq $0x10, %rax
jne 0xad09
movl $0x10, %eax
movl %eax, 0x15aa2(%rip)     # 0x207d8
movl 0x15a9b(%rip), %r15d    # 0x207d8
testl %r15d, %r15d
je 0xad52
movq 0x15a0f(%rip), %rdi     # 0x20758
callq 0x6520
movl %eax, %ebx
jmp 0xad54
xorl %ebx, %ebx
movzbl 0x159dd(%rip), %eax     # 0x20738
cmpl $0x5d, %eax
jle 0xad8f
leal -0x5e(%rax), %ecx
cmpl $0x2, %ecx
jb 0xaedb
cmpl $0x6b, %eax
jne 0xaecb
movq 0x159dc(%rip), %rdi     # 0x20758
xorl %esi, %esi
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xc772
cmpl $0x50, %eax
je 0xae55
cmpl $0x5d, %eax
jne 0xaecb
cmpl $0xc, %ebx
ja 0xaeaf
movl %ebx, %eax
leaq 0x74e1(%rip), %rcx      # 0x12294
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x2, %r15d
jl 0xaecb
leal -0xd(%rbx), %eax
cmpl $-0x3, %eax
jb 0xaecb
movq 0x15987(%rip), %r14     # 0x20760
movslq %ebx, %r15
shlq $0x4, %r15
leaq 0x7aa0(%rip), %rsi      # 0x12887
movq %r14, %rdi
callq 0x66e0
movq %rsp, %r12
movl -0xa0(%r15,%r12), %esi
testl %eax, %eax
je 0xb026
movl %esi, %edi
movq %r14, %rsi
callq 0xc09a
testl %eax, %eax
jne 0xb06f
movb $0x0, 0x13835(%rip)     # 0x1e650
movl 0x13877(%rip), %edx     # 0x1e698
decl %edx
movl %edx, %eax
sarl $0x1f, %eax
andl %edx, %eax
cltq
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
incl %ecx
shlq $0x2, %rax
addq 0x13880(%rip), %rax     # 0x1e6c0
xorl %edx, %edx
movl $0x1, (%rax,%rdx,4)
incq %rdx
cmpl %edx, %ecx
jne 0xae42
jmp 0xaedb
leaq 0x7a74(%rip), %rsi      # 0x128d0
movl $0x3, %edx
movq %r14, %rdi
callq 0x6210
testl %eax, %eax
je 0xae8e
leaq 0x7a60(%rip), %rsi      # 0x128d4
movl $0x3, %edx
movq %r14, %rdi
callq 0x6210
testl %eax, %eax
jne 0xaedb
movb $0x0, 0x137c4(%rip)     # 0x1e650
jmp 0xaea6
leaq 0x137c3(%rip), %rsi     # 0x1e658
movl $0x1, %edi
callq 0x6150
movb $0x1, 0x137aa(%rip)     # 0x1e650
andb $-0x5, 0x13847(%rip)    # 0x1e6f4
jmp 0xaedb
cmpl $0x34, %ebx
je 0xaf2e
cmpl $0x68, %ebx
jne 0xaecb
xorl %r14d, %r14d
jmp 0xaf7f
cmpl $0x3, %r15d
jge 0xaf78
leaq 0x15bba(%rip), %rax     # 0x20a8c
cmpl $0x0, (%rax)
jne 0xaf6e
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r15d
jl 0xaedb
movq 0x1586b(%rip), %rdi     # 0x20760
jmp 0xad7c
cmpl $0x2, %r15d
jl 0xaedb
jmp 0xaf16
cmpl $0x2, %r15d
jl 0xaedb
movq 0x15851(%rip), %rdi     # 0x20760
xorl %esi, %esi
callq 0xc772
movq 0x15843(%rip), %rdi     # 0x20760
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xc6b5
cmpl $0x3, %r15d
jl 0xaedb
leaq 0x15b81(%rip), %rax     # 0x20abc
cmpl $0x0, (%rax)
je 0xaedb
movq 0x15821(%rip), %rdi     # 0x20768
callq 0xb19e
testq %rax, %rax
je 0xb0a4
movq %rax, %rdi
callq 0xbd62
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xbd00
callq 0x6e16
jmp 0xaedb
movq 0x157e9(%rip), %r14     # 0x20768
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, %r15d
jl 0xaf98
movq 0x157cf(%rip), %rdi     # 0x20760
callq 0x6520
movl %eax, %ebp
testq %r14, %r14
je 0xafb0
leaq 0x78e3(%rip), %rsi      # 0x12887
movq %r14, %rdi
callq 0x66e0
testl %eax, %eax
je 0xb01b
movl %ebp, %edi
movq %r14, %rsi
callq 0xc09a
testl %eax, %eax
je 0xafda
cmpl $0x1, %r15d
jg 0xb03b
cmpl $0x68, %ebx
jne 0xb03b
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xbdcf
movb $0x0, 0x1366f(%rip)     # 0x1e650
movl 0x136b1(%rip), %edx     # 0x1e698
decl %edx
movl %edx, %eax
sarl $0x1f, %eax
andl %edx, %eax
cltq
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
incl %ecx
shlq $0x2, %rax
addq 0x136ba(%rip), %rax     # 0x1e6c0
xorl %edx, %edx
movl $0x1, (%rax,%rdx,4)
incq %rdx
cmpl %edx, %ecx
jne 0xb008
jmp 0xaedb
movl %ebp, %edi
xorl %esi, %esi
movl $0x1, %edx
jmp 0xb02a
movl %ebx, %edi
xorl %edx, %edx
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xb2a6
testq %r14, %r14
movq 0x11fab(%rip), %rax     # 0x1cff0
movq (%rax), %rdi
leaq 0x787a(%rip), %rcx      # 0x128c9
cmovneq %r14, %rcx
leaq 0x784d(%rip), %rsi      # 0x128a7
movl %ebp, %edx
xorl %eax, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6970
leaq (%r15,%r12), %rax
addq $-0xa0, %rax
movq 0x11f70(%rip), %rcx     # 0x1cff0
movq (%rcx), %rdi
movq 0x8(%rax), %rdx
leaq 0x77fb(%rip), %rsi      # 0x12889
movq %r14, %rcx
xorl %eax, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6970
callq 0x6dfa
jmp 0xaedb