// File: /workspace/github_c_makefile_star2_O2/42Bastian[P]lyxass/parser.c
// Function: GetLabel
int GetLabel(label_t *Label)
{
  extern int LabelTable[256];
  extern int mac_mode;

  int len = 0;
  char varhelp[6],*varptr = varhelp;
  char *ptr = Label->name;

  memset((char *)Label,0,sizeof(label_t));

  Label->type = UNSURE;

  sprintf(varhelp,"%04x",Global.var & 0xffff);

  if ( TestAtom('.') ){

    if ( !atom ) return  Error(LABEL_ERR,"");

    Label->type = LOCAL;

    if (atom != '\\' && LabelTable[atom]) {
      do {
        if ( atom == '@' ){
          varptr = varhelp;
          while( *varptr ){
            *ptr++ = *varptr++;
            len++;
          }
        } else {
          len++;
          *ptr++ = atom;
        }
      } while ( GetAtom() && LabelTable[atom] );

      if ( /*mac_mode &&*/ atom == ':' ){
        GetAtom();
      }
    } else {
      Label->type |= MACRO;

      if ( !GetAtom() ) return Error(LABEL_ERR,"");
      if ( atom == '~' ){
        char *ptr1 = (char *)calloc(10,1);

        GetAtom();
        if ( mac_mode ){
          *ptr++='M';
          ++len;
        }
        sprintf(ptr1,"%04X",Current.Macro.invoked);

        while(*ptr1){
          *ptr++=*ptr1++;
          ++len;
        }
      }
      if ( isalpha(atom) || atom == '_') {
        do{
          if ( atom == '@' ){
            varptr = varhelp;
            while( *varptr ){
              *ptr++ = *varptr++;
              len++;
            }
          } else {
            len++;
            *ptr++ = atom;
          }
        }while ( GetAtom() && LabelTable[atom] );
      }
      if ( /*mac_mode &&*/ atom == ':' ){
        GetAtom();
      }
    }
  } else if ( isalpha(atom) || atom == '_') {

    Label->type = UNSURE|NORMAL;
    do{
      if ( atom == '@' ){
        varptr = varhelp;
        while( *varptr ){
          *ptr++ = *varptr++;
          len++;
        }
      } else if ( atom == '$' ){
        label_t label;
        char help[10], *p = help;
        int32_t l;

        GetAtom();
        if ( GetLabel( &label ) ) return 1;
        if ( !FindLabel( &label, &l) ) return 1;

        sprintf(help,"%08X",l);
        while ( *p ){
          *ptr++=*p++;
        }
        break;
      } else {
        len++;
        *ptr++ = atom;
      }
    }while ( GetAtom() && (LabelTable[atom] || atom == '$'));
  } else if ( atom == '\\' && Current.Macro.Define ){
    GetAtom();
    if ( (atom >= '0' && atom <= '9') ||
         (atom >= 'a' && atom <= 'f') ||
         (atom >= 'A' && atom <= 'F')){
      GetAtom();
      return 0;
    }
  }
  *ptr++ = 0;
  // must return here 1 for GPU/DSP mode
  if ( len == 0 ) return 1; //Error(LABEL_ERR,"");

  if ( atom == ':' ){
    GetAtom();
    if ( !(Label->type & NORMAL) && !mac_mode ) return Error(LABEL_ERR,"");

    Label->type  = NORMAL;

    if ( atom == ':'  ){
      Label->type = GLOBAL;
      GetAtom();
    }
  }

  Label->len   = len;
  Label->file  = Current.File;
  Label->line  = Current.Line;
  Label->value = Global.pc;

//->  printf("GetLabel:%d(%s)%p %p\n",len,Label->name,Label->name,ptr);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
leaq 0x38(%rdi), %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movups %xmm0, 0x50(%rdi)
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movl $0x20, 0x4(%rdi)
leaq 0xf3d3(%rip), %r12      # 0x143b0
movzwl 0x18(%r12), %edx
leaq 0x70fc(%rip), %rsi      # 0xc0e6
leaq 0x8(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x31b0
pushq $0x2e
popq %rdi
callq 0x4da7
testl %eax, %eax
je 0x508e
movslq 0x17f20(%rip), %rcx     # 0x1cf30
testq %rcx, %rcx
je 0x5163
movl $0x2, 0x4(%rbx)
cmpl $0x5c, %ecx
je 0x510d
leaq 0x18780(%rip), %r13     # 0x1d7b0
cmpl $0x0, (%r13,%rcx,4)
je 0x510d
xorl %ebp, %ebp
cmpl $0x40, %ecx
jne 0x5059
movq %r14, %rax
movb (%rax), %cl
testb %cl, %cl
je 0x5061
incq %rax
movb %cl, (%r15)
incq %r15
incl %ebp
jmp 0x5046
incl %ebp
movb %cl, (%r15)
incq %r15
callq 0x4d44
movl 0x17ec4(%rip), %ecx     # 0x1cf30
testl %eax, %eax
je 0x507b
movslq %ecx, %rax
cmpl $0x0, (%r13,%rax,4)
jne 0x503e
cmpl $0x3a, %ecx
jne 0x52fc
callq 0x4d44
jmp 0x52fc
callq 0x31e0
movslq 0x17e96(%rip), %rcx     # 0x1cf30
cmpq $0x5f, %rcx
je 0x5180
movq (%rax), %rax
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
jne 0x5180
cmpl $0x5c, %ecx
jne 0x51e4
leaq 0xf542(%rip), %rax      # 0x14608
cmpl $0x0, 0xc(%rax)
je 0x51e4
callq 0x4d44
movl 0x17e55(%rip), %eax     # 0x1cf30
leal -0x30(%rax), %ecx
cmpl $0xa, %ecx
jb 0x5103
addl $-0x41, %eax
cmpl $0x25, %eax
ja 0x51e4
movabsq $0x3f0000003f, %rcx     # imm = 0x3F0000003F
btq %rax, %rcx
jae 0x51e4
callq 0x4d44
jmp 0x5357
movl $0x6, 0x4(%rbx)
callq 0x4d44
testl %eax, %eax
je 0x5163
movl 0x17e0c(%rip), %r14d    # 0x1cf30
xorl %ebp, %ebp
cmpl $0x7e, %r14d
jne 0x5284
pushq $0xa
popq %rdi
pushq $0x1
popq %rsi
callq 0x3100
movq %rax, %r14
callq 0x4d44
leaq 0x18a66(%rip), %rax     # 0x1dbb0
cmpl $0x0, (%rax)
je 0x524c
pushq $0x1
popq %rbp
leaq 0x39(%rbx), %r15
movb $0x4d, 0x38(%rbx)
jmp 0x524e
leaq 0x6e28(%rip), %rsi      # 0xbf92
pushq $0x3
popq %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x96cc
movl $0x21, 0x4(%rbx)
xorl %ebp, %ebp
leaq 0x8(%rsp), %r14
leaq 0x1861b(%rip), %r13     # 0x1d7b0
cmpl $0x40, %ecx
je 0x51ce
cmpl $0x24, %ecx
je 0x51ed
incl %ebp
movb %cl, (%r15)
incq %r15
callq 0x4d44
testl %eax, %eax
je 0x52fc
movslq 0x17d75(%rip), %rcx     # 0x1cf30
cmpq $0x24, %rcx
je 0x5195
cmpl $0x0, (%r13,%rcx,4)
jne 0x5195
jmp 0x52fc
movq %r14, %rax
movb (%rax), %cl
testb %cl, %cl
je 0x51a7
incq %rax
movb %cl, (%r15)
incq %r15
incl %ebp
jmp 0x51d1
movb $0x0, (%r15)
jmp 0x535b
callq 0x4d44
leaq 0x18(%rsp), %rdi
callq 0x4fa0
testl %eax, %eax
jne 0x535b
leaq 0x18(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x59a0
testq %rax, %rax
je 0x535b
movl 0x4(%rsp), %edx
leaq 0x6ec4(%rip), %rsi      # 0xc0eb
xorl %r14d, %r14d
leaq 0xe(%rsp), %rdi
xorl %eax, %eax
callq 0x31b0
movb 0xe(%rsp,%r14), %al
testb %al, %al
je 0x537e
movb %al, (%r15,%r14)
incq %r14
jmp 0x5236
xorl %ebp, %ebp
leaq 0xf3b3(%rip), %rax      # 0x14608
movl 0x24(%rax), %edx
leaq 0x6e82(%rip), %rsi      # 0xc0e1
movq %r14, %rdi
xorl %eax, %eax
callq 0x31b0
movb (%r14), %al
testb %al, %al
je 0x527d
incq %r14
movb %al, (%r15)
incq %r15
incl %ebp
jmp 0x5269
movl 0x17cac(%rip), %r14d    # 0x1cf30
callq 0x31e0
cmpl $0x5f, %r14d
je 0x52a0
movq (%rax), %rax
movslq %r14d, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0x52ea
leaq 0x8(%rsp), %r13
leaq 0x18504(%rip), %r12     # 0x1d7b0
cmpl $0x40, %r14d
jne 0x52c8
movq %r13, %rax
movb (%rax), %cl
testb %cl, %cl
je 0x52d0
incq %rax
movb %cl, (%r15)
incq %r15
incl %ebp
jmp 0x52b5
incl %ebp
movb %r14b, (%r15)
incq %r15
callq 0x4d44
movl 0x17c54(%rip), %r14d    # 0x1cf30
testl %eax, %eax
je 0x52ea
movslq %r14d, %rax
cmpl $0x0, (%r12,%rax,4)
jne 0x52ac
cmpl $0x3a, %r14d
jne 0x52f5
callq 0x4d44
leaq 0xf0b4(%rip), %r12      # 0x143b0
movb $0x0, (%r15)
testl %ebp, %ebp
je 0x535b
cmpl $0x3a, 0x17c25(%rip)    # 0x1cf30
jne 0x533f
callq 0x4d44
movl 0x4(%rbx), %eax
andl $0x1, %eax
leaq 0x18891(%rip), %rcx     # 0x1dbb0
orl (%rcx), %eax
je 0x536d
movl $0x1, 0x4(%rbx)
cmpl $0x3a, 0x17bff(%rip)    # 0x1cf30
jne 0x533f
movl $0x8, 0x4(%rbx)
callq 0x4d44
movl %ebp, (%rbx)
leaq 0xf2c0(%rip), %rax      # 0x14608
movq (%rax), %rax
movq %rax, 0x10(%rbx)
movl (%r12), %eax
movq %rax, 0x8(%rbx)
xorl %eax, %eax
jmp 0x535e
pushq $0x1
popq %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6c1e(%rip), %rsi      # 0xbf92
pushq $0x3
popq %rdi
callq 0x96cc
jmp 0x535e
addq %r14, %r15
jmp 0x52fc