// File: /workspace/github_cpp_makefile_star2_O2/mikeakohn[P]drumsplusplus/build/../src/Song.cxx
// Function: Song::parse_section(Tokens*)
int Song::parse_section(Tokens *tokens)
{
  std::string section_name;
  Section section;
  int token_type;
  char token[1024];
  int repeat, i;

  token_type = tokens->get(token);

  if (token_type != TOKEN_ALPHA)
  {
    printf("Error: Section is not alphanumeric on line %s:%d\n",
      tokens->get_filename(), tokens->get_line());
    return -1;
  }

#ifdef DEBUG
printf("parsing section: %s\n", token);
#endif

  section_name = token;

  token_type = tokens->get(token);

  if (strcmp(token, "{") != 0)
  {
    print_error(tokens, "{", token);
    return -1;
  }

  while(1)
  {
    token_type = tokens->get(token);

    if (strcmp(token, "}") == 0)
    {
      break;
    }

    if (strcmp(token, "play") == 0)
    {
      token_type = tokens->get(token);

      if (strcmp(token, ":") != 0)
      {
        print_error(tokens, ":", token);
        return -1;
      }

      while(1)
      {
        repeat = 1;
        token_type = tokens->get(token);

        if (token_type == TOKEN_NUMBER)
        {
          repeat = atoi(token);
          token_type = tokens->get(token);
        }

        if (patterns.find(token) == patterns.end())
        {
          printf("Error: Undefined pattern '%s' at %s:%d.\n",
            token, tokens->get_filename(), tokens->get_line());
          return -1;
        }

        i = patterns[token].get_index();

        section.add_pattern(i, repeat);

        token_type = tokens->get(token);

        if (strcmp(token, ";") == 0)
        {
          break;
        }
          else
        if (strcmp(token, ",") != 0)
        {
          print_error(tokens, ",", token);
          return -1;
        }
      }
    }
  }

  sections[section_name] = section;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x18(%rsp), %rdi
callq 0x3290
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x2828
cmpl $0x1, %eax
jne 0x44ea
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2360
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x2828
cmpw $0x7b, 0x70(%rsp)
jne 0x4501
leaq 0x78(%r14), %r15
movq %r14, 0x8(%rsp)
leaq 0x80(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x70(%rsp), %r12
leaq 0x3428(%rip), %r14      # 0x780b
leaq 0x50(%rsp), %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2828
cmpw $0x7d, 0x70(%rsp)
je 0x455c
movq %r12, %rdi
movq %r14, %rsi
pushq $0x5
popq %rdx
callq 0x21d0
testl %eax, %eax
jne 0x43e8
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2828
cmpw $0x3a, 0x70(%rsp)
jne 0x4580
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2828
pushq $0x1
popq %r14
cmpl $0x2, %eax
jne 0x4452
movq %r12, %rdi
callq 0x22f0
movl %eax, %r14d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2828
movq %r13, %rdi
movq %r12, %rsi
leaq 0x7(%rsp), %rdx
callq 0x507c
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f8a
movq %rax, %rbp
movq %r13, %rdi
callq 0x20f0
cmpq 0x10(%rsp), %rbp
je 0x4517
movq %r13, %rdi
movq %r12, %rsi
leaq 0x7(%rsp), %rdx
callq 0x507c
movq %r15, %rdi
movq %r13, %rsi
callq 0x511e
movl 0x38(%rax), %ebp
movq %r13, %rdi
callq 0x20f0
leaq 0x18(%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x32a2
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2828
movzwl 0x70(%rsp), %eax
cmpl $0x2c, %eax
je 0x4428
cmpl $0x3b, %eax
leaq 0x3330(%rip), %r14      # 0x780b
je 0x43e8
leaq 0x3351(%rip), %rdx      # 0x7839
jmp 0x4508
movq 0x8(%rbx), %rsi
movl 0x2c(%rbx), %edx
leaq 0x32e1(%rip), %rdi      # 0x77d9
xorl %eax, %eax
callq 0x2050
jmp 0x4531
leaq 0x31ff(%rip), %rdx      # 0x7707
leaq 0x70(%rsp), %rcx
movq %rbx, %rsi
callq 0x49e6
jmp 0x4531
movq 0x8(%rbx), %rdx
movl 0x2c(%rbx), %ecx
leaq 0x32eb(%rip), %rdi      # 0x7810
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x2050
pushq $-0x1
popq %rbx
leaq 0x18(%rsp), %rdi
callq 0x329c
leaq 0x30(%rsp), %rdi
callq 0x20f0
movl %ebx, %eax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
addq $0x48, %rdi
leaq 0x30(%rsp), %rsi
callq 0x5184
xorl %ebx, %ebx
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x53be
jmp 0x4534
leaq 0x33cf(%rip), %rdx      # 0x7956
jmp 0x4508
movq %rax, %rbx
jmp 0x45b7
jmp 0x45aa
jmp 0x45aa
jmp 0x45aa
jmp 0x459b
jmp 0x45aa
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x20f0
jmp 0x45ad
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x329c
leaq 0x30(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2330
nop