// File: /workspace/github_c_makefile_star2_O2/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 $0x228, %rsp            # imm = 0x228
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
andb $-0x8, 0x248(%rdi)
leaq 0x139cd(%rip), %rsi     # 0x20bf9
movq %rbx, %rdi
callq 0x5160
testl %eax, %eax
je 0xd368
leaq 0x139b1(%rip), %rsi     # 0x20bf4
movq %rbx, %rdi
callq 0x5160
testl %eax, %eax
je 0xd393
movq %rbx, %rdi
callq 0x50e0
leaq 0x1(%rax), %rdi
callq 0x6340
movq %rax, (%r14)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5080
movq 0x8(%rsp), %rax
testb $0x2, 0x248(%rax)
je 0xd293
pushq $0x28
popq %rdi
pushq $0x29
popq %rsi
callq 0xefde
testl %eax, %eax
je 0xd478
movq %r15, 0x18(%rsp)
movq %r14, (%rsp)
leaq 0x13951(%rip), %r12     # 0x20bf4
leaq 0x13954(%rip), %r14     # 0x20bfe
xorl %r13d, %r13d
callq 0xd0eb
movl %r13d, %r15d
testq %rax, %rax
je 0xd3e0
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
callq 0x5160
movl %eax, %ebp
testl %eax, %eax
jne 0xd30f
callq 0xf457
cmpb $0x28, %al
jne 0xd48e
callq 0xd0eb
testq %rax, %rax
je 0xd4b8
movq %rax, %rbx
pushq $0x28
popq %rdi
pushq $0x29
popq %rsi
callq 0xefde
testl %eax, %eax
je 0xd4e3
movq 0x8(%rsp), %rax
orb $0x4, 0x248(%rax)
cmpl $0x3e, %r13d
jbe 0xd321
movq %r14, %rdi
xorl %eax, %eax
callq 0x6b2c
jmp 0xd2ad
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x50e0
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %rdi
incq %rdi
callq 0x6340
movq %rax, 0x20(%rsp,%r15,8)
testl %ebp, %ebp
jne 0xd355
movb $0x24, (%rax)
incq %rax
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5080
incl %r13d
jmp 0xd2ad
callq 0xd0eb
testq %rax, %rax
je 0xd3be
movq %rax, %rbx
callq 0xf457
cmpb $0x28, %al
jne 0xd44e
movq 0x8(%rsp), %rax
orb $0x1, 0x248(%rax)
jmp 0xd23c
callq 0xd0eb
testq %rax, %rax
je 0xd3be
movq %rax, %rbx
callq 0xf457
cmpb $0x28, %al
jne 0xd44e
movq 0x8(%rsp), %rax
orb $0x2, 0x248(%rax)
jmp 0xd253
movq 0x2664b(%rip), %rbx     # 0x33a10
callq 0xf90a
xorl %ebp, %ebp
pushq $0x4e
popq %rdi
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6c19
jmp 0xd4f1
andq $0x0, 0x20(%rsp,%r15,8)
leaq 0x8(,%r15,8), %rbx
movq %rbx, %rdi
callq 0x6340
movq 0x18(%rsp), %r14
movq %rax, (%r14)
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x51a0
pushq $0x28
popq %rdi
pushq $0x29
popq %rsi
callq 0xefde
testl %eax, %eax
je 0xd47d
pushq $0x1
popq %rbp
movq 0x8(%rsp), %rax
testb $0x1, 0x248(%rax)
movq (%rsp), %rbx
je 0xd4f1
pushq $0x28
popq %rdi
pushq $0x29
popq %rsi
callq 0xefde
testl %eax, %eax
jne 0xd4f1
movq (%rbx), %rdi
jmp 0xd484
movq 0x265bb(%rip), %rbx     # 0x33a10
callq 0xf90a
xorl %ebp, %ebp
pushq $0x42
popq %rdi
pushq $0x28
popq %rcx
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6c19
pushq $0x1
popq %rdi
callq 0xf4ac
jmp 0xd4f1
movq (%r14), %rdi
jmp 0xd4ea
movq (%rsp), %rax
movq (%rax), %rdi
movq (%r14), %rsi
callq 0xcfb7
jmp 0xd4ef
movq 0x2657b(%rip), %rbx     # 0x33a10
callq 0xf90a
xorl %ebp, %ebp
pushq $0x42
popq %rdi
pushq $0x28
popq %rcx
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6c19
pushq $0x1
popq %rdi
callq 0xf4ac
jmp 0xd4d5
movq 0x26551(%rip), %rbx     # 0x33a10
callq 0xf90a
xorl %ebp, %ebp
pushq $0x4e
popq %rdi
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x6c19
movq (%rsp), %rax
movq (%rax), %rdi
callq 0x5040
jmp 0xd4f1
movq (%rsp), %rax
movq (%rax), %rdi
callq 0x5040
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq