// File: /workspace/github_cpp_makefile_star2_O3/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, %r13
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x58(%rsp), %rdi
callq 0x3300
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x2884
cmpl $0x1, %eax
jne 0x48b4
leaq 0x28(%rsp), %r14
movq 0x8(%r14), %r15
leaq 0x70(%rsp), %r12
movq %r12, %rdi
callq 0x20e0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x22b0
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x2884
cmpw $0x7b, 0x70(%rsp)
jne 0x48cb
leaq 0x78(%r13), %r15
movq %r13, 0x48(%rsp)
leaq 0x80(%r13), %rax
movq %rax, 0x50(%rsp)
leaq 0x70(%rsp), %r12
leaq 0x8(%rsp), %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2884
cmpw $0x7d, 0x70(%rsp)
je 0x4948
movl 0x70(%rsp), %eax
movl $0x79616c70, %ecx       # imm = 0x79616C70
xorl %ecx, %eax
movzbl 0x74(%rsp), %ecx
orl %eax, %ecx
jne 0x4754
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2884
cmpw $0x3a, 0x70(%rsp)
jne 0x496c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2884
movl $0x1, %r14d
cmpl $0x2, %eax
jne 0x47c2
movq %r12, %rdi
callq 0x22c0
movl %eax, %r14d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2884
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r12, %rdi
callq 0x20e0
leaq (%rsp,%rax), %rdx
addq $0x70, %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x61de
movq %r15, %rdi
movq %r13, %rsi
callq 0x6586
movq %rax, %rbp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x4811
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21b0
cmpq 0x50(%rsp), %rbp
je 0x48ef
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r12, %rdi
callq 0x20e0
leaq (%rsp,%rax), %rdx
addq $0x70, %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x61de
movq %r15, %rdi
movq %r13, %rsi
callq 0x570e
movl 0x38(%rax), %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x486b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x58(%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x3328
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2884
movzwl 0x70(%rsp), %eax
cmpl $0x2c, %eax
je 0x4796
cmpl $0x3b, %eax
je 0x4754
movq 0x8(%rbx), %rcx
movl 0x2c(%rbx), %r8d
leaq 0x3035(%rip), %rdi      # 0x78e0
leaq 0x2f6f(%rip), %rsi      # 0x7821
jmp 0x48e1
movq 0x8(%rbx), %rsi
movl 0x2c(%rbx), %edx
leaq 0x2eff(%rip), %rdi      # 0x77c1
xorl %eax, %eax
callq 0x2050
jmp 0x4909
movq 0x8(%rbx), %rcx
movl 0x2c(%rbx), %r8d
leaq 0x3006(%rip), %rdi      # 0x78e0
leaq 0x2e0e(%rip), %rsi      # 0x76ef
leaq 0x70(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
jmp 0x4909
movq 0x8(%rbx), %rdx
movl 0x2c(%rbx), %ecx
leaq 0x2efb(%rip), %rdi      # 0x77f8
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x2050
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x58(%rsp), %rdi
callq 0x3310
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4934
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21b0
movl %ebx, %eax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%rsp), %rdi
addq $0x48, %rdi
leaq 0x28(%rsp), %rsi
callq 0x578a
xorl %ebx, %ebx
leaq 0x58(%rsp), %rsi
movq %rax, %rdi
callq 0x5a24
jmp 0x490e
movq 0x8(%rbx), %rcx
movl 0x2c(%rbx), %r8d
leaq 0x2f65(%rip), %rdi      # 0x78e0
leaq 0x2fbc(%rip), %rsi      # 0x793e
jmp 0x48e1
movq %rax, %rbx
jmp 0x49c4
jmp 0x49b7
jmp 0x49b7
jmp 0x49b7
jmp 0x4996
jmp 0x49b7
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x49ba
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x49ba
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x3310
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x49e0
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x2300