LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/./stb_image.h
// Function: stbi__fill_bits(stbi__zbuf*)
static void stbi__fill_bits(stbi__zbuf *z)
{
   do {
      STBI_ASSERT(z->code_buffer < (1U << z->num_bits));
      z->code_buffer |= (unsigned int) stbi__zget8(z) << z->num_bits;
      z->num_bits += 8;
   } while (z->num_bits <= 24);
}

// Assembly:
pushq %rax
movl 0x10(%rdi), %ecx
movl 0x14(%rdi), %eax
movl %eax, %edx
shrl %cl, %edx
testl %edx, %edx
jne 0x15ea3
movq (%rdi), %rsi
xorl %edx, %edx
cmpq 0x8(%rdi), %rsi
jae 0x15e8d
leaq 0x1(%rsi), %rdx
movq %rdx, (%rdi)
movzbl (%rsi), %edx
shll %cl, %edx
orl %edx, %eax
movl %eax, 0x14(%rdi)
leal 0x8(%rcx), %edx
movl %edx, 0x10(%rdi)
cmpl $0x11, %ecx
movl %edx, %ecx
jl 0x15e70
popq %rax
retq
leaq 0x353c(%rip), %rdi      # 0x193e6
leaq 0x2b85(%rip), %rsi      # 0x18a36
leaq 0x3553(%rip), %rcx      # 0x1940b
movl $0xf7b, %edx            # imm = 0xF7B
callq 0x20f0
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/./stb_image.h
// Function: stbi__zexpand(stbi__zbuf*, char*, int)
static int stbi__zexpand(stbi__zbuf *z, char *zout, int n)  // need to make room for n bytes
{
   char *q;
   int cur, limit, old_limit;
   z->zout = zout;
   if (!z->z_expandable) return stbi__err("output buffer limit","Corrupt PNG");
   cur   = (int) (z->zout     - z->zout_start);
   limit = old_limit = (int) (z->zout_end - z->zout_start);
   while (cur + n > limit)
      limit *= 2;
   q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit);
   STBI_NOTUSED(old_limit);
   if (q == NULL) return stbi__err("outofmem", "Out of memory");
   z->zout_start = q;
   z->zout       = q + cur;
   z->zout_end   = q + limit;
   return 1;
}

