// File: /workspace/github_c_makefile_star2_O2/neovim[P]libtermkey/driver-ti.c
// Function: start_driver
static int start_driver(TermKey *tk, void *info)
{
  TermKeyTI *ti = info;
  struct stat statbuf;
  char *start_string;
  size_t len;

  if(!ti->root)
    load_terminfo(ti);

  start_string = ti->start_string;

  if(tk->fd == -1 || !start_string)
    return 1;

  /* The terminfo database will contain keys in application cursor key mode.
   * We may need to enable that mode
   */

  /* There's no point trying to write() to a pipe */
  if(fstat(tk->fd, &statbuf) == -1)
    return 0;

#ifndef _WIN32
  if(S_ISFIFO(statbuf.st_mode))
    return 1;
#endif

  // Can't call putp or tputs because they suck and don't give us fd control
  len = strlen(start_string);
  while(len) {
    size_t written = write(tk->fd, start_string, len);
    if(written == -1)
      return 0;
    start_string += written;
    len -= written;
  }
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
movq %rdi, %r15
cmpq $0x0, 0x10(%rsi)
jne 0x5f5f
movq 0x8(%r14), %rdi
pushq $0x1
popq %rbp
leaq 0x50(%rsp), %rdx
movl %ebp, %esi
callq 0x3200
testl %eax, %eax
jne 0x5f5f
xorl %edi, %edi
movl $0xff, %esi
callq 0x6179
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x5f5f
movq %r14, (%rsp)
movq %r15, 0x8(%rsp)
pushq $0xc
popq %r15
leaq 0x4c6d(%rip), %r13      # 0xa9f0
leaq 0x10(%rsp), %r12
cmpq $0x3e4, %r15            # imm = 0x3E4
je 0x5e3b
movq -0xc(%r15,%r13), %rbx
movq %r12, %rdi
leaq 0x1939(%rip), %rsi      # 0x76dd
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3280
movl -0x4(%r15,%r13), %r14d
movq (%r15,%r13), %xmm1
movd %r14d, %xmm0
movdqa %xmm1, 0x30(%rsp)
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
pshufd $0xa1, %xmm1, %xmm0     # xmm0 = xmm1[1,0,2,2]
movdqa %xmm0, 0x50(%rsp)
movq (%rsp), %rdi
movq %r12, %rsi
leaq 0x50(%rsp), %rdx
callq 0x61cd
testb %al, %al
je 0x5e32
movq %r12, %rdi
leaq 0x18f2(%rip), %rsi      # 0x76e4
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3280
movl %r14d, 0x20(%rsp)
movdqa 0x30(%rsp), %xmm0
movd %xmm0, 0x24(%rsp)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
orl $0x1, %eax
movl %eax, 0x28(%rsp)
movl %eax, 0x2c(%rsp)
movq (%rsp), %rdi
movq %r12, %rsi
leaq 0x20(%rsp), %rdx
callq 0x61cd
addq $0x18, %r15
jmp 0x5d88
leaq 0x18aa(%rip), %r15      # 0x76ec
leaq 0x47(%rsp), %r12
leaq 0x10(%rsp), %r13
cmpl $0xff, %ebp
je 0x5e8a
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x3280
movl $0x1, 0x10(%rsp)
movl %ebp, 0x14(%rsp)
andq $0x0, 0x18(%rsp)
movq (%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x61cd
incl %ebp
testb %al, %al
jne 0x5e4c
movq (%rsp), %r14
cmpq $0x0, 0x8(%r14)
je 0x5ea6
leaq 0x1858(%rip), %rdi      # 0x76f4
callq 0x3260
movq %rax, %r15
jmp 0x5ea9
xorl %r15d, %r15d
movq (%r14), %rcx
movq 0x78(%rcx), %rax
testq %rax, %rax
je 0x5ecb
movq 0x80(%rcx), %rdx
leaq 0x1831(%rip), %rdi      # 0x76f4
movq %r15, %rsi
callq *%rax
movq %rax, %r15
testq %r15, %r15
je 0x5eff
leaq 0x1827(%rip), %rsi      # 0x76fe
movq %r15, %rdi
callq 0x3170
testl %eax, %eax
jne 0x5eff
pushq $0x3
popq %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x6257
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x6291
movq 0x50ca(%rip), %rax      # 0xafd0
movq (%rax), %rax
movq 0x20(%rax), %rbx
movq 0x2c8(%rbx), %rdi
testq %rdi, %rdi
je 0x5f20
callq 0x32b0
jmp 0x5f22
xorl %eax, %eax
movq 0x8(%rsp), %r15
movq %rax, 0x18(%r14)
movq 0x2c0(%rbx), %rdi
testq %rdi, %rdi
je 0x5f3e
callq 0x32b0
jmp 0x5f40
xorl %eax, %eax
movq %rax, 0x20(%r14)
movq 0x8(%r14), %rdi
callq 0x3050
andq $0x0, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x636d
movq %rax, 0x10(%r14)
pushq $0x1
popq %rbp
movq 0x18(%r14), %r14
movl (%r15), %edi
cmpl $-0x1, %edi
setne %al
testq %r14, %r14
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x5fc7
leaq 0x50(%rsp), %rsi
callq 0x32d0
cmpl $-0x1, %eax
je 0x5fc5
movl $0xf000, %eax           # imm = 0xF000
andl 0x68(%rsp), %eax
cmpl $0x1000, %eax           # imm = 0x1000
je 0x5fc7
movq %r14, %rdi
callq 0x3100
movq %rax, %rbx
testq %rbx, %rbx
je 0x5fc7
movl (%r15), %edi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x30f0
addq %rax, %r14
subq %rax, %rbx
cmpq $-0x1, %rax
jne 0x5fa6
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq