LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/fmadio[P]pcap_flow/./fTypes.h
// Function: FormatTS
static inline char* FormatTS(u64 ts)
{
	u64 usec = ts / 1000ULL;
	u64 msec = usec / 1000ULL;
	u64 sec = msec / 1000ULL;
	u64 min = sec / 60ULL;
	u64 hour = min / 60ULL;

	u64 nsec = ts - usec*1000ULL;
	usec = usec - msec*1000ULL;
	msec = msec - sec*1000ULL;
	sec = sec - min*60ULL;
	min = min - hour*60ULL;

	static char List[16][128];
	static int Pos = 0;

	char* S = List[Pos];
	Pos = (Pos + 1) & 0xf;

	sprintf(S, "%02lli:%02lli:%02lli.%03lli.%03lli.%03lli", hour % 24, min, sec, msec,usec, nsec);

	return S;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
movq %rdx, %rcx
movabsq $0x431bde82d7b634db, %rdx # imm = 0x431BDE82D7B634DB
movq %rdi, %rax
mulq %rdx
movq %rdx, %rsi
shrq $0x4, %rcx
movq %rdi, %rax
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rdx # imm = 0x44B82FA09B5A53
mulq %rdx
movq %rdx, %r10
shrq $0x12, %rsi
movq %rdi, %rax
shrq $0xb, %rax
movabsq $0x9299ff347e9e9, %rdx  # imm = 0x9299FF347E9E9
mulq %rdx
movq %rdx, %r11
shrq $0xb, %r10
shrq $0xc, %r11
movabsq $-0x63a000d9128a12ab, %rdx # imm = 0x9C5FFF26ED75ED55
movq %rdi, %rax
mulq %rdx
shrq $0x29, %rdx
imulq $-0x3e8, %rcx, %r14     # imm = 0xFC18
addq %rdi, %r14
imulq $-0x3e8, %rsi, %r15     # imm = 0xFC18
addq %rcx, %r15
imulq $-0x3e8, %r10, %r9      # imm = 0xFC18
addq %rsi, %r9
imulq $-0x3c, %r11, %r8
addq %r10, %r8
imulq $-0x3c, %rdx, %rcx
addq %r11, %rcx
movslq 0xa7eb(%rip), %rax      # 0xd9c0
leal 0x1(%rax), %esi
shlq $0x7, %rax
leaq 0x9fdd(%rip), %rbx      # 0xd1c0
addq %rax, %rbx
andl $0xf, %esi
movl %esi, 0xa7d1(%rip)      # 0xd9c0
imulq $0xaaaaaab, %rdx, %rax  # imm = 0xAAAAAAB
shrq $0x20, %rax
shll $0x3, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edx
leaq 0x633e(%rip), %rsi      # 0x9547
movq %rbx, %rdi
xorl %eax, %eax
pushq %r14
pushq %r15
callq 0x1230
addq $0x10, %rsp
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/fmadio[P]pcap_flow/tcpstream.c
// Function: fTCPStream_FlowStats
void fTCPStream_FlowStats(TCPStream_t* S, FILE* Out)
{
	if (!S) return;

	fprintf(Out, " BufPos: %8i WritePos:%8i PktTotal:%8i PktOOO:%8i PktDrop:%8i", 
					S->BufferListPos, 
					S->WritePos,
					S->PktTotal,
					S->PktOOO,
					S->PktDrop

	);
}

// Assembly:
testq %rdi, %rdi
je 0x377d
pushq %rax
movl 0x1c(%rdi), %edx
movq 0x2440(%rdi), %rcx
movl 0x2458(%rdi), %r8d
movl 0x2454(%rdi), %r9d
movl 0x2450(%rdi), %eax
movl %eax, (%rsp)
leaq 0x5d4d(%rip), %rax      # 0x94bc
movq %rsi, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x1170
popq %rax
retq
nop
// File: /workspace/github_c_makefile_star2_O3/fmadio[P]pcap_flow/udpstream.c
// Function: fUDPStream_Add
void fUDPStream_Add(UDPStream_t* Stream, u64 TS, PCAPPacket_t* Pkt, UDPHeader_t* UDPHeader)
{
	// output in PCAP format
	if (g_OutputPCAP)
	{
		fFile_Write(Stream->F, Pkt, sizeof(PCAPPacket_t) + Pkt->LengthCapture, true);
		return;
	}

	// write only the UDP payload
	u32 Length = swap16(UDPHeader->Length);	
	if (Length >= 16*1024)
	{
		fprintf(stderr, "udp packet length invalid UDP Length:%i PacketLength:%i\n", Length, Pkt->Length);
		return;
	}

	// ensure its caped at the packet length
	if (Length > Pkt->Length)
	{
		fprintf(stderr, "udp packet length truncated: Header %i Capture %i\n", Length, Pkt->Length);
		Length = Pkt->Length;
	}	

	if (g_EnableUDPHeader)
	{
		OutputHeader_t Header;
		Header.TS 		= TS;
		Header.Length 	= sizeof(UDPHeader_t) + Length; 
		Header.StreamID	= Stream->FlowID;
		fFile_Write(Stream->F, &Header, sizeof(Header), false );
	}

	// write the UDP header + payload 
	fFile_Write(Stream->F, UDPHeader, sizeof(UDPHeader_t) + Length, true);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r13
movq %rdi, %r14
leaq 0xa885(%rip), %rax      # 0xe214
cmpl $0x0, (%rax)
je 0x39b8
movq (%r14), %rdi
movl 0x8(%r13), %edx
addl $0x10, %edx
movq %r13, %rsi
movl $0x1, %ecx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x836e
movq %rcx, %rbx
movzwl 0x4(%rcx), %eax
rolw $0x8, %ax
movzwl %ax, %r15d
cmpl $0x4000, %r15d          # imm = 0x4000
jae 0x3a3a
movq %rsi, %r12
movl 0xc(%r13), %ecx
cmpl %r15d, %ecx
jb 0x3a66
leaq 0xa819(%rip), %rax      # 0xe200
cmpl $0x0, (%rax)
je 0x3a15
movq %rsp, %rsi
movq %r12, (%rsi)
leal 0x8(%r15), %eax
movw %ax, 0x8(%rsi)
movzwl 0x408(%r14), %eax
movw %ax, 0xa(%rsi)
movq (%r14), %rdi
movl $0x10, %edx
xorl %ecx, %ecx
callq 0x836e
movq (%r14), %rdi
addl $0x8, %r15d
movq %rbx, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x836e
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x95b7(%rip), %rax      # 0xcff8
movq (%rax), %rdi
movl 0xc(%r13), %ecx
leaq 0x5c05(%rip), %rsi      # 0x9654
movl %r15d, %edx
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x1170
movq 0x958b(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x5c16(%rip), %rsi      # 0x968d
movl %r15d, %edx
xorl %eax, %eax
callq 0x1170
movl 0xc(%r13), %r15d
jmp 0x39e0
nop
// File: /workspace/github_c_makefile_star2_O3/fmadio[P]pcap_flow/main.c
// Function: FlowAlloc
static void FlowAlloc(u32 FlowMax)
{
	s_FlowListMax 		= FlowMax;

	if (s_FlowExtract)		free(s_FlowExtract);
	if (s_ExtractTCPFlow)	free(s_ExtractTCPFlow);
	if (s_ExtractTCP) 		free(s_ExtractTCP);
	if (s_ExtractUDP) 		free(s_ExtractUDP);

	s_FlowExtract 		= (u8*)malloc( s_FlowListMax * sizeof(u8) );
	s_ExtractTCPFlow 	= (u8*)malloc( s_FlowListMax * sizeof(u8) );
	s_ExtractTCP	 	= (struct TCPStream_t**)malloc( s_FlowListMax * sizeof(void*) );
	s_ExtractUDP	 	= (struct UDPStream_t**)malloc( s_FlowListMax * sizeof(void*) );

	memset(s_FlowExtract,		0, s_FlowListMax * sizeof(u8) );
	memset(s_ExtractTCPFlow,	0, s_FlowListMax * sizeof(u8) );
	memset(s_ExtractTCP, 		0, s_FlowListMax * sizeof(void*) );
	memset(s_ExtractUDP, 		0, s_FlowListMax * sizeof(void*) );
}

// Assembly:
pushq %rbx
movl %edi, %ebx
movl %edi, 0x811f(%rip)      # 0xe550
movq 0x7de0(%rip), %rdi      # 0xe218
testq %rdi, %rdi
je 0x6442
callq 0x1030
movq 0x7df7(%rip), %rdi      # 0xe240
testq %rdi, %rdi
je 0x6453
callq 0x1030
movq 0x8106(%rip), %rdi      # 0xe560
testq %rdi, %rdi
je 0x6464
callq 0x1030
movq 0x80fd(%rip), %rdi      # 0xe568
testq %rdi, %rdi
je 0x6475
callq 0x1030
movl %ebx, %ebx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x1140
movq %rax, 0x7d8d(%rip)      # 0xe218
movl $0x1, %edi
movq %rbx, %rsi
callq 0x1140
movq %rax, 0x7da1(%rip)      # 0xe240
shlq $0x3, %rbx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x1140
movq %rax, 0x80a9(%rip)      # 0xe560
movl $0x1, %edi
movq %rbx, %rsi
callq 0x1140
movq %rax, 0x809d(%rip)      # 0xe568
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/fmadio[P]pcap_flow/main.c
// Function: PrintHumanFlows
static void PrintHumanFlows(void)
{
	u64 PktMax = 0;
	/*
	for (int i=1; i < s_FlowListPos; i++)
	{
		FlowHash_t* F = &s_FlowList[i];
		if (PktMax < F->PktCnt) PktMax = F->PktCnt;
	}
	*/

	u32 FlowCnt = 0;
	s32 Remain = s_FlowListPos-1;
	while (Remain > 0)
	{
		u64 NextMax = 1e16;
		for (int i=1; i < s_FlowListPos; i++)
		{
			FlowHash_t* F = &s_FlowList[i];
			if (F->PktCnt == PktMax)
			{
				if (F->PktCnt >= s_FlowListPacketMin)
				{
					switch (F->Type)
					{
					case FLOW_TYPE_TCP: PrintFlowTCP(stdout, F, i, FlowCnt); break;
					case FLOW_TYPE_UDP: PrintFlowUDP(stdout, F, i, FlowCnt); break;
					}
				}
				
				Remain--;
				FlowCnt++;
				assert(Remain >= 0);
			}
			else if (F->PktCnt > PktMax)
			{
				if (NextMax > F->PktCnt) NextMax = F->PktCnt;
			}
		}

		//printf("%i -> %i : %i\n", PktMax, NextMax, Remain);
		PktMax = NextMax;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x6c82(%rip), %eax      # 0xd160
leal -0x1(%rax), %ebp
testl %ebp, %ebp
jle 0x65ad
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpl $0x2, %eax
jb 0x6598
movl $0x1, %r14d
movl $0x70, %r12d
movabsq $0x2386f26fc10000, %r15 # imm = 0x2386F26FC10000
movq 0x8044(%rip), %rsi      # 0xe558
movq 0x48(%rsi,%r12), %rcx
cmpq %r13, %rcx
jne 0x654f
cmpq 0x7f6b(%rip), %r13      # 0xe490
jb 0x6576
movl 0x44(%rsi,%r12), %eax
addq %r12, %rsi
cmpl $0x2, %eax
je 0x6562
cmpl $0x1, %eax
jne 0x6576
movq 0x6a90(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movl %r14d, %edx
movl %ebx, %ecx
callq 0x65db
jmp 0x6576
cmpq %rcx, %r15
movq %rcx, %rdx
cmovbq %r15, %rdx
cmpq %r13, %rcx
cmovaq %rdx, %r15
jmp 0x6584
movq 0x6a67(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movl %r14d, %edx
movl %ebx, %ecx
callq 0x6b1a
testl %ebp, %ebp
jle 0x65bc
incl %ebx
decl %ebp
movl 0x6bdc(%rip), %eax      # 0xd160
incq %r14
movl %eax, %ecx
addq $0x70, %r12
cmpq %rcx, %r14
jb 0x650d
jmp 0x65a2
movabsq $0x2386f26fc10000, %r15 # imm = 0x2386F26FC10000
movq %r15, %r13
testl %ebp, %ebp
jg 0x64ee
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4535(%rip), %rdi      # 0xaaf8
leaq 0x3320(%rip), %rsi      # 0x98ea
leaq 0x4533(%rip), %rcx      # 0xab04
movl $0x28f, %edx            # imm = 0x28F
callq 0x1110
// File: /workspace/github_c_makefile_star2_O3/fmadio[P]pcap_flow/fFile.c
// Function: fFile_Open
struct fFile_t* fFile_Open(u8* Path, u8* Mode)
{
	fFile_t* F = (fFile_t*)malloc( sizeof(fFile_t) );
	memset(F, 0, sizeof(fFile_t));

	strncpy(F->Path, Path, sizeof(F->Path));

	// initial output buffer 
	F->IsBuffer		= true;
	F->BufferMax	= s_FileSizeMin;
	F->BufferPos	= 0;
	F->Buffer		= malloc( F->BufferMax );		
	memset(F->Buffer, 0, F->BufferMax );

	F->TotalByte	= 0;

	// if file existed before get total length
	struct stat fstat;	
	if (stat(F->Path, &fstat) >= 0) 
	{
		F->TotalByte = fstat.st_size;
	}

	// new file allocated 
	s_TotalFile++;

	return F;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r14
movl $0x1, %edi
movl $0x438, %esi            # imm = 0x438
callq 0x1140
movq %rax, %rbx
movl $0x400, %edx            # imm = 0x400
movq %rax, %rdi
movq %r14, %rsi
callq 0x1050
movl $0x1, 0x408(%rbx)
movq 0x4e44(%rip), %rsi      # 0xd168
movq %rsi, 0x420(%rbx)
movl $0x1, %edi
callq 0x1140
movq %rax, 0x410(%rbx)
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x1180
testl %eax, %eax
js 0x8359
movq 0x38(%rsp), %rax
movq %rax, 0x428(%rbx)
incq 0x6e50(%rip)            # 0xf1b0
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/fmadio[P]pcap_flow/fFile.c
// Function: fFile_Write
void fFile_Write(struct fFile_t* F, void* Buffer, u32 Length, bool IsPayload)
{
	// should never write with a null file handle
	assert(F != NULL);

	// need to create a file 
	if (F->IsBuffer)
	{
		if (F->BufferPos + Length > F->BufferMax)
		{
			F->File = fopen(F->Path, "a");
			assert(F->File != NULL);

			fwrite(F->Buffer, 1, F->BufferPos, F->File);
			F->TotalByte	+= F->BufferPos;

			F->IsBuffer 	= false;
			F->BufferPos	= 0;

			s_TotalFileActive++;
		}
	}

	// buffer it
	if (F->IsBuffer)
	{
		memcpy(F->Buffer + F->BufferPos, Buffer, Length);
		F->BufferPos += Length;
	}
	else
	{
		assert(F->File != NULL);

		fwrite(Buffer, 1, Length, F->File);
		if (s_ForceFlush) fflush(F->File);
		F->TotalByte	+= Length; 
	}

	// if this is payload
	if (IsPayload) F->TotalPayload += Length;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x847a
movl %ecx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
cmpl $0x0, 0x408(%rdi)
movl %edx, %r14d
je 0x840f
movq 0x418(%rbx), %rdi
leaq (%rdi,%r14), %rax
cmpq 0x420(%rbx), %rax
jbe 0x8449
leaq 0x27d3(%rip), %rsi      # 0xab85
movq %rbx, %rdi
callq 0x1210
movq %rax, 0x400(%rbx)
testq %rax, %rax
je 0x84b8
movq 0x410(%rbx), %rdi
movq 0x418(%rbx), %rdx
movl $0x1, %esi
movq %rax, %rcx
callq 0x1250
movq 0x418(%rbx), %rax
addq %rax, 0x428(%rbx)
movl $0x0, 0x408(%rbx)
movq $0x0, 0x418(%rbx)
incq 0x6da9(%rip)            # 0xf1b8
movq 0x400(%rbx), %rcx
testq %rcx, %rcx
je 0x8499
movl $0x1, %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x1250
cmpb $0x1, 0x6d8e(%rip)      # 0xf1c0
jne 0x8440
movq 0x400(%rbx), %rdi
callq 0x11c0
leaq 0x428(%rbx), %r12
jmp 0x8462
leaq 0x418(%rbx), %r12
addq 0x410(%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1190
addq %r14, (%r12)
testl %ebp, %ebp
je 0x8471
addq %r14, 0x430(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23a9(%rip), %rdi      # 0xa82a
leaq 0x26bf(%rip), %rsi      # 0xab47
leaq 0x26c0(%rip), %rcx      # 0xab4f
movl $0x5d, %edx
callq 0x1110
leaq 0x26e7(%rip), %rdi      # 0xab87
leaq 0x26a0(%rip), %rsi      # 0xab47
leaq 0x26a1(%rip), %rcx      # 0xab4f
movl $0x79, %edx
callq 0x1110
leaq 0x26c8(%rip), %rdi      # 0xab87
leaq 0x2681(%rip), %rsi      # 0xab47
leaq 0x2682(%rip), %rcx      # 0xab4f
movl $0x65, %edx
callq 0x1110
// File: /workspace/github_c_makefile_star2_O3/fmadio[P]pcap_flow/fFile.c
// Function: fFile_Close
void fFile_Close(struct fFile_t* F)
{
	if (!F) return;

	// flush buffer contents if not written to disk
	if (F->IsBuffer && (F->BufferPos > 0))
	{
		// if theres real substational data the flush it
		if (F->TotalPayload > s_FileSizeMin)
		{
			F->File = fopen(F->Path, "a");
			assert(F->File != NULL);

			fwrite(F->Buffer, 1, F->BufferPos, F->File);
			F->BufferPos = 0;
		}
	}

	// close
	if (F->File)
	{
		fclose(F->File);
		s_TotalFileActive--;
	}

	if (F->Buffer)
	{
		free(F->Buffer);
		F->Buffer = NULL;
	}
	memset(F, 0, sizeof(fFile_t));
	free(F);

	s_TotalFileClose++;
}

// Assembly:
pushq %rbx
testq %rdi, %rdi
je 0x8580
movq %rdi, %rbx
cmpl $0x0, 0x408(%rdi)
je 0x8548
cmpq $0x0, 0x418(%rbx)
je 0x8548
movq 0x430(%rbx), %rax
cmpq 0x4c63(%rip), %rax      # 0xd168
jbe 0x8548
leaq 0x2677(%rip), %rsi      # 0xab85
movq %rbx, %rdi
callq 0x1210
movq %rax, 0x400(%rbx)
testq %rax, %rax
je 0x8582
movq 0x410(%rbx), %rdi
movq 0x418(%rbx), %rdx
movl $0x1, %esi
movq %rax, %rcx
callq 0x1250
movq $0x0, 0x418(%rbx)
movq 0x400(%rbx), %rdi
testq %rdi, %rdi
je 0x8560
callq 0x10d0
decq 0x6c58(%rip)            # 0xf1b8
movq 0x410(%rbx), %rdi
testq %rdi, %rdi
je 0x8571
callq 0x1030
movq %rbx, %rdi
callq 0x1030
incq 0x6c48(%rip)            # 0xf1c8
popq %rbx
retq
leaq 0x25fe(%rip), %rdi      # 0xab87
leaq 0x25b7(%rip), %rsi      # 0xab47
leaq 0x2600(%rip), %rcx      # 0xab97
movl $0x91, %edx
callq 0x1110
// File: /workspace/github_c_makefile_star2_O3/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_6/exercise_6_02/var_group.c
// Function: main
int main(int argc, char *argv[])
{
  if (!parse_arg_list(argc, argv))
  {
    puts("Error: invalid arguments.");
    return EXIT_FAILURE;
  }

  int n;
  struct list_node *list_root = NULL;
  char word[MAX_WORD_LEN];

  while (get_word(word, MAX_WORD_LEN) != EOF)
  {
    if ((n = bin_search(word, data_types, NR_OF_TYPES)) >= 0)
    {
      do
      {
        // NOTE: This approach takes into consideration both variable and function names.
        if (get_word(word, MAX_WORD_LEN) != EOF && (isalpha(word[0]) || word[0] == '_'))
        {
          list_root = add_to_list(list_root, word);
        }
      } while (get_word(word, MAX_WORD_LEN) == ',');
    }
  }

  print_list(list_root);

  return EXIT_SUCCESS;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x68, %rsp
callq 0x12b8
testl %eax, %eax
je 0x1299
movq %rsp, %rdi
movl $0x64, %esi
callq 0x12fd
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpl $-0x1, %eax
je 0x128f
leaq 0x2e6a(%rip), %r15      # 0x4080
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rsi
movl $0x7, %edx
callq 0x1402
testl %eax, %eax
js 0x127d
movq %r12, %rdi
movl $0x64, %esi
callq 0x12fd
cmpl $-0x1, %eax
je 0x126b
callq 0x10d0
movsbq (%rsp), %rcx
cmpq $0x5f, %rcx
je 0x125d
movq (%rax), %rax
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0x126b
movq %r14, %rdi
movq %r12, %rsi
callq 0x1463
movq %rax, %r14
movq %r12, %rdi
movl $0x64, %esi
callq 0x12fd
cmpl $0x2c, %eax
je 0x122d
movq %r12, %rdi
movl $0x64, %esi
callq 0x12fd
cmpl $-0x1, %eax
jne 0x1219
movq %r14, %rdi
callq 0x14c4
jmp 0x12aa
leaq 0xd8a(%rip), %rdi       # 0x202a
callq 0x1060
movl $0x1, %ebx
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_6/exercise_6_02/var_group.c
// Function: get_word
int get_word(char *word, int max_word_len)
{
  skip_blanks();
  skip_comments();
  skip_char_literal();
  skip_string_literal();

  int c = getc(stdin);
  size_t i = 0;

  if (c != EOF)
  {
    word[i++] = c;
  }

  if (!isalpha(c) && c != '_')
  {
    word[i] = '\0';
    return c;
  }

  while ((isalnum(c = getc(stdin)) || c == '_') && i < max_word_len)
  {
    word[i++] = c;
  }
  ungetc(c, stdin);
  word[i] = '\0';

  return word[0];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, 0x4(%rsp)
movq %rdi, %rbx
callq 0x150f
callq 0x1547
movl $0x27, %edi
movl $0x27, %esi
callq 0x15b4
movl $0x22, %edi
movl $0x22, %esi
callq 0x15b4
movq 0x2ca2(%rip), %r12      # 0x3fe0
movq (%r12), %rdi
callq 0x10c0
movl %eax, %r15d
cmpl $-0x1, %eax
je 0x135a
movb %r15b, (%rbx)
movl $0x1, %r13d
jmp 0x135d
xorl %r13d, %r13d
callq 0x10d0
movq %rax, %r14
movq (%rax), %rbp
cmpl $0x5f, %r15d
je 0x1384
movslq %r15d, %rax
movzwl (%rbp,%rax,2), %eax
andl $0x400, %eax            # imm = 0x400
jne 0x1384
movb $0x0, (%rbx,%r13)
jmp 0x13f0
movq (%r12), %rdi
callq 0x10c0
movslq %eax, %rcx
testb $0x8, (%rbp,%rcx,2)
sete %dl
cmpl $0x5f, %ecx
setne %cl
andb %dl, %cl
movslq 0x4(%rsp), %r15
cmpq %r15, %r13
setae %dl
orb %cl, %dl
jne 0x13dc
movb %al, (%rbx,%r13)
incq %r13
movq (%r14), %rbp
movq (%r12), %rdi
callq 0x10c0
movslq %eax, %rcx
testb $0x8, (%rbp,%rcx,2)
sete %dl
cmpl $0x5f, %ecx
setne %cl
testb %dl, %cl
jne 0x13dc
cmpq %r15, %r13
jb 0x13af
movq (%r12), %rsi
movl %eax, %edi
callq 0x10a0
movb $0x0, (%rbx,%r13)
movsbl (%rbx), %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_6/exercise_6_02/var_group.c
// Function: bin_search
int bin_search(char *word, char *arr[], int arr_len)
{
  int low = 0;
  int high = arr_len - 1;
  int mid;

  while (low <= high)
  {
    mid = (low + high) / 2;

    int cond = strcmp(word, arr[mid]);
    if (cond < 0)
    {
      high = mid - 1;
    }
    else if (cond > 0)
    {
      low = mid + 1;
    }
    else
    {
      return mid;
    }
  }

  return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %edx, %edx
jle 0x1452
movl %edx, %r12d
movq %rsi, %r14
movq %rdi, %r15
decl %r12d
xorl %r13d, %r13d
leal (%r12,%r13), %ebp
shrl %ebp
movq (%r14,%rbp,8), %rsi
movq %r15, %rdi
callq 0x1080
testl %eax, %eax
jns 0x1442
decl %ebp
movl %ebp, %r12d
jmp 0x1449
je 0x1450
incl %ebp
movl %ebp, %r13d
cmpl %r12d, %r13d
jle 0x1425
jmp 0x1452
movl %ebp, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_6/exercise_6_02/var_group.c
// Function: add_to_list
struct list_node *add_to_list(struct list_node *list_node_p, char *word)
{
  if (list_node_p == NULL)
  {
    list_node_p = (struct list_node *)malloc(sizeof(struct list_node));
    list_node_p->var_group = add_to_tree(list_node_p->var_group, word);
  }
  else if (strncmp(list_node_p->var_group->word, word, var_name_str_cmp_len) == 0)
  {
    list_node_p->var_group = add_to_tree(list_node_p->var_group, word);
  }
  else
  {
    list_node_p->next = add_to_list(list_node_p->next, word);
  }

  return list_node_p;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
testq %rdi, %rdi
je 0x149e
movq %rdi, %rbx
movq (%rdi), %r15
movq (%r15), %rdi
movslq 0x2c38(%rip), %rdx      # 0x40b8
movq %r14, %rsi
callq 0x1040
testl %eax, %eax
je 0x14ad
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x1463
movq %rax, 0x8(%rbx)
jmp 0x14bb
movl $0x10, %edi
callq 0x1090
movq %rax, %rbx
jmp 0x14b0
movq %r15, %rdi
movq %r14, %rsi
callq 0x162d
movq %rax, (%rbx)
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_6/exercise_6_02/var_group.c
// Function: print_list
void print_list(struct list_node *node_p)
{
  if (node_p != NULL)
  {
    print_tree(node_p->var_group);
    putchar('\n');
    print_list(node_p->next);
  }
}

// Assembly:
testq %rdi, %rdi
je 0x14e9
pushq %rbx
movq %rdi, %rbx
movq (%rbx), %rdi
callq 0x169b
movl $0xa, %edi
callq 0x1030
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
jne 0x14cd
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_6/exercise_6_02/var_group.c
// Function: skip_chars_between
void skip_chars_between(char start, char end)
{
  int c = getc(stdin);
  if (c == start)
  {
    while ((c = getc(stdin)) != EOF)
    {
      if (c == '\\')
      {
        if ((c = getc(stdin)) == EOF)
        {
          break;
        }
      }
      else if (c == end)
      {
        return;
      }
    }
  }
  ungetc(c, stdin);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebx
movl %edi, %ebp
movq 0x2a1d(%rip), %r14      # 0x3fe0
movq (%r14), %rdi
callq 0x10c0
cmpl %ebp, %eax
jne 0x15fc
movsbl %bl, %ebx
movq (%r14), %rdi
callq 0x10c0
cmpl $0x5c, %eax
je 0x15ea
cmpl $-0x1, %eax
je 0x15fc
cmpl %ebx, %eax
jne 0x15d2
jmp 0x160a
movq (%r14), %rdi
callq 0x10c0
cmpl $-0x1, %eax
jne 0x15d2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq (%r14), %rsi
movl %eax, %edi
popq %rbx
popq %r14
popq %rbp
jmp 0x10a0
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/ohkimur[P]the-c-programming-language-2nd-edition-solutions/chapter_6/exercise_6_02/var_group.c
// Function: print_tree
void print_tree(struct tree_node *node_p)
{
  if (node_p != NULL)
  {
    print_tree(node_p->left);
    puts(node_p->word);
    print_tree(node_p->right);
  }
}

// Assembly:
testq %rdi, %rdi
je 0x16bf
pushq %rbx
movq %rdi, %rbx
movq 0x8(%rbx), %rdi
callq 0x169b
movq (%rbx), %rdi
callq 0x1060
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x16a4
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: setNotify
bool setNotify(struct service* s, struct conn *c) {
    struct conn **onot = s->notify;
    size_t onot_n = s->notify_n;
    size_t nnot_n = onot_n + 1;
    struct conn **nnot = arralloc(struct conn*, nnot_n);
    if(nnot == NULL) {
        return false;
    }
    memcpy(nnot, onot, sizeof(struct notify*) * onot_n);
    nnot[onot_n] = c;
    ref(c);
    free(onot);
    s->notify = nnot;
    s->notify_n++;
    return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r15
movq %rdi, %rbx
movq 0x10(%rdi), %r14
movq 0x18(%rdi), %r13
leaq 0x8(,%r13,8), %rsi
movl $0x1, %edi
callq 0x1100
movq %rax, %r12
testq %rax, %rax
je 0x1b80
leaq (,%r13,8), %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x1140
movq %r15, (%r12,%r13,8)
incl 0x10(%r15)
movq %r14, %rdi
callq 0x1030
movq %r12, 0x10(%rbx)
incq 0x18(%rbx)
testq %r12, %r12
setne %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: notify
enum{ notify_fail, notify_success, notify_gone } notify(struct conn *c, struct service* s, struct buf msg) {
    if(c->closed == true) {
        deref(c);   //get rid of reference so the conn can be freed
        return notify_gone;
    }
    byte* ndat = realloc(c->tx.dat, c->tx.len + msg.len);
    if(ndat == NULL) {
        return notify_fail;
    }
    memcpy(ndat + c->tx.len, msg.dat, msg.len);
    c->tx.dat = ndat;
    c->tx.len += msg.len;
    if(c->txoff && (c->tx.len > 0)) {  //tx buffer was just populated
        //enable write in epoll
        struct epoll_event ev = {.events = EPOLLIN | EPOLLOUT, .data = {.ptr = &c->e}};
        if(epoll_ctl(epollfd, EPOLL_CTL_MOD, c->fd, &ev) == -1) {   //failed to enable - close and forget
            fprintf(stderr, "[ERROR] Failed to enable writing on conn %d\n", c->fd);
            close_conn(c);
        } else {
            c->txoff = false;
        }
    }
    return notify_success;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpb $0x1, 0x18(%rdi)
jne 0x1bc0
movl $0x2, %ebp
subl $0x1, 0x10(%rbx)
jae 0x1c3c
movq %rbx, %rdi
callq 0x1030
jmp 0x1c3c
movq %rcx, %r14
movq %rdx, %r15
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
addq %rcx, %rsi
callq 0x1160
testq %rax, %rax
je 0x1c3a
movq %rax, %r12
movq 0x38(%rbx), %r13
movq %rax, %rdi
addq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1140
movq %r12, 0x30(%rbx)
addq %r14, %r13
movq %r13, 0x38(%rbx)
setne %al
andb 0x19(%rbx), %al
movl $0x1, %ebp
cmpb $0x1, %al
jne 0x1c3c
leaq 0xc(%rsp), %rcx
movl $0x5, (%rcx)
movq %rbx, 0x4(%rcx)
movl 0x5526(%rip), %edi      # 0x7148
movl 0x14(%rbx), %edx
movl $0x3, %esi
callq 0x10e0
cmpl $-0x1, %eax
je 0x1c4d
movb $0x0, 0x19(%rbx)
jmp 0x1c3c
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14(%rbx), %rdi
movq %rbx, %rsi
callq 0x1260
jmp 0x1c3c
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: close_conn
void close_conn(struct conn *c) {   //close a connection
    printf("[INFO] Disconnecting connection %d\n", c->fd);
    if(epoll_ctl(epollfd, EPOLL_CTL_DEL, c->fd, NULL) == -1) {  //not compat before Linux 2.6.9
        fprintf(stderr, "[FATAL] Failed to deregister conn with epoll\n");
        exit(65);
    }
    if(close(c->fd) == -1) {
        fprintf(stderr, "[FATAL] Failed to close fd %d: %s\n", c->fd, strerror(errno));
        exit(65);
    }
    c->closed = true;
    c->fd = -1;
    //wipe rx/tx buffers
    free(c->rx.dat);
    free(c->tx.dat);
    bzero(&c->rx, sizeof(c->rx));
    bzero(&c->tx, sizeof(c->tx));
    deref(c);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x14(%rdi), %esi
leaq 0x2614(%rip), %rdi      # 0x4280
xorl %eax, %eax
callq 0x10c0
movl 0x54cf(%rip), %edi      # 0x7148
movl 0x14(%rbx), %edx
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x10e0
cmpl $-0x1, %eax
je 0x1ce3
leaq 0x14(%rbx), %r14
movl (%r14), %edi
callq 0x10d0
cmpl $-0x1, %eax
je 0x1ce8
movb $0x1, 0x18(%rbx)
movl $0xffffffff, 0x14(%rbx) # imm = 0xFFFFFFFF
movq 0x20(%rbx), %rdi
callq 0x1030
movq 0x30(%rbx), %rdi
callq 0x1030
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
subl $0x1, 0x10(%rbx)
jae 0x1cdb
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1030
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x12c4
movq %r14, %rdi
callq 0x128b
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: notifyAll
bool notifyAll(struct service* s) {
    char *cmds = NULL;
    if(asprintf(&cmds, "notify %s %s", s->name, statestr(s->state)) == -1) {
        return false;
    }
    struct buf cmdb = { .dat = cmds, .len = strlen(cmds) + 1 };
    bool oks[s->notify_n];
    size_t nok = 0;
    for(size_t i = 0; i < s->notify_n; i++) {
        switch(notify(s->notify[i], s, cmdb)) {
        case notify_success:
            oks[i] = true;
            nok++;
            break;
        case notify_gone:
            oks[i] = false;
            break;
        case notify_fail:
            free(cmds);
            return false;
        }
    }
    if(nok != s->notify_n) {
        //compact the buffer
        struct conn **not = s->notify;
        for(size_t i = 0; i < s->notify_n; i++) {
            if(oks[i]) { *(not++) = s->notify[i]; }
        }
        //shrink memory allocation with realloc
        not = realloc(s->notify, sizeof(struct conn *) * nok);
        if(not == NULL) {   //reallocation failed - just change the notify_n
            s->notify_n = nok;
        } else {
            s->notify = not;
            s->notify_n = nok;
        }
    }
    free(cmds);
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq $0x0, -0x38(%rbp)
movq (%rdi), %rdx
movl 0x8(%rdi), %eax
cmpq $0x5, %rax
ja 0x1d25
leaq 0x5099(%rip), %rcx      # 0x6db8
movq (%rcx,%rax,8), %rcx
jmp 0x1d2c
leaq 0x22fa(%rip), %rcx      # 0x4026
leaq 0x2324(%rip), %rsi      # 0x4057
xorl %r13d, %r13d
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
callq 0x1170
cmpl $-0x1, %eax
je 0x1e2c
movq -0x38(%rbp), %rdi
movq %rdi, -0x40(%rbp)
callq 0x10a0
movq %rax, %r12
movq %rsp, -0x30(%rbp)
movq 0x18(%rbx), %rax
movq %rsp, %r14
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movb $0x1, %r13b
cmpq $0x0, 0x18(%rbx)
je 0x1dcc
incq %r12
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x10(%rbx), %rax
movq (%rax,%r13,8), %rdi
movq -0x40(%rbp), %rdx
movq %r12, %rcx
callq 0x1b90
cmpl $0x1, %eax
je 0x1dab
cmpl $0x2, %eax
jne 0x1dc9
movb $0x0, (%r14,%r13)
jmp 0x1db3
movb $0x1, (%r14,%r13)
incq %r15
incq %r13
movq 0x18(%rbx), %rax
cmpq %rax, %r13
jb 0x1d86
cmpq %rax, %r15
jne 0x1dd2
movb $0x1, %r13b
jmp 0x1dcc
xorl %r13d, %r13d
movq -0x30(%rbp), %r14
jmp 0x1e20
movq 0x10(%rbx), %rdi
testq %rax, %rax
movb $0x1, %r13b
je 0x1e02
xorl %ecx, %ecx
cmpb $0x1, (%r14,%rcx)
jne 0x1df6
movq 0x10(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, (%rdi)
addq $0x8, %rdi
incq %rcx
cmpq %rcx, %rax
jne 0x1de0
movq 0x10(%rbx), %rdi
leaq (,%r15,8), %rsi
callq 0x1160
testq %rax, %rax
movq -0x30(%rbp), %r14
je 0x1e1c
movq %rax, 0x10(%rbx)
movq %r15, 0x18(%rbx)
movq -0x38(%rbp), %rdi
callq 0x1030
movq %r14, %rsp
movl %r13d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: findService
struct service* findService(char* name) {
    struct service *s;
    for(s = services.first; s != NULL; s = s->next) {
        if(streq(s->name, name)) {
            return s;
        }
    }
    return s;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq 0x5307(%rip), %rbx      # 0x7150
testq %rbx, %rbx
je 0x1e69
movq %rdi, %r14
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x1120
testl %eax, %eax
je 0x1e6b
movq 0x20(%rbx), %rbx
testq %rbx, %rbx
jne 0x1e51
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: newService
struct service* newService() {
    struct service* new = alalloc(struct service);
    if(new == NULL) {
        return NULL;
    }
    if(services.first == NULL) {
        services.first = new;
        return new;
    }
    struct service *s, *n;
    for(s = n = services.first; n != NULL; n = n->next) { s = n; }
    s->next = new;
    return new;
}

// Assembly:
pushq %rax
movl $0x1, %edi
movl $0x28, %esi
callq 0x1100
testq %rax, %rax
je 0x1eb3
movq 0x52be(%rip), %rdx      # 0x7150
testq %rdx, %rdx
je 0x1ea9
movq %rdx, %rcx
movq 0x20(%rdx), %rdx
testq %rdx, %rdx
jne 0x1e97
addq $0x20, %rcx
jmp 0x1eb0
leaq 0x52a0(%rip), %rcx      # 0x7150
movq %rax, (%rcx)
popq %rcx
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: rmService
void rmService(char* name) {
    struct service *s, *n;
    for(s = n = services.first; (n != NULL) && (!streq(n->name, name)); n = n->next) { s = n; }
    if(n == NULL) {
        fprintf(stderr, "[FATAL] Service %s does not exist\n", name);
        exit(65);
    }
    s->next = n->next;
    //notifications should already have been dealt with
    free(n->name);
    free(n);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x5289(%rip), %rbx      # 0x7150
testq %rbx, %rbx
je 0x1f25
movq (%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1120
testl %eax, %eax
je 0x1efe
movq %rbx, %r12
movq 0x20(%rbx), %rbx
testq %rbx, %rbx
je 0x1f25
movq (%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1120
testl %eax, %eax
jne 0x1ede
jmp 0x1f01
movq %rbx, %r12
movq 0x20(%rbx), %rax
movq %rax, 0x20(%r12)
movq %r15, %rdi
callq 0x1030
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x1030
movq %r14, %rdi
callq 0x12e9
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: readBuf
bool readBuf(struct buf *b, int fd) {  //read data from fd into the buffer
    byte dat[1024];
    size_t n = read(fd, dat, 1024);
    if(n < 0) {
        return false;
    } else if(n == 0) {
        return true;
    }
    byte* nd = arralloc(byte, n + b->len);
    if(nd == NULL) {
        return false;
    }
    memcpy(nd, b->dat, b->len);
    memcpy(nd + b->len, dat, n);
    free(b->dat);
    b->dat = nd;
    b->len += n;
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movl %esi, %eax
movq %rdi, %rbx
movq %rsp, %rsi
movl $0x400, %edx            # imm = 0x400
movl %eax, %edi
callq 0x10f0
movb $0x1, %bpl
testq %rax, %rax
je 0x1fac
movq %rax, %r14
movq 0x8(%rbx), %r12
leaq (%r12,%rax), %rsi
movl $0x1, %edi
callq 0x1100
testq %rax, %rax
je 0x1faa
movq %rax, %r15
movq (%rbx), %r13
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1140
movq %r15, %rdi
addq %r12, %rdi
movq %rsp, %rsi
movq %r14, %rdx
callq 0x1140
movq %r13, %rdi
callq 0x1030
movq %r15, (%rbx)
addq %r14, 0x8(%rbx)
jmp 0x1fac
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: writeBuf
bool writeBuf(struct buf* b, int fd) { //write data from buffer into fd
    size_t n = write(fd, b->dat, b->len);
    if(n < 1) {
        return false;
    }
    byte* nd = arralloc(byte, n - b->len);
    if(nd == NULL) {
        return false;
    }
    memcpy(nd, b->dat + n, b->len - n);
    free(b->dat);
    b->dat = nd;
    b->len -= n;
    return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %esi, %eax
movq %rdi, %rbx
movq (%rdi), %rsi
movq 0x8(%rdi), %rdx
movl %eax, %edi
callq 0x1090
testq %rax, %rax
je 0x2028
movq %rax, %r14
movq 0x8(%rbx), %r15
movq %rax, %rsi
subq %r15, %rsi
movl $0x1, %edi
callq 0x1100
testq %rax, %rax
je 0x2028
movq %rax, %r12
movq (%rbx), %r13
leaq (%r14,%r13), %rsi
subq %r14, %r15
movq %rax, %rdi
movq %r15, %rdx
callq 0x1140
movq %r13, %rdi
callq 0x1030
movq %r12, (%rbx)
subq %r14, 0x8(%rbx)
movb $0x1, %al
jmp 0x202a
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: set_noblock
void set_noblock(int fd) {
    int flags = fcntl(fd, F_GETFL, 0);
    if(flags < 0) {
        goto fail;
    }
    flags |= O_NONBLOCK;
    if(fcntl(fd, F_SETFL, flags) == -1) {
        goto fail;
    }
    return;
fail:
    fprintf(stderr, "[FATAL] Failed to SET O_NONBLOCK on %d: %s\n", fd, strerror(errno));
    exit(65);
}

// Assembly:
pushq %rbx
movl %edi, %ebx
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x1080
testl %eax, %eax
js 0x2065
orl $0x800, %eax            # imm = 0x800
movl %ebx, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x1080
cmpl $-0x1, %eax
je 0x2065
popq %rbx
retq
movl %ebx, %edi
callq 0x130d
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: addSock
void addSock(int fd) {  //add a socket to epoll
    printf("Sock: %d\n", fd);
    if(listen(fd, backlog) == -1) {
        fprintf(stderr, "[FATAL] Failed to run listen on %d: %s\n", fd, strerror(errno));
        exit(65);
    }
    struct epolldat *d = alalloc(struct epolldat);
    if(d == NULL) {
        fprintf(stderr, "[FATAL] Failed to allocate epolldat for %d: %s\n", fd, strerror(errno));
        exit(65);
    }
    d->typecode = epoll_socket;
    d->sockfd = fd;
    //register with epoll
    struct epoll_event ev = {.events = EPOLLIN, .data = {.ptr = d}};
    if(epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) {
        fprintf(stderr, "[FATAL] Failed to register with epoll: %s\n", strerror(errno));
        exit(65);
    }
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movl %edi, %ebx
leaq 0x2039(%rip), %rdi      # 0x40b3
movl %ebx, %esi
xorl %eax, %eax
callq 0x10c0
movl 0x50af(%rip), %esi      # 0x7138
movl %ebx, %edi
callq 0x1150
cmpl $-0x1, %eax
je 0x20db
movl $0x1, %edi
movl $0x10, %esi
callq 0x1100
testq %rax, %rax
je 0x20e2
movl $0x1, %edx
movl %edx, (%rax)
movl %ebx, 0x8(%rax)
leaq 0x4(%rsp), %rcx
movl %edx, (%rcx)
movq %rax, 0x4(%rcx)
movl 0x5084(%rip), %edi      # 0x7148
movl $0x1, %esi
movl %ebx, %edx
callq 0x10e0
cmpl $-0x1, %eax
je 0x20e9
addq $0x10, %rsp
popq %rbx
retq
movl %ebx, %edi
callq 0x13b4
movl %ebx, %edi
callq 0x137a
callq 0x1347
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: handle_epoll
void handle_epoll(struct epoll_event ev) {  //handle an epoll event
    struct epolldat d = *((struct epolldat*)ev.data.ptr);
    switch(d.typecode) {
    case epoll_conn:
        handle_conn(d.c, ev.events);
        break;
    case epoll_socket:
        handle_socket(d.sockfd, ev.events);
        break;
    }
}

// Assembly:
leaq 0x8(%rsp), %rax
movq 0x4(%rax), %rdx
movl (%rdx), %ecx
movq 0x8(%rdx), %rdi
cmpl $0x1, %ecx
je 0x210d
testl %ecx, %ecx
jne 0x2114
movl (%rax), %esi
jmp 0x2115
movl (%rax), %esi
jmp 0x22b2
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: handle_socket
void handle_socket(int sockfd, uint32_t events) {
    if(EPOLL_MODE(events, EPOLLIN)) {
        int fd = accept(sockfd, NULL, NULL);
        if(fd == -1) {
            fprintf(stderr, "[ERROR] Failed to accept connection: %s\n", strerror(errno));
            return;
        }
        struct conn *c = newConn(fd);
        if(c == NULL) {
            fprintf(stderr, "[ERROR] Failed to create conn with fd %d\n", fd);
            if(close(fd) == -1) {
                fprintf(stderr, "[FATAL] Failed to close fd %d\n", fd);
                exit(65);
            }
            return;
        }
    } else if(EPOLL_MODE(events, EPOLLPRI)) {
        fprintf(stderr, "[FATAL] Recieved EPOLLPRI on socket fd %d\n", sockfd);
        exit(65);
    } else if(EPOLL_MODE(events, EPOLLERR)) {
        fprintf(stderr, "[FATAL] Recieved EPOLLERR on socket fd %d\n", sockfd);
        exit(65);
    } else {
        fprintf(stderr, "[FATAL] Recieved unrecognized epoll event %d on socket fd %d\n", events, sockfd);
        exit(65);
    }
}

// Assembly:
pushq %rbx
movl %esi, %edx
movl %edi, %ecx
testb $0x1, %dl
je 0x22ec
movl %ecx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x11c0
cmpl $-0x1, %eax
je 0x22dc
movl %eax, %ebx
movl %eax, %edi
callq 0x23a3
testq %rax, %rax
je 0x22e3
popq %rbx
retq
callq 0x1510
jmp 0x22da
movl %ebx, %edi
callq 0x14c1
jmp 0x22da
testb $0x2, %dl
jne 0x2310
movq 0x4d00(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
testb $0x8, %dl
jne 0x2317
leaq 0x1f3b(%rip), %rsi      # 0x4242
xorl %eax, %eax
callq 0x1130
jmp 0x2327
movl %ecx, %edi
callq 0x153c
leaq 0x1ef9(%rip), %rsi      # 0x4217
movl %ecx, %edx
xorl %eax, %eax
callq 0x1130
movl $0x41, %edi
callq 0x11f0
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: epoll_cycle
void epoll_cycle() {    //run epoll wait with a timeout and handle the events
    struct epoll_event ev[4];
    int n = epoll_wait(epollfd, ev, 4, 50);
    if(n == -1) {
        fprintf(stderr, "[FATAL] epoll_wait failed: %s\n", strerror(errno));
        exit(65);
        return;
    }
    for(int i = 0; i < n; i++) {
        handle_epoll(ev[i]);
    }
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl 0x4e0a(%rip), %edi      # 0x7148
leaq 0x10(%rsp), %rsi
movl $0x4, %edx
movl $0x32, %ecx
callq 0x1180
cmpl $-0x1, %eax
je 0x239e
testl %eax, %eax
jle 0x2396
movl %eax, %eax
shlq $0x2, %rax
leaq (%rax,%rax,2), %rbx
xorl %r14d, %r14d
movl 0x18(%rsp,%r14), %eax
movl %eax, 0x8(%rsp)
movq 0x10(%rsp,%r14), %rax
movq %rax, (%rsp)
movl 0x8(%rsp), %eax
movq (%rsp), %rcx
pushq %rax
pushq %rcx
callq 0x20ee
addq $0x10, %rsp
addq $0xc, %r14
cmpq %r14, %rbx
jne 0x2368
addq $0x48, %rsp
popq %rbx
popq %r14
retq
callq 0x155f
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: newConn
struct conn *newConn(int fd) { //create a new conn with fd
    printf("[INFO] New connection: %d\n", fd);
    //set up conn data
    struct conn *c = alalloc(struct conn);
    if(c == NULL) {
        return NULL;
    }
    c->e.typecode = epoll_conn;
    c->e.c = c;
    c->fd = fd;
    c->txoff = true;
    //register with epoll
    struct epoll_event ev = {.events = EPOLLIN, .data = {.ptr = &c->e}};
    if(epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) {
        fprintf(stderr, "[FATAL] Failed to register with epoll: %s\n", strerror(errno));
        exit(65);
    }
    ref(c); //referenced by epoll
    //tell read and write not to block
    set_noblock(fd);
    return c;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
leaq 0x1dac(%rip), %rdi      # 0x415f
movl %ebx, %esi
xorl %eax, %eax
callq 0x10c0
movl $0x1, %edi
movl $0x40, %esi
callq 0x1100
movq %rax, %r14
testq %rax, %rax
je 0x2411
movq %r14, 0x8(%r14)
movl %ebx, 0x14(%r14)
movb $0x1, 0x19(%r14)
leaq 0xc(%rsp), %rcx
movl $0x1, (%rcx)
movq %r14, 0x4(%rcx)
movl 0x4d53(%rip), %edi      # 0x7148
movl $0x1, %esi
movl %ebx, %edx
callq 0x10e0
cmpl $-0x1, %eax
je 0x241c
incl 0x10(%r14)
movl %ebx, %edi
callq 0x2034
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r14
retq
callq 0x1592
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: conn_has_cmd
bool conn_has_cmd(struct conn *c) { //is there is a full command in the buffer?
    if(c->closed) { return false; }
    struct buf b = c->rx;
    for(size_t i = 0; i < b.len; i++) {
        switch(b.dat[i]) {
        case '\n':
            b.dat[i] = '\0';
        case '\0':
            return true;
        }
    }
    return false;
}

// Assembly:
cmpb $0x0, 0x18(%rdi)
jne 0x244d
movq 0x28(%rdi), %rcx
testq %rcx, %rcx
je 0x244d
movq 0x20(%rdi), %rdx
xorl %esi, %esi
movzbl (%rdx,%rsi), %edi
movb $0x1, %al
testl %edi, %edi
je 0x244f
cmpl $0xa, %edi
je 0x2450
incq %rsi
cmpq %rsi, %rcx
jne 0x2436
xorl %eax, %eax
retq
movb $0x0, (%rdx,%rsi)
retq
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: handle_scmd
void handle_scmd(struct conn *c) {
    ref(c);
    //extract command from rx buffer
    char *cmds = strdup(c->rx.dat);
    if(cmds == NULL) {
        fprintf(stderr, "[ERROR] Failed to extract command from conn %d\n", c->fd);
        close_conn(c);
        goto end;
    }
    //slide & shrink rx buffer
    memmove(c->rx.dat, c->rx.dat + strlen(cmds) + 1, c->rx.len - (strlen(cmds) + 1));
    c->rx.len -= strlen(cmds) + 1;
    byte *ndat = realloc(c->rx.dat, c->rx.len);
    if(ndat != NULL) {
        c->rx.dat = ndat;
    }
    //split command and args
    if(!hasSpace(cmds)) {
        fprintf(stderr, "[ERROR] Invalid command syntax (sent by conn %d): \"%s\"\n", c->fd, cmds);
        free(cmds);
        close_conn(c);
        goto end;
    }
    char *cmd, *args;
    for(cmd = args = cmds; *args != ' '; args++) {}
    *args = '\0';
    args++;
    //run handler
    if(streq(cmd, "start")) {
        cmd_start(c, args);
    } else if(streq(cmd, "stop")) {
        cmd_stop(c, args);
    } else if(streq(cmd, "state")) {
        cmd_state(c, args);
    } else {
        fprintf(stderr, "[ERROR] Unrecognized command \"%s\" sent on conn %d\n", cmd, c->fd);
        free(cmds);
        close_conn(c);
        goto end;
    }
    //cleanup
    free(cmds);
end:
    deref(c);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
incl 0x10(%rdi)
movq 0x20(%rdi), %r15
movq %r15, %rdi
callq 0x1210
testq %rax, %rax
je 0x256a
movq %rax, %r14
movq %rax, %rdi
callq 0x10a0
leaq (%r15,%rax), %rsi
incq %rsi
notq %rax
addq 0x28(%rbx), %rax
movq %r15, %rdi
movq %rax, %rdx
callq 0x11a0
movq %r14, %rdi
callq 0x10a0
notq %rax
addq 0x28(%rbx), %rax
movq %rax, 0x28(%rbx)
movq 0x20(%rbx), %rdi
movq %rax, %rsi
callq 0x1160
testq %rax, %rax
je 0x24c1
movq %rax, 0x20(%rbx)
movq %r14, %rax
movzbl (%rax), %ecx
cmpl $0x20, %ecx
je 0x24d9
testl %ecx, %ecx
je 0x2574
incq %rax
jmp 0x24c4
movq %r14, %r15
cmpb $0x20, (%r15)
leaq 0x1(%r15), %r15
jne 0x24dc
movb $0x0, -0x1(%r15)
leaq 0x1ef8(%rip), %rsi      # 0x43ea
movq %r14, %rdi
callq 0x1120
testl %eax, %eax
je 0x2531
leaq 0x1ef1(%rip), %rsi      # 0x43f6
movq %r14, %rdi
callq 0x1120
testl %eax, %eax
je 0x253e
leaq 0x220c(%rip), %rsi      # 0x4724
movq %r14, %rdi
callq 0x1120
movq %rbx, %rdi
testl %eax, %eax
jne 0x2581
movq %r15, %rsi
callq 0x2ad9
jmp 0x2549
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2673
jmp 0x2549
movq %rbx, %rdi
movq %r15, %rsi
callq 0x28df
movq %r14, %rdi
callq 0x1030
subl $0x1, 0x10(%rbx)
jae 0x2564
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x1030
popq %rbx
popq %r14
popq %r15
retq
movq %rbx, %rdi
callq 0x1645
jmp 0x2551
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1605
jmp 0x2551
movq %r14, %rsi
callq 0x15c5
jmp 0x2551
// File: /workspace/github_c_makefile_star2_O3/panux[P]linit/src/linitd.c
// Function: fexec
bool fexec(int argc, char **argv) { //forks and exec's
    switch(fork()) {
    case -1:    //failure
        return false;
    case 0:;    //child
        char *args[argc + 1];
        for(int i = 0; i < argc; i++) {
            args[i] = argv[i];
        }
        args[argc] = NULL;
        if(execvpe(args[0], args, environ) == -1) {
            fprintf(stderr, "[FATAL] exec failed: %s\n", strerror(errno));
            exit(65);
        }
    }
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movl %edi, %ebx
callq 0x1230
cmpl $-0x1, %eax
je 0x2605
testl %eax, %eax
jne 0x2601
movq %rsp, %r12
leal 0x1(%rbx), %eax
movq %rsp, %r15
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
testl %ebx, %ebx
jle 0x25d9
movl %ebx, %edx
shlq $0x3, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x1140
movslq %ebx, %rax
movq $0x0, (%r15,%rax,8)
movq (%r15), %rdi
movq 0x49f2(%rip), %rax      # 0x6fe0
movq (%rax), %rdx
movq %r15, %rsi
callq 0x10b0
cmpl $-0x1, %eax
je 0x2614
movq %r12, %rsp
movb $0x1, %al
jmp 0x2607
xorl %eax, %eax
leaq -0x20(%rbp), %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x166d