// File: /workspace/github_cpp_makefile_star2_O1/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 0x32f4
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x2880
cmpl $0x1, %eax
jne 0x4854
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 0x2880
cmpw $0x7b, 0x70(%rsp)
jne 0x486b
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 0x2880
cmpw $0x7d, 0x70(%rsp)
je 0x48e8
movl 0x70(%rsp), %eax
movl $0x79616c70, %ecx       # imm = 0x79616C70
xorl %ecx, %eax
movzbl 0x74(%rsp), %ecx
orl %eax, %ecx
jne 0x46f4
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2880
cmpw $0x3a, 0x70(%rsp)
jne 0x490c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2880
movl $0x1, %r14d
cmpl $0x2, %eax
jne 0x4762
movq %r12, %rdi
callq 0x22c0
movl %eax, %r14d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2880
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 0x6180
movq %r15, %rdi
movq %r13, %rsi
callq 0x6522
movq %rax, %rbp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x47b1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21b0
cmpq 0x50(%rsp), %rbp
je 0x488f
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 0x6180
movq %r15, %rdi
movq %r13, %rsi
callq 0x56c2
movl 0x38(%rax), %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x480b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x58(%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x331c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2880
movzwl 0x70(%rsp), %eax
cmpl $0x2c, %eax
je 0x4736
cmpl $0x3b, %eax
je 0x46f4
movq 0x8(%rbx), %rcx
movl 0x2c(%rbx), %r8d
leaq 0x309d(%rip), %rdi      # 0x78e8
leaq 0x2fd7(%rip), %rsi      # 0x7829
jmp 0x4881
movq 0x8(%rbx), %rsi
movl 0x2c(%rbx), %edx
leaq 0x2f67(%rip), %rdi      # 0x77c9
xorl %eax, %eax
callq 0x2050
jmp 0x48a9
movq 0x8(%rbx), %rcx
movl 0x2c(%rbx), %r8d
leaq 0x306e(%rip), %rdi      # 0x78e8
leaq 0x2e76(%rip), %rsi      # 0x76f7
leaq 0x70(%rsp), %rdx
xorl %eax, %eax
callq 0x2050
jmp 0x48a9
movq 0x8(%rbx), %rdx
movl 0x2c(%rbx), %ecx
leaq 0x2f63(%rip), %rdi      # 0x7800
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x2050
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x58(%rsp), %rdi
callq 0x3304
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x48d4
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 0x573e
xorl %ebx, %ebx
leaq 0x58(%rsp), %rsi
movq %rax, %rdi
callq 0x59d8
jmp 0x48ae
movq 0x8(%rbx), %rcx
movl 0x2c(%rbx), %r8d
leaq 0x2fcd(%rip), %rdi      # 0x78e8
leaq 0x3024(%rip), %rsi      # 0x7946
jmp 0x4881
movq %rax, %rbx
jmp 0x4964
jmp 0x4957
jmp 0x4957
jmp 0x4957
jmp 0x4936
jmp 0x4957
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x495a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x495a
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x3304
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4980
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x2300