// File: /workspace/github_c_makefile_star2_O0/hamsternz[P]drummer/drummer.c
// Function: generate_sample
void generate_sample(int16_t o[2]) {
   int32_t samples[N_VOICES];
   int32_t output[2];

   // Start of new tick?
   if(sampleOfTick == 0) {
      for(int i = 0; i < N_VOICES; i++) {
         if(patterns[bars[bar]]->pattern[i][tickOfBar] != ' ') {
            voices[i].pos  = 1;
            voices[i].emph = (patterns[bars[bar]]->pattern[i][tickOfBar]-'1') * 12;
         }
      }
   }

   for(int i = 0; i < N_VOICES; i++) {
      samples[i] = 0;
      if(voices[i].sample >= 0) {
         samples[i] = sounds[voices[i].sample].samples[voices[i].pos ];
         if(voices[i].pos != 0) {
            voices[i].pos++;
            if(voices[i].pos  >= sounds[voices[i].sample].len) {
               voices[i].pos  = 0;
            } 
         }
      }
   }

   output[0] = 0;
   output[1] = 0;
   for(int i = 0; i < N_VOICES; i++) {
      int vol = voices[i].emph + voices[i].volume;
      output[0] += vol * samples[i]*(voices[i].pan);
      output[1] += vol * samples[i]*(32-voices[i].pan);
   }

   sampleOfTick++;
   if(sampleOfTick == samplesPerTick) {
      sampleOfTick = 0;
      tickOfBar++;
      if(tickOfBar == BAR_LEN) {
         tickOfBar = 0;
         bar++;
      }
   }

   // Convert back to 16 bit
   o[0] = output[0] / (32 *4 * 256);
   o[1] = output[1] / (32 *4 * 256);
}

// Assembly:
movq %rdi, -0x8(%rsp)
cmpl $0x0, 0x184d0(%rip)     # 0x1965c
jne 0x125c
movl $0x0, -0x34(%rsp)
cmpl $0x6, -0x34(%rsp)
jge 0x125a
movslq 0x184b4(%rip), %rcx     # 0x19660
leaq 0x183fd(%rip), %rax     # 0x195b0
movslq (%rax,%rcx,4), %rcx
leaq 0x183a2(%rip), %rax     # 0x19560
movq (%rax,%rcx,8), %rax
movslq -0x34(%rsp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movslq 0x1848f(%rip), %rcx     # 0x19664
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
je 0x1248
movslq -0x34(%rsp), %rcx
leaq 0x183f6(%rip), %rax     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0xc(%rax)
movslq 0x18461(%rip), %rcx     # 0x19660
leaq 0x183aa(%rip), %rax     # 0x195b0
movslq (%rax,%rcx,4), %rcx
leaq 0x1834f(%rip), %rax     # 0x19560
movq (%rax,%rcx,8), %rax
movslq -0x34(%rsp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movslq 0x1843c(%rip), %rcx     # 0x19664
movsbl (%rax,%rcx), %eax
subl $0x31, %eax
imull $0xc, %eax, %ecx
movslq -0x34(%rsp), %rdx
leaq 0x183a2(%rip), %rax     # 0x195e0
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
jmp 0x124a
movl -0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rsp)
jmp 0x119a
jmp 0x125c
movl $0x0, -0x38(%rsp)
cmpl $0x6, -0x38(%rsp)
jge 0x138c
movslq -0x38(%rsp), %rax
movl $0x0, -0x28(%rsp,%rax,4)
movslq -0x38(%rsp), %rcx
leaq 0x18358(%rip), %rax     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jl 0x137a
movslq -0x38(%rsp), %rcx
leaq 0x1833b(%rip), %rax     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rcx
leaq 0x17ae9(%rip), %rax     # 0x18da0
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x38(%rsp), %rdx
leaq 0x18313(%rip), %rcx     # 0x195e0
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movslq 0xc(%rcx), %rcx
movswl (%rax,%rcx,2), %ecx
movslq -0x38(%rsp), %rax
movl %ecx, -0x28(%rsp,%rax,4)
movslq -0x38(%rsp), %rcx
leaq 0x182ef(%rip), %rax     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
je 0x1378
movslq -0x38(%rsp), %rcx
leaq 0x182d6(%rip), %rax     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movslq -0x38(%rsp), %rcx
leaq 0x182ba(%rip), %rax     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movslq 0xc(%rax), %rax
movslq -0x38(%rsp), %rdx
leaq 0x182a3(%rip), %rcx     # 0x195e0
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movslq 0x8(%rcx), %rdx
leaq 0x17a51(%rip), %rcx     # 0x18da0
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jb 0x1376
movslq -0x38(%rsp), %rcx
leaq 0x18278(%rip), %rax     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0xc(%rax)
jmp 0x1378
jmp 0x137a
jmp 0x137c
movl -0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rsp)
jmp 0x1264
movl $0x0, -0x30(%rsp)
movl $0x0, -0x2c(%rsp)
movl $0x0, -0x3c(%rsp)
cmpl $0x6, -0x3c(%rsp)
jge 0x144e
movslq -0x3c(%rsp), %rcx
leaq 0x18225(%rip), %rax     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movslq -0x3c(%rsp), %rdx
leaq 0x1820f(%rip), %rcx     # 0x195e0
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
addl 0x4(%rcx), %eax
movl %eax, -0x40(%rsp)
movl -0x40(%rsp), %eax
movslq -0x3c(%rsp), %rcx
imull -0x28(%rsp,%rcx,4), %eax
movslq -0x3c(%rsp), %rdx
leaq 0x181e7(%rip), %rcx     # 0x195e0
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
imull (%rcx), %eax
addl -0x30(%rsp), %eax
movl %eax, -0x30(%rsp)
movl -0x40(%rsp), %eax
movslq -0x3c(%rsp), %rcx
imull -0x28(%rsp,%rcx,4), %eax
movslq -0x3c(%rsp), %rcx
leaq 0x181bb(%rip), %rdx     # 0x195e0
imulq $0x14, %rcx, %rcx
addq %rcx, %rdx
movl $0x20, %ecx
subl (%rdx), %ecx
imull %ecx, %eax
addl -0x2c(%rsp), %eax
movl %eax, -0x2c(%rsp)
movl -0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rsp)
jmp 0x13a4
movl 0x18208(%rip), %eax     # 0x1965c
addl $0x1, %eax
movl %eax, 0x181ff(%rip)     # 0x1965c
movl 0x181f9(%rip), %eax     # 0x1965c
cmpl 0x181ff(%rip), %eax     # 0x19668
jne 0x14a8
movl $0x0, 0x181e7(%rip)     # 0x1965c
movl 0x181e9(%rip), %eax     # 0x19664
addl $0x1, %eax
movl %eax, 0x181e0(%rip)     # 0x19664
cmpl $0x48, 0x181d9(%rip)    # 0x19664
jne 0x14a6
movl $0x0, 0x181cd(%rip)     # 0x19664
movl 0x181c3(%rip), %eax     # 0x19660
addl $0x1, %eax
movl %eax, 0x181ba(%rip)     # 0x19660
jmp 0x14a8
movl -0x30(%rsp), %eax
movl $0x8000, %ecx           # imm = 0x8000
cltd
idivl %ecx
movw %ax, %cx
movq -0x8(%rsp), %rax
movw %cx, (%rax)
movl -0x2c(%rsp), %eax
movl $0x8000, %ecx           # imm = 0x8000
cltd
idivl %ecx
movw %ax, %cx
movq -0x8(%rsp), %rax
movw %cx, 0x2(%rax)
retq
nopl (%rax,%rax)