// Assembly:
movq %rsi, 0x18(%rdi)
cmpl $0x0, 0x30(%rdi)
je 0x15f1b
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq 0x20(%rdi), %rdi
subq %rdi, %r14
movl 0x28(%rbx), %eax
subl %edi, %eax
addl %r14d, %edx
movl %eax, %ecx
leal (%rcx,%rcx), %eax
cmpl %ecx, %edx
jg 0x15ee6
movslq %ecx, %r15
movq %r15, %rsi
callq 0x22d0
testq %rax, %rax
je 0x15f2c
movq %rax, 0x20(%rbx)
movslq %r14d, %rcx
addq %rax, %rcx
movq %rcx, 0x18(%rbx)
addq %rax, %r15
movq %r15, 0x28(%rbx)
movl $0x1, %eax
jmp 0x15f3c
leaq 0x356c(%rip), %rax      # 0x1948e
movq %rax, 0x72cf(%rip)      # 0x1d1f8
xorl %eax, %eax
retq
leaq 0x2c76(%rip), %rax      # 0x18ba9
movq %rax, 0x72be(%rip)      # 0x1d1f8
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/./stb_image.h
// Function: stbi__hdr_test_core(stbi__context*, char const*)
static int stbi__hdr_test_core(stbi__context *s, const char *signature)
{
   int i;
   for (i=0; signature[i]; ++i)
      if (stbi__get8(s) != signature[i])
          return 0;
   stbi__rewind(s);
   return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpb $0x0, (%rsi)
je 0x15fe5
movq %rsi, %r14
leaq 0x38(%rbx), %r15
leaq 0x39(%rbx), %r12
movq 0xb8(%rbx), %rcx
movq 0xc0(%rbx), %rax
incq %r14
cmpq %rax, %rcx
jae 0x15f89
leaq 0x1(%rcx), %rsi
movq %rsi, 0xb8(%rbx)
movb (%rcx), %dl
movq %rsi, %rcx
jmp 0x15fcf
cmpl $0x0, 0x30(%rbx)
je 0x15faa
movq 0x28(%rbx), %rdi
movl 0x34(%rbx), %edx
movq %r15, %rsi
callq *0x10(%rbx)
testl %eax, %eax
je 0x15fae
cltq
addq %r15, %rax
movb (%r15), %dl
jmp 0x15fbe
xorl %edx, %edx
jmp 0x15fcf
movl $0x0, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
xorl %edx, %edx
movq %r12, %rax
movq %rax, 0xc0(%rbx)
movq %r12, 0xb8(%rbx)
movq %r12, %rcx
movzbl %dl, %edx
movsbl -0x1(%r14), %esi
cmpl %esi, %edx
jne 0x15ffa
cmpb $0x0, (%r14)
leaq 0x1(%r14), %r14
jne 0x15f72
movups 0xc8(%rbx), %xmm0
movups %xmm0, 0xb8(%rbx)
movl $0x1, %eax
jmp 0x15ffc
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/./stb_image.h
// Function: stbi__psd_info(stbi__context*, int*, int*, int*)
static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp)
{
   int channelCount, dummy, depth;
   if (!x) x = &dummy;
   if (!y) y = &dummy;
   if (!comp) comp = &dummy;
   if (stbi__get32be(s) != 0x38425053) {
       stbi__rewind( s );
       return 0;
   }
   if (stbi__get16be(s) != 1) {
       stbi__rewind( s );
       return 0;
   }
   stbi__skip(s, 6);
   channelCount = stbi__get16be(s);
   if (channelCount < 0 || channelCount > 16) {
       stbi__rewind( s );
       return 0;
   }
   *y = stbi__get32be(s);
   *x = stbi__get32be(s);
   depth = stbi__get16be(s);
   if (depth != 8 && depth != 16) {
       stbi__rewind( s );
       return 0;
   }
   if (stbi__get16be(s) != 3) {
       stbi__rewind( s );
       return 0;
   }
   *comp = 4;
   return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
callq 0xfc21
movl %eax, %ebp
shll $0x10, %ebp
movq %rbx, %rdi
callq 0xfc21
orl %ebp, %eax
cmpl $0x38425053, %eax       # imm = 0x38425053
jne 0x16111
movq %rbx, %rdi
callq 0xfc21
cmpl $0x1, %eax
jne 0x16111
cmpq $0x0, 0x10(%rbx)
je 0x16081
movq 0xb8(%rbx), %rax
movq 0xc0(%rbx), %rdx
movl %edx, %ecx
subl %eax, %ecx
cmpl $0x5, %ecx
jg 0x16088
movq %rdx, 0xb8(%rbx)
movq 0x28(%rbx), %rdi
movl $0x6, %esi
subl %ecx, %esi
callq *0x18(%rbx)
jmp 0x16093
movq 0xb8(%rbx), %rax
addq $0x6, %rax
movq %rax, 0xb8(%rbx)
movq %rbx, %rdi
callq 0xfc21
cmpl $0x11, %eax
jae 0x16111
movq %rbx, %rdi
callq 0xfc21
movl %eax, %ebp
movq %rbx, %rdi
callq 0xfc21
testq %r12, %r12
je 0x160c0
shll $0x10, %ebp
orl %eax, %ebp
movl %ebp, (%r12)
movq %rbx, %rdi
callq 0xfc21
movl %eax, %ebp
movq %rbx, %rdi
callq 0xfc21
testq %r15, %r15
je 0x160df
shll $0x10, %ebp
orl %eax, %ebp
movl %ebp, (%r15)
movq %rbx, %rdi
callq 0xfc21
cmpl $0x8, %eax
je 0x160f1
cmpl $0x10, %eax
jne 0x16111
movq %rbx, %rdi
callq 0xfc21
cmpl $0x3, %eax
jne 0x16111
movl $0x1, %eax
testq %r14, %r14
je 0x16121
movl $0x4, (%r14)
jmp 0x16121
movups 0xc8(%rbx), %xmm0
movups %xmm0, 0xb8(%rbx)
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/./stb_image.h
// Function: stbi__hdr_info(stbi__context*, int*, int*, int*)
static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp)
{
   char buffer[STBI__HDR_BUFLEN];
   char *token;
   int valid = 0;
   int dummy;

   if (!x) x = &dummy;
   if (!y) y = &dummy;
   if (!comp) comp = &dummy;

   if (stbi__hdr_test(s) == 0) {
       stbi__rewind( s );
       return 0;
   }

   for(;;) {
      token = stbi__hdr_gettoken(s,buffer);
      if (token[0] == 0) break;
      if (strcmp(token, "FORMAT=32-bit_rle_rgbe") == 0) valid = 1;
   }

   if (!valid) {
       stbi__rewind( s );
       return 0;
   }
   token = stbi__hdr_gettoken(s,buffer);
   if (strncmp(token, "-Y ", 3)) {
       stbi__rewind( s );
       return 0;
   }
   token += 3;
   *y = (int) strtol(token, &token, 10);
   while (*token == ' ') ++token;
   if (strncmp(token, "+X ", 3)) {
       stbi__rewind( s );
       return 0;
   }
   token += 3;
   *x = (int) strtol(token, NULL, 10);
   *comp = 3;
   return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
callq 0x319b
testl %eax, %eax
je 0x165eb
movq %r14, 0x8(%rsp)
movq %rbx, %r14
leaq 0x10(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x15595
cmpb $0x0, (%r13)
je 0x165eb
xorl %ebp, %ebp
movl $0x1, %ebx
leaq 0x10(%rsp), %r13
movdqu 0x17(%rsp), %xmm0
pcmpeqb 0x1bb5(%rip), %xmm0     # 0x180d0
movdqa 0x10(%rsp), %xmm1
pcmpeqb 0x1bb7(%rip), %xmm1     # 0x180e0
pand %xmm0, %xmm1
pmovmskb %xmm1, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
cmovel %ebx, %ebp
movq %r15, %rdi
movq %r13, %rsi
callq 0x15595
cmpb $0x0, 0x10(%rsp)
jne 0x1650d
testl %ebp, %ebp
je 0x165eb
leaq 0x10(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x15595
movl $0x592d, %eax           # imm = 0x592D
xorl (%r13), %eax
movzbl 0x2(%r13), %ecx
xorl $0x20, %ecx
orw %ax, %cx
jne 0x165eb
leaq 0x13(%rsp), %rdi
movq %rsp, %rsi
movq %rdi, (%rsi)
movl $0xa, %edx
callq 0x2230
testq %r12, %r12
je 0x16597
movl %eax, (%r12)
movq (%rsp), %rdi
addq $0x2, %rdi
movzbl -0x2(%rdi), %eax
incq %rdi
cmpl $0x20, %eax
je 0x1659f
cmpl $0x2b, %eax
jne 0x165eb
cmpb $0x58, -0x2(%rdi)
jne 0x165eb
cmpb $0x20, -0x1(%rdi)
jne 0x165eb
movq %rdi, (%rsp)
xorl %esi, %esi
movl $0xa, %edx
callq 0x2230
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
je 0x165d8
movl %eax, (%rcx)
movl $0x1, %eax
testq %r14, %r14
je 0x165ff
movl $0x3, (%r14)
jmp 0x165ff
movdqu 0xc8(%r15), %xmm0
movdqu %xmm0, 0xb8(%r15)
xorl %eax, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/./stb_image.h
// Function: stbi__png_info_raw(stbi__png*, int*, int*, int*)
static int stbi__png_info_raw(stbi__png *p, int *x, int *y, int *comp)
{
   if (!stbi__parse_png_file(p, STBI__SCAN_header, 0)) {
      stbi__rewind( p->s );
      return 0;
   }
   if (x) *x = p->s->img_x;
   if (y) *y = p->s->img_y;
   if (comp) *comp = p->s->img_n;
   return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
xorl %ebp, %ebp
movl $0x2, %esi
xorl %edx, %edx
callq 0x10f8c
testl %eax, %eax
je 0x16b66
testq %r12, %r12
je 0x16b44
movq (%r14), %rax
movl (%rax), %eax
movl %eax, (%r12)
testq %r15, %r15
je 0x16b52
movq (%r14), %rax
movl 0x4(%rax), %eax
movl %eax, (%r15)
movl $0x1, %ebp
testq %rbx, %rbx
je 0x16b77
movq (%r14), %rax
movl 0x8(%rax), %eax
movl %eax, (%rbx)
jmp 0x16b77
movq (%r14), %rax
movups 0xc8(%rax), %xmm0
movups %xmm0, 0xb8(%rax)
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/png2tlg.cpp
// Function: TLG6BitStream::PutGamma(int)
void PutGamma(int v)
	{
		// Put a gamma code.
		// v must be larger than 0.
		int t = v;
		t >>= 1;
		int cnt = 0;
		while(t)
		{
			Put1Bit(0);
			t >>= 1;
			cnt ++;
		}
		Put1Bit(1);
		while(cnt--)
		{
			Put1Bit(v&1);
			v >>= 1;
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x2, %esi
jae 0x16ba8
movq %rbx, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x16bf2
movl %esi, %ebp
xorl %r14d, %r14d
movl %esi, %r15d
sarl %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x16bf2
decl %r14d
cmpl $0x1, %r15d
ja 0x16bb0
movq %rbx, %rdi
movl $0x1, %esi
callq 0x16bf2
movl %ebp, %esi
andl $0x1, %esi
movq %rbx, %rdi
callq 0x16bf2
sarl %ebp
incl %r14d
jne 0x16bd3
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/png2tlg.cpp
// Function: TLG6BitStream::Put1Bit(bool)
void Put1Bit(bool b)
	{
		if(BufferBytePos == BufferCapacity)
		{
			// need more bytes
			long org_cap = BufferCapacity;
			BufferCapacity += 0x1000;
			if(Buffer)
				Buffer = (unsigned char *)realloc(Buffer, BufferCapacity);
			else
				Buffer = (unsigned char *)malloc(BufferCapacity);
			if(!Buffer) throw std::runtime_error("TVPTlgInsufficientMemory");
			memset(Buffer + org_cap, 0, BufferCapacity - org_cap);
		}

		if(b) Buffer[BufferBytePos] |= 1 << BufferBitPos;
		BufferBitPos ++;
		if(BufferBitPos == 8)
		{
			BufferBitPos = 0;
			BufferBytePos ++;
		}
	}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
movq 0x8(%rdi), %r14
cmpq 0x20(%rdi), %r14
jne 0x16c45
leaq 0x1000(%r14), %rsi
movq %rsi, 0x20(%rbx)
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x16c20
callq 0x22d0
jmp 0x16c28
movq %rsi, %rdi
callq 0x2200
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x16c78
addq %r14, %rax
movq 0x20(%rbx), %rdx
subq %r14, %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x20e0
testb %bpl, %bpl
je 0x16c5e
movb (%rbx), %cl
movl $0x1, %eax
shll %cl, %eax
movq 0x18(%rbx), %rcx
movq 0x8(%rbx), %rdx
orb %al, (%rcx,%rdx)
movl (%rbx), %eax
incl %eax
movl %eax, (%rbx)
cmpl $0x8, %eax
jne 0x16c73
movl $0x0, (%rbx)
incq 0x8(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
movl $0x10, %edi
callq 0x20d0
movq %rax, %rbx
leaq 0x28a0(%rip), %rsi      # 0x1952c
movq %rax, %rdi
callq 0x20a0
movq 0x6355(%rip), %rsi      # 0x1cff0
movq 0x6326(%rip), %rdx      # 0x1cfc8
movq %rbx, %rdi
callq 0x22f0
movq %rax, %r14
movq %rbx, %rdi
callq 0x2130
movq %r14, %rdi
callq 0x2300
nop
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/png2tlg.cpp
// Function: TryCompressGolomb::Try(char*, int)
int Try(char *buf, int size)
	{
		for(int i = 0; i < size; i++)
		{
			if(buf[i])
			{
				// write zero count
				if(!LastNonZero)
				{
					if(Count)
						TotalBits +=
							TLG6BitStream::GetGammaBitLength(Count);

					// count non-zero values
					Count = 0;
				}

				// write non-zero values
				for(; i < size; i++)
				{
					int e = buf[i];
					if(!e) break;
					Count ++;
					int k = TVPTLG6GolombBitLengthTable[A][N];
					int m = ((e >= 0) ? 2*e : -2*e-1) - 1;
					int unexp_bits = (m>>k);
					if(unexp_bits >= (GOLOMB_GIVE_UP_BYTES*8-8/2))
						unexp_bits = (GOLOMB_GIVE_UP_BYTES*8-8/2)+8;
					TotalBits += unexp_bits + 1 + k;
					A += (m>>1);
					if (--N < 0) {
						A >>= 1; N = TVP_TLG6_GOLOMB_N_COUNT - 1;
					}
				}

				// write non-zero count

				i--;
				LastNonZero = true;
			}
			else
			{
				// zero
				if(LastNonZero)
				{
					if(Count)
					{
						TotalBits += TLG6BitStream::GetGammaBitLength(Count);
						Count = 0;
					}
				}

				Count ++;
				LastNonZero = false;
			}
		}
		return TotalBits;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
testl %edx, %edx
jle 0x16e0a
movq %rsi, %r15
movl %edx, %r12d
xorl %r13d, %r13d
movl $0x25, %ebp
movl %edx, 0x4(%rsp)
movslq %r13d, %rbx
cmpb $0x0, (%r15,%rbx)
movb 0x10(%r14), %al
je 0x16dcb
testb %al, %al
jne 0x16d18
movl 0x4(%r14), %edi
testl %edi, %edi
je 0x16d10
callq 0x16f98
movl 0x4(%rsp), %edx
addl %eax, (%r14)
movl $0x0, 0x4(%r14)
cmpl %edx, %r13d
jge 0x16dfc
movl (%r14), %eax
movl 0x4(%r14), %r11d
movl 0xc(%r14), %esi
movl 0x8(%r14), %ecx
incl %r11d
leaq 0x64d6(%rip), %r13      # 0x1d210
movsbl (%r15,%rbx), %r8d
testl %r8d, %r8d
je 0x16df9
movl %r11d, 0x4(%r14)
movslq %esi, %rsi
movslq %ecx, %rdi
leaq (,%rsi,4), %rcx
addq %r13, %rcx
movsbl (%rdi,%rcx), %ecx
movl %r8d, %r9d
addl %r8d, %r9d
sarb $0x7, %r8b
movsbl %r8b, %r8d
xorl %r9d, %r8d
decl %r8d
movl %r8d, %r9d
sarl %cl, %r9d
leal 0x1(%r9), %r10d
cmpl $0x1c, %r9d
cmovgel %ebp, %r10d
addl %ecx, %eax
addl %r10d, %eax
movl %eax, (%r14)
sarl %r8d
addl %r8d, %esi
movl %esi, 0xc(%r14)
leal -0x1(%rdi), %ecx
movl %ecx, 0x8(%r14)
testl %edi, %edi
jg 0x16db7
sarl %esi
movl %esi, 0xc(%r14)
movl $0x3, 0x8(%r14)
movl $0x3, %ecx
incq %rbx
incl %r11d
cmpq %rbx, %r12
jne 0x16d3a
movl %r12d, %r13d
jmp 0x16dfc
movl 0x4(%r14), %edi
testb %al, %al
je 0x16de7
xorl %ebx, %ebx
testl %edi, %edi
je 0x16de9
callq 0x16f98
movl 0x4(%rsp), %edx
addl %eax, (%r14)
jmp 0x16de9
movl %edi, %ebx
incl %ebx
movl %ebx, 0x4(%r14)
movb $0x0, 0x10(%r14)
incl %r13d
jmp 0x16e01
movl %ebx, %r13d
movb $0x1, 0x10(%r14)
cmpl %edx, %r13d
jl 0x16ce6
movl (%r14), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/png2tlg.cpp
// Function: TLG6BitStream::Flush()
void Flush()
	{
		if(Buffer && (BufferBitPos || BufferBytePos))
		{
			if(BufferBitPos) BufferBytePos ++;
			OutStream->write((const char *)Buffer, BufferBytePos);
			BufferBytePos = 0;
			BufferBitPos = 0;
		}
		free(Buffer);
		BufferCapacity = 0;
		Buffer = NULL;
	}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
leaq 0x18(%rdi), %r14
movq 0x18(%rdi), %rsi
testq %rsi, %rsi
je 0x16e6f
movq %rdi, %rbx
movl (%rdi), %eax
testl %eax, %eax
sete %cl
movq 0x8(%rdi), %rdx
testq %rdx, %rdx
sete %dil
testb %dil, %cl
jne 0x16e71
testl %eax, %eax
je 0x16e52
incq %rdx
movq %rdx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x21f0
movq $0x0, 0x8(%rbx)
movl $0x0, (%rbx)
movq 0x18(%rbx), %rsi
jmp 0x16e71
xorl %esi, %esi
movq %rsi, %rdi
callq 0x21d0
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/zhiyb[P]png2tlg/png2tlg.cpp
// Function: TLG6BitStream::GetGammaBitLength(int)
static int GetGammaBitLength(int v)
	{
		// Get bit length where v is to be encoded as a gamma code.
		if(v<=1) return 1;    //                   1
		if(v<=3) return 3;    //                 x10
		if(v<=7) return 5;    //               xx100
		if(v<=15) return 7;   //             xxx1000
		if(v<=31) return 9;   //          x xxx10000
		if(v<=63) return 11;  //        xxx xx100000
		if(v<=127) return 13; //      xxxxx x1000000
		if(v<=255) return 15; //    xxxxxxx 10000000
		if(v<=511) return 17; //   xxxxxxx1 00000000
		return GetGammaBitLengthGeneric(v);
	}

// Assembly:
movl $0x1, %eax
cmpl $0x2, %edi
jl 0x1700e
movl $0x3, %eax
cmpl $0x4, %edi
jb 0x1700e
movl $0x5, %eax
cmpl $0x8, %edi
jb 0x1700e
movl $0x7, %eax
cmpl $0x10, %edi
jb 0x1700e
movl $0x9, %eax
cmpl $0x20, %edi
jb 0x1700e
movl $0xb, %eax
cmpl $0x40, %edi
jb 0x1700e
movl $0xd, %eax
cmpl $0x80, %edi
jb 0x1700e
movl $0xf, %eax
cmpl $0x100, %edi            # imm = 0x100
jb 0x1700e
movl $0x11, %eax
cmpl $0x200, %edi            # imm = 0x200
jb 0x1700e
movl $0x1, %eax
movl %edi, %ecx
shrl %ecx
addl $0x2, %eax
cmpl $0x3, %edi
movl %ecx, %edi
ja 0x17002
retq
// File: /workspace/github_c_makefile_star2_O3/pyk[P]simple-nn/deps/pcg/test-low/../extras/entropy.c
// Function: entropy_getbytes
bool entropy_getbytes(void* dest, size_t size)
{
    int fd = open("/dev/random", O_RDONLY);
    if (fd >= 0)
        return false;
    uint64_t seeding[2];
    int sz = read(fd, dest, size);
    if (sz < size)
        return false;
    return close(fd) == 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r15
leaq 0xb92(%rip), %rdi       # 0x2176
xorl %r14d, %r14d
xorl %esi, %esi
xorl %eax, %eax
callq 0x1080
testl %eax, %eax
jns 0x161c
movl %eax, %ebp
movl %eax, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1060
cltq
cmpq %rbx, %rax
jae 0x160f
xorl %r14d, %r14d
jmp 0x161c
movl %ebp, %edi
callq 0x1050
testl %eax, %eax
sete %r14b
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/pyk[P]simple-nn/deps/pcg/test-low/../extras/entropy.c
// Function: fallback_entropy_getbytes
void fallback_entropy_getbytes(void* dest, size_t size)
{
    // Most modern OSs use address-space randomization, meaning that we can
    // use the address of stack variables and system library code as
    // initializers.  It's not as good as using /dev/random, but probably
    // better than using the current time alone.

    static PCG_SPINLOCK_DECLARE(mutex);
    PCG_SPINLOCK_LOCK(mutex);

    static int intitialized = 0;
    static pcg32_random_t entropy_rng;
    
    if (!intitialized) {
        int dummyvar;
        pcg32_srandom_r(&entropy_rng,
                        time(NULL) ^ (intptr_t)&fallback_entropy_getbytes, 
                        (intptr_t)&dummyvar);
        intitialized = 1;
    }
    
    char* dest_cp = (char*) dest;
    for (size_t i = 0; i < size; ++i) {
        dest_cp[i] = (char) pcg32_random_r(&entropy_rng);
    }

    PCG_SPINLOCK_UNLOCK(mutex);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movb $0x1, %al
xchgb %al, 0x2a27(%rip)       # 0x4068
testb $0x1, %al
jne 0x1639
movabsq $0x5851f42d4c957f2d, %r15 # imm = 0x5851F42D4C957F2D
cmpb $0x0, 0x2a16(%rip)      # 0x406c
jne 0x169d
xorl %edi, %edi
callq 0x1070
leaq -0x3c(%rip), %rcx       # 0x162a
xorq %rax, %rcx
leaq 0xc(%rsp), %rax
leaq 0x1(,%rax,2), %rdx
movq %rdx, 0x29fb(%rip)      # 0x4078
leaq (%rcx,%rax,2), %rcx
incq %rcx
imulq %r15, %rcx
leaq (%rcx,%rax,2), %rax
incq %rax
movq %rax, 0x29da(%rip)      # 0x4070
movb $0x1, 0x29cf(%rip)      # 0x406c
testq %rbx, %rbx
je 0x16e6
movq 0x29cf(%rip), %rdx      # 0x4078
movq 0x29c0(%rip), %rax      # 0x4070
xorl %esi, %esi
movq %rax, %rcx
imulq %r15, %rax
movq %rcx, %rdi
shrq $0x2d, %rdi
movq %rcx, %r8
shrq $0x1b, %r8
xorl %r8d, %edi
shrq $0x3b, %rcx
rorl %cl, %edi
addq %rdx, %rax
movb %dil, (%r14,%rsi)
incq %rsi
cmpq %rsi, %rbx
jne 0x16b2
movq %rax, 0x298a(%rip)      # 0x4070
xorl %eax, %eax
xchgb %al, 0x297a(%rip)       # 0x4068
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/pyk[P]simple-nn/deps/pcg/src/pcg-advance-32.c
// Function: pcg_advance_lcg_32
uint32_t pcg_advance_lcg_32(uint32_t state, uint32_t delta, uint32_t cur_mult,
                            uint32_t cur_plus)
{
    uint32_t acc_mult = 1u;
    uint32_t acc_plus = 0u;
    while (delta > 0) {
        if (delta & 1) {
            acc_mult *= cur_mult;
            acc_plus = acc_plus * cur_mult + cur_plus;
        }
        cur_plus = (cur_mult + 1) * cur_plus;
        cur_mult *= cur_mult;
        delta /= 2;
    }
    return acc_mult * state + acc_plus;
}

// Assembly:
testl %esi, %esi
je 0x1742
pushq %rbx
movl $0x1, %r9d
xorl %r8d, %r8d
movl $0x1, %eax
movl %esi, %r10d
movl %r8d, %r11d
imull %edx, %r11d
addl %ecx, %r11d
testb $0x1, %sil
movl %edx, %ebx
cmovel %r9d, %ebx
cmovnel %r11d, %r8d
imull %ebx, %eax
leal 0x1(%rdx), %r11d
imull %r11d, %ecx
imull %edx, %edx
shrl %r10d
cmpl $0x1, %esi
movl %r10d, %esi
ja 0x170e
popq %rbx
jmp 0x174a
xorl %r8d, %r8d
movl $0x1, %eax
imull %edi, %eax
addl %r8d, %eax
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_alloc
static struct multiboot * butterfly_alloc(void)
{
    struct multiboot * mboot = malloc(sizeof(struct multiboot));
    if (mboot == NULL)
    {
        return NULL;
    }

    memset(mboot, 0x00, sizeof(struct multiboot));
    mboot->ops= &butterfly_ops;

    bfly_privdata_t * p_priv = malloc(sizeof(bfly_privdata_t));
    if (p_priv == NULL)
    {
        free(mboot);
        return NULL;
    }

    memset(p_priv, 0x00, sizeof(bfly_privdata_t));

    optarg_register(bfly_optargs, ARRAY_SIZE(bfly_optargs),
                    bfly_optarg_cb, (void *)p_priv);

    mboot->privdata = p_priv;
    return mboot;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl $0x1, %edi
movl $0x20, %esi
callq 0x2160
testq %rax, %rax
je 0x2fd1
movq %rax, %rbx
leaq 0xa1f2(%rip), %rax      # 0xd180
movq %rax, (%rbx)
movl $0x1, %edi
movl $0x58, %esi
callq 0x2160
testq %rax, %rax
je 0x2fc9
movq %rax, %r14
leaq 0xa221(%rip), %rdi      # 0xd1d0
leaq 0x81b(%rip), %rdx       # 0x37d1
movl $0x4, %esi
movq %rax, %rcx
callq 0x72f0
movq %r14, 0x8(%rbx)
jmp 0x2fd3
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_free
static void butterfly_free(struct multiboot * p_mboot)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;

    if (p_priv->p_device != NULL)
    {
        free(p_priv->p_device);
    }

    free(p_priv);
    free(p_mboot);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2ff6
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2030
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_close
static int butterfly_close(struct multiboot * p_mboot)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;

    if (p_priv->progmode_active)
    {
        butterfly_leave_progmode(p_priv);
    }

    butterfly_close_device(p_priv);

    return 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq 0x8(%rdi), %rbx
cmpb $0x0, 0x52(%rbx)
je 0x33f3
cmpb $0x0, 0x4a(%rbx)
movl 0x44(%rbx), %edi
leaq 0x5096(%rip), %rax      # 0x8462
leaq 0x508d(%rip), %rsi      # 0x8460
cmoveq %rax, %rsi
movl $0x1, %edx
callq 0x2090
movl 0x44(%rbx), %edi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x38d2
movl 0x44(%rbx), %edi
leaq 0x8(%rbx), %rdx
xorl %esi, %esi
callq 0x2200
movl 0x44(%rbx), %edi
callq 0x2140
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_read
static int butterfly_read(struct multiboot * p_mboot,
                          struct databuf * p_dbuf,
                          int memtype)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;
    char * p_progress_msg = (memtype == 'F') ? "reading flash" : "reading eeprom";

    uint16_t pos = 0;
    uint16_t size = (memtype == 'F') ? p_priv->flashsize :
                                       p_priv->eepromsize;

    if (butterfly_set_address(p_priv, pos) < 0)
    {
        fprintf(stderr, "failed to set address\n");
        return -1;
    }

    while (pos < size)
    {
        p_mboot->progress_cb(p_progress_msg, pos, size);

        uint16_t len = MIN(p_priv->buffersize, size - pos);
        if (butterfly_read_data(p_priv, p_dbuf->data + pos, len, memtype))
        {
            p_mboot->progress_cb(p_progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    p_dbuf->length = pos;

    p_mboot->progress_cb(p_progress_msg, pos, size);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r14d
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi), %r12
xorl %eax, %eax
cmpl $0x46, %edx
setne %al
leaq 0x5025(%rip), %rcx      # 0x8464
leaq 0x502c(%rip), %rdx      # 0x8472
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsp)
movzwl 0x4e(%r12,%rax,2), %ebx
movq %r12, %rdi
callq 0x39e8
testl %eax, %eax
js 0x351e
movl $0x0, %ebp
testl %ebx, %ebx
je 0x34d4
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
movzbl %r14b, %r14d
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
movq 0x10(%rsp), %rax
callq *0x18(%rax)
movzwl 0x4c(%r12), %eax
movl %ebx, %r13d
subl %ebp, %r13d
cmpl %eax, %r13d
cmovgl %eax, %r13d
movzwl %r15w, %esi
addq 0x20(%rsp), %rsi
movzwl %r13w, %edx
movq %r12, %rdi
movl %r14d, %ecx
callq 0x3a6b
testl %eax, %eax
jne 0x34f1
addl %r15d, %r13d
movzwl %r13w, %ebp
movl %r13d, %r15d
cmpw %bx, %bp
jb 0x3485
movq 0x18(%rsp), %rax
movl %ebp, 0x4(%rax)
movq 0x8(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
movq 0x10(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x350d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rax
callq *0x18(%rax)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2401
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x350d
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_verify
static int butterfly_verify(struct multiboot * p_mboot,
                            struct databuf * p_dbuf,
                            int memtype)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;
    char * p_progress_msg = (memtype == 'F') ? "verifing flash" : "verifing eeprom";

    uint16_t pos = 0;
    uint8_t comp[256];

    if (butterfly_set_address(p_priv, pos) < 0)
    {
        fprintf(stderr, "failed to set address\n");
        return -1;
    }

    while (pos < p_dbuf->length)
    {
        p_mboot->progress_cb(p_progress_msg, pos, p_dbuf->length);

        uint16_t len = MIN(p_priv->buffersize, p_dbuf->length - pos);
        if (butterfly_read_data(p_priv, comp, len, memtype))
        {
            p_mboot->progress_cb(p_progress_msg, -1, -1);
            return -1;
        }

        if (memcmp(comp, p_dbuf->data + pos, len) != 0x00)
        {
            p_mboot->progress_cb(p_progress_msg, -1, -1);
            fprintf(stderr, "verify failed at pos 0x%04x!!\n", pos);
            return -1;
        }

        pos += len;
    }

    p_dbuf->length = pos;

    p_mboot->progress_cb(p_progress_msg, pos, p_dbuf->length);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movq 0x8(%rdi), %rdi
cmpl $0x46, %edx
leaq 0x4f47(%rip), %rax      # 0x849a
leaq 0x4f4f(%rip), %rcx      # 0x84a9
cmoveq %rax, %rcx
movq %rcx, (%rsp)
movq %rdi, 0x28(%rsp)
callq 0x39e8
testl %eax, %eax
js 0x364b
movl 0x4(%r12), %edx
movl $0x0, %ebx
testl %edx, %edx
je 0x3616
movq 0x18(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%r12), %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movzbl %bpl, %eax
movl %eax, 0x14(%rsp)
xorl %r14d, %r14d
movq (%rsp), %rdi
movl %ebx, %esi
movq 0x8(%rsp), %rax
callq *(%rax)
movq 0x28(%rsp), %rdi
movzwl 0x4c(%rdi), %eax
movl 0x4(%r12), %r15d
subl %ebx, %r15d
cmpl %eax, %r15d
cmoval %eax, %r15d
movzwl %r15w, %ebp
leaq 0x30(%rsp), %r13
movq %r13, %rsi
movl %ebp, %edx
movl 0x14(%rsp), %ecx
callq 0x3a6b
testl %eax, %eax
jne 0x362f
movzwl %r14w, %esi
addq 0x20(%rsp), %rsi
movq %r13, %rdi
movq %rbp, %rdx
callq 0x21e0
testl %eax, %eax
jne 0x3652
addl %r14d, %r15d
movzwl %r15w, %ebx
movl 0x4(%r12), %edx
movl %r15d, %r14d
cmpl %ebx, %edx
ja 0x35ab
movl %ebx, 0x4(%r12)
movq (%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
movq 0x18(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x3667
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq (%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rax
callq *(%rax)
jmp 0x3667
callq 0x2448
jmp 0x3662
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movl %ebx, %edx
callq 0x241d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_write
static int butterfly_write(struct multiboot * p_mboot,
                           struct databuf * p_dbuf,
                           int memtype)
{
    bfly_privdata_t * p_priv = (bfly_privdata_t *)p_mboot->privdata;
    char * p_progress_msg = (memtype == 'F') ? "writing flash" : "writing eeprom";

    uint16_t pos = 0;

    if (butterfly_set_address(p_priv, pos) < 0)
    {
        fprintf(stderr, "failed to set address\n");
        return -1;
    }

    while (pos < p_dbuf->length)
    {
        p_mboot->progress_cb(p_progress_msg, pos, p_dbuf->length);

        uint16_t len = (memtype == 'F') ? p_priv->buffersize : WRITE_SIZE_EEPROM;

        len = MIN(len, p_dbuf->length - pos);

        if (butterfly_write_data(p_priv, p_dbuf->data + pos, len, memtype))
        {
            p_mboot->progress_cb(p_progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    p_mboot->progress_cb(p_progress_msg, pos, p_dbuf->length);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r15d
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movq 0x8(%rdi), %r13
cmpl $0x46, %edx
leaq 0x4e36(%rip), %rax      # 0x84d8
leaq 0x4e3d(%rip), %rcx      # 0x84e6
cmoveq %rax, %rcx
movq %rcx, 0x10(%rsp)
movq %r13, %rdi
callq 0x39e8
testl %eax, %eax
js 0x37c5
movl 0x4(%r12), %eax
movl $0x0, %ebp
movl $0x0, %edx
testl %eax, %eax
je 0x3785
leaq 0x8(%r12), %rcx
movq %rcx, 0x20(%rsp)
xorl %ebp, %ebp
movl %eax, %edx
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
movl %ebp, %esi
movq 0x18(%rsp), %rax
callq *0x18(%rax)
movl $0x10, %eax
cmpl $0x46, %r15d
jne 0x3709
movzwl 0x4c(%r13), %eax
movl 0x4(%r12), %ebx
subl %ebp, %ebx
cmpl %ebx, %eax
cmovbl %eax, %ebx
movzwl %r14w, %ebp
addq 0x20(%rsp), %rbp
movb $0x42, 0xc(%rsp)
movb %bh, 0xd(%rsp)
movb %bl, 0xe(%rsp)
movb %r15b, 0xf(%rsp)
movl 0x44(%r13), %edi
movl $0x4, %edx
leaq 0xc(%rsp), %rsi
callq 0x2090
movl 0x44(%r13), %edi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2090
movl 0x44(%r13), %edi
leaq 0xb(%rsp), %rsi
movl $0x1, %edx
callq 0x38d2
cmpl $0x1, %eax
jne 0x3798
cmpb $0xd, 0xb(%rsp)
jne 0x3798
addl %ebx, %r14d
movzwl %r14w, %ebp
movl 0x4(%r12), %edx
cmpl %ebp, %edx
ja 0x36ea
movq 0x10(%rsp), %rdi
movl %ebp, %esi
movq 0x18(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x37b4
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rax
callq *0x18(%rax)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2464
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x37b4
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_serial_read
static int butterfly_serial_read(int fd, void * data, int size,
                                 unsigned int timeout_ms)
{
    int pos = 0;

    while (1)
    {
        fd_set fdset;
        struct timeval timeout;
        struct timeval * p_timeout = NULL;

        FD_ZERO(&fdset);
        FD_SET(fd, &fdset);

        if (timeout_ms != 0)
        {
            p_timeout = &timeout;

            timeout.tv_sec = timeout_ms / 1000;
            timeout.tv_usec = (timeout_ms % 1000) * 1000;
        }

        int ret = select(fd +1, &fdset, NULL, NULL, p_timeout);
        if (ret == -1)
        {
            perror("select");
            return -1;
        }
        else if (ret == 0)
        {
            break;
        }
        else if (FD_ISSET(fd, &fdset))
        {
            int len = read(fd, data + pos, size - pos);
            if (len < 0)
            {
                return -1;
            }
            else
            {
                pos += len;
                if (pos == size)
                {
                    break;
                }
            }
        }
    }

    return pos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %ebx
movl %edi, %r14d
leal 0x3f(%r14), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %edi, %ecx
subl %edx, %ecx
movl $0x1, %r13d
shlq %cl, %r13
movq %rsi, 0x8(%rsp)
sarl $0x6, %eax
movslq %eax, %r12
leal 0x1(%r14), %ebp
xorl %r15d, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
orq %r13, 0x20(%rsp,%r12,8)
movq $0x1, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movl %ebp, %edi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
callq 0x21c0
testl %eax, %eax
je 0x39c5
cmpl $-0x1, %eax
je 0x39da
testq %r13, 0x20(%rsp,%r12,8)
je 0x39b0
movl %r15d, %esi
addq 0x8(%rsp), %rsi
movl %ebx, %eax
subl %r15d, %eax
movslq %eax, %rdx
movl %r14d, %edi
callq 0x2150
addl %eax, %r15d
xorl %ecx, %ecx
cmpl %ebx, %r15d
sete %dl
testl %eax, %eax
js 0x39bf
movb %dl, %cl
leal (%rcx,%rcx,2), %eax
jmp 0x39b2
xorl %eax, %eax
testl %eax, %eax
je 0x3915
cmpl $0x3, %eax
je 0x39c5
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4a76(%rip), %rdi      # 0x8457
callq 0x2240
jmp 0x39bf
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_set_address
static int butterfly_set_address(bfly_privdata_t * p_priv, uint16_t pos)
{
    uint8_t buffer[1];
    int result;

    (void)write(p_priv->fd, "a", 1);

    result = butterfly_serial_read(p_priv->fd, buffer, sizeof(buffer),
                                   SERIAL_TIMEOUT);
    if ((result == 1) &&
        (buffer[0] == 'Y')
       )
    {
        /* convert to word address */
        pos >>= 1;

        uint8_t cmd[3] = { 'A', pos >> 8, pos & 0xFF };
        (void)write(p_priv->fd, cmd, sizeof(cmd));

        result = butterfly_expect_cr(p_priv);
    }

    return result;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl 0x44(%rdi), %edi
leaq 0x4a9e(%rip), %rsi      # 0x8498
movl $0x1, %edx
callq 0x2090
movl 0x44(%rbx), %edi
leaq 0xb(%rsp), %rsi
movl $0x1, %edx
callq 0x38d2
cmpl $0x1, %eax
jne 0x3a65
cmpb $0x59, 0xb(%rsp)
jne 0x3a65
leaq 0xd(%rsp), %rsi
movw $0x41, (%rsi)
movb $0x0, 0x2(%rsi)
movl 0x44(%rbx), %edi
movl $0x3, %edx
callq 0x2090
movl 0x44(%rbx), %edi
leaq 0xc(%rsp), %rbx
movq %rbx, %rsi
movl $0x1, %edx
callq 0x38d2
cmpl $0x1, %eax
setne %al
cmpb $0xd, (%rbx)
setne %cl
orb %al, %cl
movzbl %cl, %eax
negl %eax
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/butterfly_prog.c
// Function: butterfly_read_data
static int butterfly_read_data(bfly_privdata_t * p_priv,
                               uint8_t * p_data, uint16_t size,
                               uint8_t memtype)
{
    int result;

    uint8_t cmd[4] = { 'g', size >> 8, size & 0xFF, memtype };
    (void)write(p_priv->fd, cmd, 4);

    result = butterfly_serial_read(p_priv->fd, p_data, size,
                                   SERIAL_TIMEOUT);
    return (result != size);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
leaq 0xc(%rsp), %rsi
movb $0x67, (%rsi)
movb %bh, 0xd(%rsp)
movb %bl, 0x2(%rsi)
movb %cl, 0x3(%rsi)
movl 0x44(%rdi), %edi
movl $0x4, %edx
callq 0x2090
movl 0x44(%r15), %edi
movq %r14, %rsi
movl %ebx, %edx
callq 0x38d2
xorl %ecx, %ecx
cmpl %ebx, %eax
setne %cl
movl %ecx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/chipinfo_avr.c
// Function: chipinfo_get_by_signature
const avr_chipinfo_t * chipinfo_get_by_signature(const uint8_t *sig)
{
    unsigned int i;

    for (i = 0; i < ARRAY_SIZE(chips); i++)
    {
        avr_chipinfo_t *chip = &chips[i];

        if ((chip->sig[0] == sig[0]) &&
            (chip->sig[1] == sig[1]) &&
            (chip->sig[2] == sig[2])
           )
        {
            return chip;
        }
    }

    return NULL;
}

// Assembly:
movb (%rdi), %dl
xorl %eax, %eax
leaq 0x9789(%rip), %rcx      # 0xd250
xorl %esi, %esi
cmpb %dl, (%rsi,%rcx)
jne 0x3ae4
movb 0x1(%rsi,%rcx), %r8b
cmpb 0x1(%rdi), %r8b
jne 0x3ae4
movb 0x2(%rsi,%rcx), %r8b
cmpb 0x2(%rdi), %r8b
je 0x3af2
addq $0x18, %rsi
cmpq $0xa8, %rsi
jne 0x3ac9
retq
addq %rsi, %rcx
movq %rcx, %rax
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_alloc
static struct multiboot * eprog_alloc(void)
{
    struct multiboot * mboot = malloc(sizeof(struct multiboot));
    if (mboot == NULL)
    {
        return NULL;
    }

    memset(mboot, 0x00, sizeof(struct multiboot));
    mboot->ops= &eprog_ops;

    struct eprog_privdata *p_prog = malloc(sizeof(struct eprog_privdata));
    if (p_prog == NULL)
    {
        free(mboot);
        return NULL;
    }

    memset(p_prog, 0x00, sizeof(struct eprog_privdata));
    p_prog->device = NULL;

    optarg_register(eprog_optargs, ARRAY_SIZE(eprog_optargs),
                    eprog_optarg_cb, (void *)p_prog);

    mboot->privdata = p_prog;
    return mboot;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl $0x1, %edi
movl $0x20, %esi
callq 0x2160
testq %rax, %rax
je 0x3bb1
movq %rax, %rbx
leaq 0x9792(%rip), %rax      # 0xd300
movq %rax, (%rbx)
movl $0x1, %edi
movl $0x78, %esi
callq 0x2160
testq %rax, %rax
je 0x3ba9
movq %rax, %r14
leaq 0x97c1(%rip), %rdi      # 0xd350
leaq 0x68f(%rip), %rdx       # 0x4225
movl $0x3, %esi
movq %rax, %rcx
callq 0x72f0
movq %r14, 0x8(%rbx)
jmp 0x3bb3
movq %rbx, %rdi
callq 0x2030
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_free
static void eprog_free(struct multiboot *mboot)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;

    if (p_prog->device != NULL)
    {
        free(p_prog->device);
    }

    free(p_prog);
    free(mboot);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x3bd6
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2030
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_close
static int eprog_close(struct multiboot *mboot)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;

    if (p_prog->progmode == PROGMODE_ENABLED)
    {
        eprog_set_progmode(p_prog, PROGMODE_DISABLED);
    }

    eprog_close_device(p_prog);

    return 0;
}

// Assembly:
pushq %rbx
movq 0x8(%rdi), %rbx
cmpb $0x1, 0x70(%rbx)
jne 0x3f21
movq %rbx, %rdi
xorl %esi, %esi
callq 0x43a1
movq %rbx, %rdi
callq 0x437c
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_read
static int eprog_read(struct multiboot *mboot,
                      struct databuf *dbuf, int memtype)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;
    char *progress_msg = "reading EPROM";

    /* unused parameter */
    (void)memtype;

    uint32_t pos = 0;
    uint32_t size = p_prog->eprom_type * 1024;

    if (eprog_set_address(p_prog, pos) < 0)
    {
        fprintf(stderr, "failed to set address\n");
        return -1;
    }

    while (pos < size)
    {
        mboot->progress_cb(progress_msg, pos, size);

        uint8_t len = MIN(p_prog->pagesize_max, size - pos);
        if (eprog_read_data(p_prog, dbuf->data + pos, len))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    dbuf->length = pos;

    mboot->progress_cb(progress_msg, pos, size);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, (%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %r12
movzbl 0x69(%r12), %r14d
movq %r12, %rdi
callq 0x4677
testl %eax, %eax
js 0x3ffd
movl %r14d, %eax
shll $0xa, %r14d
movl $0x0, %r13d
testb %al, %al
je 0x3fb7
movq (%rsp), %rax
leaq 0x8(%rax), %rbp
xorl %r13d, %r13d
leaq 0x4977(%rip), %rdi      # 0x88f3
movl %r13d, %esi
movl %r14d, %edx
callq *0x18(%rbx)
movzbl 0x68(%r12), %eax
movl %r14d, %ecx
subl %r13d, %ecx
cmpl %eax, %ecx
cmoval %eax, %ecx
movl %r13d, %esi
addq %rbp, %rsi
movzbl %cl, %r15d
movq %r12, %rdi
movl %r15d, %edx
callq 0x46bf
testl %eax, %eax
jne 0x3fd3
addl %r15d, %r13d
cmpl %r14d, %r13d
jb 0x3f75
movq (%rsp), %rax
movl %r13d, 0x4(%rax)
leaq 0x492d(%rip), %rdi      # 0x88f3
movl %r13d, %esi
movl %r14d, %edx
callq *0x18(%rbx)
xorl %ebp, %ebp
jmp 0x3fec
leaq 0x4919(%rip), %rdi      # 0x88f3
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *0x18(%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x25c0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x3fec
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_verify
static int eprog_verify(struct multiboot *mboot,
                       struct databuf *dbuf, int memtype)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;
    char *progress_msg = "verifing EPROM";

    /* unused parameter */
    (void)memtype;

    uint32_t pos = 0;
    uint8_t comp[256];

    if (eprog_set_address(p_prog, pos) < 0)
    {
        fprintf(stderr, "failed to set address\n");
        return -1;
    }

    while (pos < dbuf->length)
    {
        mboot->progress_cb(progress_msg, pos, dbuf->length);

        uint8_t len = MIN(p_prog->pagesize, dbuf->length - pos);
        if (eprog_read_data(p_prog, comp, len))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        if (memcmp(comp, dbuf->data + pos, len) != 0x00)
        {
            mboot->progress_cb(progress_msg, -1, -1);
            fprintf(stderr, "verify failed at pos 0x%04x!!\n", pos);
            return -1;
        }

        pos += len;
    }

    dbuf->length = pos;

    mboot->progress_cb(progress_msg, pos, dbuf->length);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %r12
movq %r12, %rdi
callq 0x4677
testl %eax, %eax
js 0x40e6
movl 0x4(%r15), %edx
movl $0x0, %ebp
testl %edx, %edx
je 0x40ad
movq 0x8(%rsp), %rax
addq $0x18, %rax
movq %rax, (%rsp)
leaq 0x8(%r15), %r13
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
leaq 0x489f(%rip), %rdi      # 0x8901
movl %ebp, %esi
movq (%rsp), %rax
callq *(%rax)
movzbl 0x6a(%r12), %eax
movl 0x4(%r15), %ecx
subl %ebp, %ecx
cmpl %eax, %ecx
cmoval %eax, %ecx
movzbl %cl, %ebx
movq %r12, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x46bf
testl %eax, %eax
jne 0x40c8
movl %ebp, %esi
addq %r13, %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x21e0
testl %eax, %eax
jne 0x40ed
addl %ebx, %ebp
movl 0x4(%r15), %edx
cmpl %edx, %ebp
jb 0x405b
movl %ebp, 0x4(%r15)
leaq 0x4849(%rip), %rdi      # 0x8901
movl %ebp, %esi
movl %ebp, %edx
movq 0x8(%rsp), %rax
callq *0x18(%rax)
xorl %ebx, %ebx
jmp 0x40fd
leaq 0x4832(%rip), %rdi      # 0x8901
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq (%rsp), %rax
callq *(%rax)
jmp 0x40fd
callq 0x260c
jmp 0x40f8
movq (%rsp), %rdi
movl %ebp, %esi
callq 0x25dc
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/orempel[P]multiboot_tool/eprom_prog.c
// Function: eprog_write
static int eprog_write(struct multiboot *mboot,
                       struct databuf *dbuf,
                       int memtype)
{
    struct eprog_privdata *p_prog = (struct eprog_privdata *)mboot->privdata;
    char *progress_msg = "writing EPROM";

    /* unused parameter */
    (void)memtype;

    uint32_t pos = 0;

    if (eprog_set_address(p_prog, pos) < 0)
    {
        fprintf(stderr, "failed to set address\n");
        return -1;
    }

    while (pos < dbuf->length)
    {
        mboot->progress_cb(progress_msg, pos, dbuf->length);

        uint8_t len = MIN(p_prog->pagesize, dbuf->length - pos);
        if (eprog_write_data(p_prog, dbuf->data + pos, len))
        {
            mboot->progress_cb(progress_msg, -1, -1);
            return -1;
        }

        pos += len;
    }

    mboot->progress_cb(progress_msg, pos, dbuf->length);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movq %r15, %rdi
callq 0x4677
testl %eax, %eax
js 0x4219
movl 0x4(%r14), %eax
movl $0x0, %r12d
movl $0x0, %edx
testl %eax, %eax
je 0x41de
leaq 0x8(%r14), %rbp
xorl %r12d, %r12d
movl %eax, %edx
leaq 0x47b3(%rip), %rdi      # 0x8910
movl %r12d, %esi
callq *0x18(%rbx)
movzbl 0x6a(%r15), %eax
movl 0x4(%r14), %r13d
subl %r12d, %r13d
cmpl %eax, %r13d
cmoval %eax, %r13d
movb $0x6, 0x6(%rsp)
movb %r13b, 0x7(%rsp)
movl 0x44(%r15), %edi
movl $0x2, %edx
leaq 0x6(%rsp), %rsi
callq 0x2090
movzbl %r13b, %r13d
testl %eax, %eax
jle 0x41ca
movl %r12d, %esi
addq %rbp, %rsi
movl 0x44(%r15), %edi
movq %r13, %rdx
callq 0x2090
testl %eax, %eax
jle 0x41ca
movl 0x44(%r15), %edi
movl $0x86, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x452c
movl %eax, %ecx
sarl $0x1f, %eax
andl %ecx, %eax
testl %eax, %eax
jne 0x41ef
addl %r13d, %r12d
movl 0x4(%r14), %edx
cmpl %edx, %r12d
jb 0x4156
leaq 0x472b(%rip), %rdi      # 0x8910
movl %r12d, %esi
callq *0x18(%rbx)
xorl %ebp, %ebp
jmp 0x4208
leaq 0x471a(%rip), %rdi      # 0x8910
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq *0x18(%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2628
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x4208