// File: attractivechaos[P]udb2/stb/./stb.h
// Function: stb_sha1
void stb_sha1(stb_uchar output[20], stb_uchar *buffer, stb_uint len)
{
   unsigned char final_block[128];
   stb_uint end_start, final_len, j;
   int i;

   stb_uint h[5];

   h[0] = 0x67452301;
   h[1] = 0xefcdab89;
   h[2] = 0x98badcfe;
   h[3] = 0x10325476;
   h[4] = 0xc3d2e1f0;

   // we need to write padding to the last one or two
   // blocks, so build those first into 'final_block'

   // we have to write one special byte, plus the 8-byte length

   // compute the block where the data runs out
   end_start = len & ~63;

   // compute the earliest we can encode the length
   if (((len+9) & ~63) == end_start) {
      // it all fits in one block, so fill a second-to-last block
      end_start -= 64;
   }

   final_len = end_start + 128;

   // now we need to copy the data in
   assert(end_start + 128 >= len+9);
   assert(end_start < len || len < 64-9);

   j = 0;
   if (end_start > len)
      j = (stb_uint) - (int) end_start;

   for (; end_start + j < len; ++j)
      final_block[j] = buffer[end_start + j];
   final_block[j++] = 0x80;
   while (j < 128-5) // 5 byte length, so write 4 extra padding bytes
      final_block[j++] = 0;
   // big-endian size
   final_block[j++] = len >> 29;
   final_block[j++] = len >> 21;
   final_block[j++] = len >> 13;
   final_block[j++] = len >>  5;
   final_block[j++] = len <<  3;
   assert(j == 128 && end_start + j == final_len);

   for (j=0; j < final_len; j += 64) { // 512-bit chunks
      if (j+64 >= end_start+64)
         stb__sha1(&final_block[j - end_start], h);
      else
         stb__sha1(&buffer[j], h);
   }

   for (i=0; i < 5; ++i) {
      output[i*4 + 0] = h[i] >> 24;
      output[i*4 + 1] = h[i] >> 16;
      output[i*4 + 2] = h[i] >>  8;
      output[i*4 + 3] = h[i] >>  0;
   }
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movl %edx, 0xb4(%rsp)
movl $0x67452301, (%rsp)     # imm = 0x67452301
movl $0xefcdab89, 0x4(%rsp)  # imm = 0xEFCDAB89
movl $0x98badcfe, 0x8(%rsp)  # imm = 0x98BADCFE
movl $0x10325476, 0xc(%rsp)  # imm = 0x10325476
movl $0xc3d2e1f0, 0x10(%rsp) # imm = 0xC3D2E1F0
movl 0xb4(%rsp), %eax
andl $-0x40, %eax
movl %eax, 0x2c(%rsp)
movl 0xb4(%rsp), %eax
addl $0x9, %eax
andl $-0x40, %eax
cmpl 0x2c(%rsp), %eax
jne 0x10ce1
movl 0x2c(%rsp), %eax
subl $0x40, %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
addl $0x80, %eax
movl %eax, 0x28(%rsp)
movl 0x2c(%rsp), %eax
addl $0x80, %eax
movl 0xb4(%rsp), %ecx
addl $0x9, %ecx
cmpl %ecx, %eax
jb 0x10d07
jmp 0x10d26
leaq 0xeaa1(%rip), %rdi      # 0x1f7af
leaq 0xe674(%rip), %rsi      # 0x1f389
movl $0x18d1, %edx           # imm = 0x18D1
leaq 0xeaa7(%rip), %rcx      # 0x1f7c8
callq 0x2140
movl 0x2c(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jb 0x10d3d
cmpl $0x37, 0xb4(%rsp)
jae 0x10d3f
jmp 0x10d5e
leaq 0xeab4(%rip), %rdi      # 0x1f7fa
leaq 0xe63c(%rip), %rsi      # 0x1f389
movl $0x18d2, %edx           # imm = 0x18D2
leaq 0xea6f(%rip), %rcx      # 0x1f7c8
callq 0x2140
movl $0x0, 0x24(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jbe 0x10d7d
xorl %eax, %eax
subl 0x2c(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x10d7f
movl 0x2c(%rsp), %eax
addl 0x24(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jae 0x10dba
movq 0xb8(%rsp), %rax
movl 0x2c(%rsp), %ecx
addl 0x24(%rsp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movl 0x24(%rsp), %eax
movb %cl, 0x30(%rsp,%rax)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x10d7f
movl 0x24(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x24(%rsp)
movl %eax, %eax
movb $-0x80, 0x30(%rsp,%rax)
cmpl $0x7b, 0x24(%rsp)
jae 0x10deb
movl 0x24(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x24(%rsp)
movl %eax, %eax
movb $0x0, 0x30(%rsp,%rax)
jmp 0x10dce
movl 0xb4(%rsp), %eax
shrl $0x1d, %eax
movb %al, %cl
movl 0x24(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x24(%rsp)
movl %eax, %eax
movb %cl, 0x30(%rsp,%rax)
movl 0xb4(%rsp), %eax
shrl $0x15, %eax
movb %al, %cl
movl 0x24(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x24(%rsp)
movl %eax, %eax
movb %cl, 0x30(%rsp,%rax)
movl 0xb4(%rsp), %eax
shrl $0xd, %eax
movb %al, %cl
movl 0x24(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x24(%rsp)
movl %eax, %eax
movb %cl, 0x30(%rsp,%rax)
movl 0xb4(%rsp), %eax
shrl $0x5, %eax
movb %al, %cl
movl 0x24(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x24(%rsp)
movl %eax, %eax
movb %cl, 0x30(%rsp,%rax)
movl 0xb4(%rsp), %eax
shll $0x3, %eax
movb %al, %cl
movl 0x24(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x24(%rsp)
movl %eax, %eax
movb %cl, 0x30(%rsp,%rax)
cmpl $0x80, 0x24(%rsp)
jne 0x10ea0
movl 0x2c(%rsp), %eax
addl 0x24(%rsp), %eax
cmpl 0x28(%rsp), %eax
jne 0x10ea0
jmp 0x10ebf
leaq 0xe971(%rip), %rdi      # 0x1f818
leaq 0xe4db(%rip), %rsi      # 0x1f389
movl $0x18e3, %edx           # imm = 0x18E3
leaq 0xe90e(%rip), %rcx      # 0x1f7c8
callq 0x2140
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x28(%rsp), %eax
jae 0x10f25
movl 0x24(%rsp), %eax
addl $0x40, %eax
movl 0x2c(%rsp), %ecx
addl $0x40, %ecx
cmpl %ecx, %eax
jb 0x10eff
movl 0x24(%rsp), %eax
subl 0x2c(%rsp), %eax
movl %eax, %eax
leaq 0x30(%rsp), %rdi
addq %rax, %rdi
movq %rsp, %rsi
callq 0x10ff0
jmp 0x10f16
movq 0xb8(%rsp), %rdi
movl 0x24(%rsp), %eax
addq %rax, %rdi
movq %rsp, %rsi
callq 0x10ff0
jmp 0x10f18
movl 0x24(%rsp), %eax
addl $0x40, %eax
movl %eax, 0x24(%rsp)
jmp 0x10ec7
movl $0x0, 0x20(%rsp)
cmpl $0x5, 0x20(%rsp)
jge 0x10fdc
movslq 0x20(%rsp), %rax
movl (%rsp,%rax,4), %eax
shrl $0x18, %eax
movb %al, %dl
movq 0xc0(%rsp), %rax
movl 0x20(%rsp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movslq 0x20(%rsp), %rax
movl (%rsp,%rax,4), %eax
shrl $0x10, %eax
movb %al, %dl
movq 0xc0(%rsp), %rax
movl 0x20(%rsp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movslq 0x20(%rsp), %rax
movl (%rsp,%rax,4), %eax
shrl $0x8, %eax
movb %al, %dl
movq 0xc0(%rsp), %rax
movl 0x20(%rsp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movslq 0x20(%rsp), %rax
movl (%rsp,%rax,4), %eax
shrl $0x0, %eax
movb %al, %dl
movq 0xc0(%rsp), %rax
movl 0x20(%rsp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x10f2d
addq $0xc8, %rsp
retq
nopw %cs:(%rax,%rax)