// File: 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
movq %rsp, %rbp
subq $0x570, %rsp            # imm = 0x570
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x4d8(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2310
leaq -0x50(%rbp), %rdi
callq 0x4620
jmp 0x6f72
movq -0x18(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x2b10
movl %eax, -0x4dc(%rbp)
jmp 0x6f8a
movl -0x4dc(%rbp), %eax
movl %eax, -0x60(%rbp)
cmpl $0x1, -0x60(%rbp)
je 0x7011
movq -0x18(%rbp), %rdi
callq 0x2f40
movq %rax, -0x4e8(%rbp)
jmp 0x6fab
movq -0x18(%rbp), %rdi
callq 0x89f0
movl %eax, -0x4ec(%rbp)
jmp 0x6fbc
movl -0x4ec(%rbp), %edx
movq -0x4e8(%rbp), %rsi
leaq 0x98a3(%rip), %rdi      # 0x10873
xorl %eax, %eax
callq 0x2060
jmp 0x6fd9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x46c(%rbp)
jmp 0x74ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x7513
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x750a
leaq -0x38(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x2300
jmp 0x7023
movq -0x18(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x2b10
movl %eax, -0x4f0(%rbp)
jmp 0x703b
movl -0x4f0(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x460(%rbp), %rdi
leaq 0x974d(%rip), %rsi      # 0x1079f
callq 0x2320
cmpl $0x0, %eax
je 0x7092
movq -0x4d8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0x9731(%rip), %rdx      # 0x1079f
leaq -0x460(%rbp), %rcx
callq 0x7e10
jmp 0x707c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x46c(%rbp)
jmp 0x74ec
jmp 0x7094
jmp 0x7096
movq -0x18(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x2b10
movl %eax, -0x4f4(%rbp)
jmp 0x70ae
movl -0x4f4(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x460(%rbp), %rdi
leaq 0x96dc(%rip), %rsi      # 0x107a1
callq 0x2320
cmpl $0x0, %eax
jne 0x70d4
jmp 0x74ac
leaq -0x460(%rbp), %rdi
leaq 0x97c3(%rip), %rsi      # 0x108a5
callq 0x2320
cmpl $0x0, %eax
jne 0x74a7
movq -0x18(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x2b10
movl %eax, -0x4f8(%rbp)
jmp 0x7108
movl -0x4f8(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x460(%rbp), %rdi
leaq 0x953e(%rip), %rsi      # 0x1065d
callq 0x2320
cmpl $0x0, %eax
je 0x715f
movq -0x4d8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0x9522(%rip), %rdx      # 0x1065d
leaq -0x460(%rbp), %rcx
callq 0x7e10
jmp 0x7149
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x46c(%rbp)
jmp 0x74ec
jmp 0x7161
jmp 0x7163
movl $0x1, -0x464(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x2b10
movl %eax, -0x4fc(%rbp)
jmp 0x7185
movl -0x4fc(%rbp), %eax
movl %eax, -0x60(%rbp)
cmpl $0x2, -0x60(%rbp)
jne 0x71ce
leaq -0x460(%rbp), %rdi
movq %rdi, -0x508(%rbp)
callq 0x2380
movq -0x508(%rbp), %rsi
movl %eax, -0x464(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2b10
movl %eax, -0x500(%rbp)
jmp 0x71c5
movl -0x500(%rbp), %eax
movl %eax, -0x60(%rbp)
movq -0x4d8(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x518(%rbp)
leaq -0x499(%rbp), %rdi
movq %rdi, -0x510(%rbp)
callq 0x23d0
movq -0x510(%rbp), %rdx
leaq -0x498(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x8f10
jmp 0x720f
movq -0x518(%rbp), %rdi
leaq -0x498(%rbp), %rsi
callq 0x90d0
movq %rax, -0x520(%rbp)
jmp 0x722b
movq -0x4d8(%rbp), %rdi
movq -0x520(%rbp), %rax
movq %rax, -0x478(%rbp)
addq $0x78, %rdi
callq 0x9100
movq %rax, -0x4a8(%rbp)
leaq -0x478(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x91d0
movb %al, -0x521(%rbp)
leaq -0x498(%rbp), %rdi
callq 0x2150
leaq -0x499(%rbp), %rdi
callq 0x2260
movb -0x521(%rbp), %al
testb $0x1, %al
jne 0x7290
jmp 0x7332
leaq -0x460(%rbp), %rax
movq %rax, -0x538(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2f40
movq %rax, -0x530(%rbp)
jmp 0x72b0
movq -0x18(%rbp), %rdi
callq 0x89f0
movl %eax, -0x53c(%rbp)
jmp 0x72c1
movl -0x53c(%rbp), %ecx
movq -0x530(%rbp), %rdx
movq -0x538(%rbp), %rsi
leaq 0x95ce(%rip), %rdi      # 0x108aa
xorl %eax, %eax
callq 0x2060
jmp 0x72e5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x46c(%rbp)
jmp 0x74ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x7321
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x498(%rbp), %rdi
callq 0x2150
leaq -0x499(%rbp), %rdi
callq 0x2260
jmp 0x750a
movq -0x4d8(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x550(%rbp)
leaq -0x4c9(%rbp), %rdi
movq %rdi, -0x548(%rbp)
callq 0x23d0
movq -0x548(%rbp), %rdx
leaq -0x4c8(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x8f10
jmp 0x7373
movq -0x550(%rbp), %rdi
leaq -0x4c8(%rbp), %rsi
callq 0x9200
movq %rax, -0x558(%rbp)
jmp 0x738f
movq -0x558(%rbp), %rdi
callq 0x92e0
movl %eax, -0x55c(%rbp)
jmp 0x73a3
movl -0x55c(%rbp), %eax
movl %eax, -0x468(%rbp)
leaq -0x4c8(%rbp), %rdi
callq 0x2150
leaq -0x4c9(%rbp), %rdi
callq 0x2260
movl -0x468(%rbp), %esi
movl -0x464(%rbp), %edx
leaq -0x50(%rbp), %rdi
callq 0x4660
jmp 0x73de
movq -0x18(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x2b10
movl %eax, -0x560(%rbp)
jmp 0x73f6
movl -0x560(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x460(%rbp), %rdi
leaq 0x91bb(%rip), %rsi      # 0x105c8
callq 0x2320
cmpl $0x0, %eax
jne 0x7453
jmp 0x74a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x7442
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x4c8(%rbp), %rdi
callq 0x2150
leaq -0x4c9(%rbp), %rdi
callq 0x2260
jmp 0x750a
leaq -0x460(%rbp), %rdi
leaq 0x9472(%rip), %rsi      # 0x108d3
callq 0x2320
cmpl $0x0, %eax
je 0x749e
movq -0x4d8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0x9456(%rip), %rdx      # 0x108d3
leaq -0x460(%rbp), %rcx
callq 0x7e10
jmp 0x748b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x46c(%rbp)
jmp 0x74ec
jmp 0x74a0
jmp 0x7161
jmp 0x74a7
jmp 0x7094
movq -0x4d8(%rbp), %rdi
addq $0x48, %rdi
leaq -0x38(%rbp), %rsi
callq 0x9300
movq %rax, -0x568(%rbp)
jmp 0x74c9
movq -0x568(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x93e0
jmp 0x74db
movl $0x0, -0x4(%rbp)
movl $0x1, -0x46c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4640
leaq -0x38(%rbp), %rdi
callq 0x2150
movl -0x4(%rbp), %eax
addq $0x570, %rsp            # imm = 0x570
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x4640
leaq -0x38(%rbp), %rdi
callq 0x2150
movq -0x58(%rbp), %rdi
callq 0x23c0
nopw %cs:(%rax,%rax)