// File: /workspace/github_c_makefile_star2_O0/42Bastian[P]lyxass/label.c
// Function: DefineLabel
label_t * DefineLabel(label_t *l, int *solved)
{
  int hashvalue;
  label_t *ptr;
  label_t *_this;
//->  extern int mac_mode;

  *solved = 0;

  //mesg("DefineLabel");

//->   printf("Type:%02x\n",l->type);

  if ( (l->type & GLOBAL) || (l->type & NORMAL) ){

    if ( n_global == MAX_GLOBAL_LABELS ){
      Error(TOOMANY_ERR,"");
      return NULL;
    }

    // clear local-labels
    if ( (l->type & GLOBAL) /*|| mac_mode*/ ){

      CheckForUnsolvedLocals();
      next_local = local_labels;
      local_hook = NULL;
      memset((char *)local_labels, 0, sizeof(label_t)*MAX_LOCAL_LABELS);

    }
    // get hash-value

    hashvalue = ComputeHash(l->name);

    //printf("Hashvalue: %d %p ",hashvalue,hash[hashvalue]);

    // check first hash-tab.
    if ( (ptr = hash[hashvalue]) == NULL ){
      hash[hashvalue] = next_global;
    }

    // go through all lables, check if _this one is already used
    // if not, go until the end is reached.

    else {
      do{
        if ( ptr->len == l->len && ! strcmp(l->name, ptr->name) ){
          if ( (ptr->type & REGISTER) ){
            l->type |= REGISTER;
            l->file = Current.File;
            return ptr;
          } else
            if ( (ptr->type & VARIABLE) ){
            //printf("LABEL:(%s)%d\n",next->name,next->value);
            l->type |= VARIABLE;
            return ptr;
          } else if ( ptr->type & UNSOLVED ){
            l->next = ptr->next;
            *ptr = *l;
            *solved = 1;
            return ptr;
          } else {
            Error(REDEF_ERR,(char *) ptr);
            return NULL;
          }
        }
        if ( ! ptr->next ) break;
        ptr = ptr->next;
      } while ( 1 );
      ptr->next = next_global;
    }

    // copy temp. data into buffer
    _this = next_global;

    *next_global++ = *l;
    ++n_global;

    //    printf("next_global:%p\n",next_global);
    return _this;
  } // global or normal label

  /* define a macro-label : .\xxx */

  if ( (l->type & (MACRO|LOCAL)) == (MACRO|LOCAL) ){

    //mesg("macro-label");

    if ( n_localmacro == MAX_MACRO_LABELS ){
      Error(LMTOOMANY_ERR,"");
      return NULL;
    }

    if ( (ptr = macro_hook) == NULL){
      macro_hook = next_macro;
    } else {
      do{
        if ( (ptr->len == l->len) &&
             ! strcmp(l->name, ptr->name) ){
          if ( ptr->type & VARIABLE ){
            //      printf("LABEL:(%s)%d\n",ptr->name,ptr->value);
            l->type |= VARIABLE;
            return ptr;
          } else if ( ptr->type & UNSOLVED ){
            l->next = ptr->next;
            *ptr = *l;
            *solved = 1;
            return ptr;
          } else {
            // re-definition allowed
            ptr->line = l->line;
            ptr->file = l->file;
            ptr->value = l->value;
            return ptr;
            //      Error(REDEF_ERR,(char *) ptr);
            //      return NULL;
          }

        }
        if ( !ptr->next ) break;
        ptr = ptr->next;
      } while ( 1 );
      ptr->next = next_macro;
    }

    l->next = (label_t *)NULL;
    _this = next_macro;
    *next_macro++ = *l;
    ++n_localmacro;
    //    printf("macro %s %02x",_this->name,_this->type);
    return _this;
  }

  /* define a local label : .xxx */

  if ( (l->type & LOCAL) == LOCAL  ){

    //mesg("local label");

    if ( n_local == MAX_LOCAL_LABELS ){
      Error(LTOOMANY_ERR,"");
      return NULL;
    }

    if ( (ptr = local_hook) == NULL){
      local_hook = next_local;
    } else {
      do{
        if ( (ptr->len == l->len) &&
             ! strcmp(l->name, ptr->name) ){
          if ( ptr->type & VARIABLE ){
            //printf("LABEL:(%s)%d\n",ptr->name,ptr->value);
            l->type |= VARIABLE;
            return ptr;
          } else if ( ptr->type & UNSOLVED ){
            l->next = ptr->next;
            *ptr = *l;
            *solved = 1;
            return ptr;
          } else {
            Error(REDEF_ERR,(char *) ptr);
            return NULL;
          }
        }
        if ( !ptr->next ) break;
        ptr = ptr->next;
      } while ( 1 );

      ptr->next = next_local;
    }

    l->next = (label_t *)NULL;
    _this = next_local;
    *next_local++ = *l;
    ++n_local;

    //    printf("%s (%d,%d)-%s-\n ",l->name,l->line,l->value,srcLine);
    return _this;
  }

  /* define a macro-name */

  if ( l->type == MACRO  ){

    // mesg("macro - name");

    if ( n_macro == MAX_MACROS ){
      Error(MTOOMANY_ERR,"");
      return NULL;
    }

    if ( (ptr = macroname_hook) == NULL){
      macroname_hook = next_macroname;
    } else {

      for ( ; ptr->next ; ptr = ptr->next ){
        if ( (ptr->len == l->len) &&
             ! strcmp(l->name, ptr->name) ){
          Error(REDEF_ERR,(char *) ptr);
          return NULL;
        }
      }
      ptr->next = next_macroname;
    }

    l->next = (label_t *)NULL;
    _this = next_macroname;
    *next_macroname++ = *l;
    ++n_macro;

    return _this;
  }
  return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x684c
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6a74
cmpl $0x2000, 0x1a6f6(%rip)  # imm = 0x2000
jne 0x6876
movl $0xb, %edi
leaq 0xa7f9(%rip), %rsi      # 0x1105d
callq 0xd130
movq $0x0, -0x8(%rbp)
jmp 0x6f08
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x68b8
movb $0x0, %al
callq 0x4bc0
movq 0x1aecd(%rip), %rax     # 0x21760
movq %rax, 0x1aece(%rip)     # 0x21768
movq $0x0, 0x1a68b(%rip) # 0x20f30
movq 0x1aeb4(%rip), %rdi     # 0x21760
xorl %esi, %esi
movl $0xc000, %edx           # imm = 0xC000
callq 0x30c0
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
callq 0x6770
movl %eax, -0x1c(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x1a68d(%rip), %rax     # 0x20f60
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x68fc
movq 0x1ae90(%rip), %rdx     # 0x21778
movslq -0x1c(%rbp), %rcx
leaq 0x1a66d(%rip), %rax     # 0x20f60
movq %rdx, (%rax,%rcx,8)
jmp 0x6a2a
jmp 0x68fe
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x69f6
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
callq 0x3100
cmpl $0x0, %eax
jne 0x69f6
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x6968
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
orl $0x40, %ecx
movl %ecx, 0x4(%rax)
leaq 0x11ca7(%rip), %rax     # 0x185f8
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x6991
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x69db
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x60, %edx
callq 0x3140
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rsi
movl $0x7, %edi
callq 0xd130
movq $0x0, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x6a03
jmp 0x6a1b
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x68fe
jmp 0x6a1b
movq 0x1ad56(%rip), %rcx     # 0x21778
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq 0x1ad47(%rip), %rax     # 0x21778
movq %rax, -0x30(%rbp)
movq 0x1ad3c(%rip), %rdi     # 0x21778
movq %rdi, %rax
addq $0x60, %rax
movq %rax, 0x1ad2e(%rip)     # 0x21778
movq -0x10(%rbp), %rsi
movl $0x60, %edx
callq 0x3140
movl 0x1a4ee(%rip), %eax     # 0x20f4c
addl $0x1, %eax
movl %eax, 0x1a4e5(%rip)     # 0x20f4c
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x6, %eax
cmpl $0x6, %eax
jne 0x6c3d
cmpl $0x200, 0x1a4bf(%rip)   # imm = 0x200
jne 0x6ab1
movl $0xc, %edi
leaq 0xa5be(%rip), %rsi      # 0x1105d
callq 0xd130
movq $0x0, -0x8(%rbp)
jmp 0x6f08
movq 0x1a480(%rip), %rax     # 0x20f38
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x6ad5
movq 0x1acbf(%rip), %rax     # 0x21788
movq %rax, 0x1a468(%rip)     # 0x20f38
jmp 0x6be7
jmp 0x6ad7
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x6bb3
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
callq 0x3100
cmpl $0x0, %eax
jne 0x6bb3
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x6b30
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x6b7a
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x60, %edx
callq 0x3140
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x6bc0
jmp 0x6bd8
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x6ad7
jmp 0x6bd8
movq 0x1aba9(%rip), %rcx     # 0x21788
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq 0x1ab8e(%rip), %rax     # 0x21788
movq %rax, -0x30(%rbp)
movq 0x1ab83(%rip), %rdi     # 0x21788
movq %rdi, %rax
addq $0x60, %rax
movq %rax, 0x1ab75(%rip)     # 0x21788
movq -0x10(%rbp), %rsi
movl $0x60, %edx
callq 0x3140
movl 0x1a329(%rip), %eax     # 0x20f50
addl $0x1, %eax
movl %eax, 0x1a320(%rip)     # 0x20f50
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x2, %eax
cmpl $0x2, %eax
jne 0x6de8
cmpl $0x200, 0x1a2ee(%rip)   # imm = 0x200
jne 0x6c7a
movl $0xd, %edi
leaq 0xa3f5(%rip), %rsi      # 0x1105d
callq 0xd130
movq $0x0, -0x8(%rbp)
jmp 0x6f08
movq 0x1a2af(%rip), %rax     # 0x20f30
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x6c9e
movq 0x1aad6(%rip), %rax     # 0x21768
movq %rax, 0x1a297(%rip)     # 0x20f30
jmp 0x6d92
jmp 0x6ca0
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x6d5e
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
callq 0x3100
cmpl $0x0, %eax
jne 0x6d5e
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x6cf9
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x6d43
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x60, %edx
callq 0x3140
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rsi
movl $0x7, %edi
callq 0xd130
movq $0x0, -0x8(%rbp)
jmp 0x6f08
movq -0x28(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x6d6b
jmp 0x6d83
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x6ca0
jmp 0x6d83
movq 0x1a9de(%rip), %rcx     # 0x21768
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq 0x1a9c3(%rip), %rax     # 0x21768
movq %rax, -0x30(%rbp)
movq 0x1a9b8(%rip), %rdi     # 0x21768
movq %rdi, %rax
addq $0x60, %rax
movq %rax, 0x1a9aa(%rip)     # 0x21768
movq -0x10(%rbp), %rsi
movl $0x60, %edx
callq 0x3140
movl 0x1a176(%rip), %eax     # 0x20f48
addl $0x1, %eax
movl %eax, 0x1a16d(%rip)     # 0x20f48
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq -0x10(%rbp), %rax
cmpl $0x4, 0x4(%rax)
jne 0x6f00
cmpl $0x400, 0x1a154(%rip)   # imm = 0x400
jne 0x6e20
movl $0xe, %edi
leaq 0xa24f(%rip), %rsi      # 0x1105d
callq 0xd130
movq $0x0, -0x8(%rbp)
jmp 0x6f08
movq 0x1a119(%rip), %rax     # 0x20f40
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x6e41
movq 0x1a960(%rip), %rax     # 0x21798
movq %rax, 0x1a101(%rip)     # 0x20f40
jmp 0x6ead
jmp 0x6e43
movq -0x28(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x6e9e
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x6e8e
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movq -0x28(%rbp), %rsi
addq $0x38, %rsi
callq 0x3100
cmpl $0x0, %eax
jne 0x6e8e
movq -0x28(%rbp), %rsi
movl $0x7, %edi
callq 0xd130
movq $0x0, -0x8(%rbp)
jmp 0x6f08
jmp 0x6e90
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x6e43
movq 0x1a8f3(%rip), %rcx     # 0x21798
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq 0x1a8d8(%rip), %rax     # 0x21798
movq %rax, -0x30(%rbp)
movq 0x1a8cd(%rip), %rdi     # 0x21798
movq %rdi, %rax
addq $0x60, %rax
movq %rax, 0x1a8bf(%rip)     # 0x21798
movq -0x10(%rbp), %rsi
movl $0x60, %edx
callq 0x3140
movl 0x1a067(%rip), %eax     # 0x20f54
addl $0x1, %eax
movl %eax, 0x1a05e(%rip)     # 0x20f54
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6f08
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)