// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]vlink/ldscript.c
// Function: parse_pattern
static bool parse_pattern(struct GlobalVars *gv,char *keyword,
                          char **fpat,char ***spatlist)
/* parse file/section-pattern and allocate pattern-lists */
{
  const char *sortcmd = "SORT";
  char *patternlist[64];   /* yes... it's ugly :| */
  int pcnt = 0;
  bool sortsec;

  gv->scriptflags &= ~(LDSF_KEEP | LDSF_SORTFIL | LDSF_SORTSEC);
  if (!strcmp(keyword,"KEEP")) {
    if (keyword = getpattern()) {
      if (getchr() != '(') {
        error(66,scriptname,getlineno(),'(');  /* '(' expected */
        back(1);
        return FALSE;
      }
    }
    else {
      error(78,scriptname,getlineno());   /* missing argument */
      return FALSE;
    }
    gv->scriptflags |= LDSF_KEEP;
  }

  if (!strcmp(keyword,sortcmd)) {
    if (keyword = getpattern()) {
      if (getchr() != '(') {
        error(66,scriptname,getlineno(),'(');  /* '(' expected */
        back(1);
        return FALSE;
      }
    }
    else {
      error(78,scriptname,getlineno());   /* missing argument */
      return FALSE;
    }
    gv->scriptflags |= LDSF_SORTFIL;
  }
  *fpat = alloc(strlen(keyword)+1);
  strcpy(*fpat,keyword);
  if (gv->scriptflags & LDSF_SORTFIL) {
    if (!endofblock('(',')')) {
      free(*fpat);
      return FALSE;
    }
  }

  while (keyword = getpattern()) {
    sortsec = FALSE;
    if (!strcmp(keyword,sortcmd)) {
      if (getchr() == '(') {
        if (!(keyword = getpattern())) {
          error(78,scriptname,getlineno());   /* missing argument */
          free(*fpat);
          return FALSE;
        }
      }
      else {
        error(66,scriptname,getlineno(),'(');  /* '(' expected */
        back(1);
        free(*fpat);
        return FALSE;
      }
      if (!endofblock('(',')')) {
        free(*fpat);
        return FALSE;
      }
      gv->scriptflags |= LDSF_SORTSEC;
      sortsec = TRUE;
    }

    if (pcnt < 63) {
      patternlist[pcnt] = alloc(strlen(keyword) + (sortsec ? 2 : 1));
      if (sortsec) {
        *patternlist[pcnt] = '$';   /* indicate sort-request */
        strcpy(patternlist[pcnt]+1,keyword);
      }
      else
        strcpy(patternlist[pcnt],keyword);
      pcnt++;
    }
    else
      ierror("parse_pattern(): pattern buffer overrun");
  }

  patternlist[pcnt++] = NULL;
  *spatlist = alloc(pcnt * sizeof(char *));
  memcpy(*spatlist,patternlist,pcnt*sizeof(char *));

  if (!endofblock('(',')')) {
    free_patterns(*fpat,*spatlist);
    return FALSE;
  }
  if (gv->scriptflags & LDSF_KEEP) {
    if (!endofblock('(',')')) {
      free_patterns(*fpat,*spatlist);
      return FALSE;
    }
  }
  return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
andb $-0x8, 0x248(%rdi)
leaq 0x15084(%rip), %rsi     # 0x22c08
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
je 0xdcd5
leaq 0x15068(%rip), %rsi     # 0x22c03
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
je 0xdcfd
movq %r12, %rdi
callq 0x50e0
leaq 0x1(%rax), %rdi
callq 0x6668
movq %rax, (%rbx)
movq %rax, %rdi
movq %r12, %rsi
callq 0x5080
testb $0x2, 0x248(%r15)
je 0xdbeb
movl $0x28, %edi
movl $0x29, %esi
callq 0xfb48
testl %eax, %eax
je 0xde11
movq %r14, 0x8(%rsp)
movq %rbx, (%rsp)
movl $0x5, %edi
callq 0x100e6
testq %rax, %rax
je 0xdd7c
movq %rax, %rbp
leaq 0x14ff2(%rip), %r12     # 0x22c03
xorl %ebx, %ebx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x5160
movl %eax, %r14d
testl %eax, %eax
jne 0xdc67
callq 0x1006f
cmpb $0x28, %al
jne 0xde16
movl $0x5, %edi
callq 0x100e6
testq %rax, %rax
je 0xde46
movq %rax, %rbp
movl $0x28, %edi
movl $0x29, %esi
callq 0xfb48
testl %eax, %eax
je 0xde73
orb $0x4, 0x248(%r15)
cmpl $0x3e, %ebx
jg 0xdcac
xorl %r13d, %r13d
testl %r14d, %r14d
sete %r13b
movq %rbp, %rdi
callq 0x50e0
leaq (%rax,%r13), %rdi
incq %rdi
callq 0x6668
movslq %ebx, %rcx
movq %rax, 0x10(%rsp,%rcx,8)
testl %r14d, %r14d
jne 0xdc9d
movb $0x24, (%rax)
incq %rax
movq %rax, %rdi
movq %rbp, %rsi
callq 0x5080
incl %ebx
jmp 0xdcba
leaq 0x14f5a(%rip), %rdi     # 0x22c0d
xorl %eax, %eax
callq 0x52b0
movl $0x5, %edi
callq 0x100e6
movq %rax, %rbp
testq %rax, %rax
jne 0xdc13
jmp 0xdd7e
movl $0x5, %edi
callq 0x100e6
testq %rax, %rax
je 0xdd25
movq %rax, %r12
callq 0x1006f
cmpb $0x28, %al
jne 0xdd49
orb $0x1, 0x248(%r15)
jmp 0xdb94
movl $0x5, %edi
callq 0x100e6
testq %rax, %rax
je 0xdd25
movq %rax, %r12
callq 0x1006f
cmpb $0x28, %al
jne 0xdd49
orb $0x2, 0x248(%r15)
jmp 0xdbab
movq 0x258f4(%rip), %rbx     # 0x33620
callq 0x10563
xorl %ebp, %ebp
movl $0x4e, %edi
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6f84
jmp 0xde81
movq 0x258d0(%rip), %rbx     # 0x33620
callq 0x10563
xorl %ebp, %ebp
movl $0x42, %edi
movq %rbx, %rsi
movl %eax, %edx
movl $0x28, %ecx
xorl %eax, %eax
callq 0x6f84
movl $0x1, %edi
callq 0x100d3
jmp 0xde81
xorl %ebx, %ebx
movslq %ebx, %rax
movq $0x0, 0x10(%rsp,%rax,8)
leaq 0x8(,%rax,8), %r14
movq %r14, %rdi
callq 0x6668
movq 0x8(%rsp), %rbx
movq %rax, (%rbx)
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x51a0
movl $0x28, %edi
movl $0x29, %esi
callq 0xfb48
testl %eax, %eax
je 0xde00
movl $0x1, %ebp
testb $0x1, 0x248(%r15)
je 0xde81
movl $0x28, %edi
movl $0x29, %esi
callq 0xfb48
testl %eax, %eax
jne 0xde81
movq (%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rsi
jmp 0xde0a
movq (%rsp), %rax
movq (%rax), %rdi
movq (%rbx), %rsi
callq 0xd898
jmp 0xde7f
movq (%rbx), %rdi
jmp 0xde7a
movq 0x25803(%rip), %r14     # 0x33620
callq 0x10563
xorl %ebp, %ebp
movl $0x42, %edi
movq %r14, %rsi
movl %eax, %edx
movl $0x28, %ecx
xorl %eax, %eax
callq 0x6f84
movl $0x1, %edi
callq 0x100d3
jmp 0xde65
movq 0x257d3(%rip), %r14     # 0x33620
callq 0x10563
xorl %ebp, %ebp
movl $0x4e, %edi
movq %r14, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6f84
movq (%rsp), %rax
movq (%rax), %rdi
callq 0x5040
jmp 0xde81
movq (%rsp), %rax
movq (%rax), %rdi
callq 0x5040
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq