LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes256otrsv2/ref/OTR.c
// Function: AFunc
int AFunc(
		  const uint8 *header,
		  uint32 h_len)
{
	uint32 i,j = 0;
	uint32 m, last;
	uint8 ASum[BLOCK]={0}, tmp[BLOCK], mask[BLOCK];

	last = h_len % BLOCK;
	if(last == 0) last = BLOCK;
	m = (h_len-last) / BLOCK; //header = m blocks + last bytes

	memcpy(mask,Q,BLOCK);
	/* XE */
	for(i = 0; i < m; i++, j=j+BLOCK){
		xor(mask,header+j,tmp);
		Encryption(KeyLen,tmp,tmp);
		xor(ASum,tmp,ASum);
		mul2(mask,mask);
	}
	/* last block */
	ozp(last,header+j,tmp);
	xor(ASum,tmp,ASum);

	if(last != BLOCK ){
		xor(mask, gamma, mask);
	}
	else{
		xor(mask,gamma2,mask);
	}
	xor(ASum,mask,ASum);
	Encryption(KeyLen,ASum,TA);
    return SUCCESS;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movl $0x0, 0x44(%rsp)
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
movl 0x4c(%rsp), %eax
andl $0xf, %eax
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jne 0x1ca0
movl $0x10, 0x3c(%rsp)
movl 0x4c(%rsp), %eax
subl 0x3c(%rsp), %eax
shrl $0x4, %eax
movl %eax, 0x40(%rsp)
movq 0x3302(%rip), %rax      # 0x4fb8
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movl $0x0, 0x48(%rsp)
movl 0x48(%rsp), %eax
cmpl 0x40(%rsp), %eax
jae 0x1d3c
movq %rsp, %rdi
movq 0x50(%rsp), %rsi
movl 0x44(%rsp), %eax
addq %rax, %rsi
leaq 0x10(%rsp), %rdx
callq 0x13d0
leaq 0x10(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x13d0
movq %rsp, %rdi
movq %rsp, %rsi
callq 0x1270
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
movl 0x44(%rsp), %eax
addl $0x10, %eax
movl %eax, 0x44(%rsp)
jmp 0x1cce
movl 0x3c(%rsp), %edi
movq 0x50(%rsp), %rsi
movl 0x44(%rsp), %eax
addq %rax, %rsi
leaq 0x10(%rsp), %rdx
callq 0x1850
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x13d0
cmpl $0x10, 0x3c(%rsp)
je 0x1d85
movq %rsp, %rdi
movq %rsp, %rdx
movq 0x320a(%rip), %rsi      # 0x4f88
callq 0x13d0
jmp 0x1d97
movq %rsp, %rdi
movq %rsp, %rdx
movq 0x325e(%rip), %rsi      # 0x4ff0
callq 0x13d0
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
callq 0x13d0
leaq 0x20(%rsp), %rsi
movl $0x100, %edi            # imm = 0x100
movq 0x322e(%rip), %rdx      # 0x4fe8
callq 0x10f0
xorl %eax, %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes256otrsv2/ref/OTR.c
// Function: AFuncS
int AFuncS(
		  const uint8 *header,
		  uint32 h_len)
{
	uint32 i,j = 0;
	uint32 m, last;
	uint8 tmp[BLOCK], chain[BLOCK]={0};

	last = h_len % BLOCK;
	if(last == 0) last = BLOCK;
	m = (h_len-last) / BLOCK; //header = m blocks + last bytes

	/* CBC */
	for(i = 0; i < m; i++, j=j+BLOCK){
		xor(chain,header+j,chain);
		Encryption(KeyLen,chain,chain);
	}
	/* last block */
	ozp(last,header+j,tmp);
	xor(tmp,chain,chain);
	if(last != BLOCK ){
		xor(chain,gamma2,chain);
	}
	else{
		xor(chain,Q,chain);
	}
	Encryption(KeyLen,chain,TA);
    return SUCCESS;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movl %esi, 0x3c(%rsp)
movl $0x0, 0x34(%rsp)
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1030
movl 0x3c(%rsp), %eax
andl $0xf, %eax
movl %eax, 0x2c(%rsp)
cmpl $0x0, 0x2c(%rsp)
jne 0x1e0e
movl $0x10, 0x2c(%rsp)
movl 0x3c(%rsp), %eax
subl 0x2c(%rsp), %eax
shrl $0x4, %eax
movl %eax, 0x30(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x30(%rsp), %eax
jae 0x1e6e
movq %rsp, %rdi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %eax
addq %rax, %rsi
movq %rsp, %rdx
callq 0x13d0
movq %rsp, %rsi
movq %rsp, %rdx
movl $0x100, %edi            # imm = 0x100
callq 0x10f0
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movl 0x34(%rsp), %eax
addl $0x10, %eax
movl %eax, 0x34(%rsp)
jmp 0x1e25
movl 0x2c(%rsp), %edi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %eax
addq %rax, %rsi
leaq 0x10(%rsp), %rdx
callq 0x1850
leaq 0x10(%rsp), %rdi
movq %rsp, %rsi
movq %rsp, %rdx
callq 0x13d0
cmpl $0x10, 0x2c(%rsp)
je 0x1eb3
movq %rsp, %rdi
movq %rsp, %rdx
movq 0x3144(%rip), %rsi      # 0x4ff0
callq 0x13d0
jmp 0x1ec5
movq %rsp, %rdi
movq %rsp, %rdx
movq 0x30f8(%rip), %rsi      # 0x4fb8
callq 0x13d0
movq %rsp, %rsi
movl $0x100, %edi            # imm = 0x100
movq 0x3114(%rip), %rdx      # 0x4fe8
callq 0x10f0
xorl %eax, %eax
addq $0x48, %rsp
retq
// File: /workspace/github_c_makefile_star2_O0/soso7885[P]OPCUA_example/demo_src/server_firstSteps.c
// Function: main
int main(void) {
    signal(SIGINT,  stopHandler);
    signal(SIGTERM, stopHandler);

    UA_ServerConfig config = UA_ServerConfig_standard;
    UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
    config.networkLayers = &nl;
    config.networkLayersSize = 1;
    UA_Server *server = UA_Server_new(config);

    UA_StatusCode retval = UA_Server_run(server, &running);
    UA_Server_delete(server);
    nl.deleteMembers(&nl);
    return (int)retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x330, %rsp            # imm = 0x330
movl $0x0, -0x4(%rbp)
movl $0x2, %edi
leaq 0x102(%rip), %rsi       # 0x12b0
callq 0x1060
movl $0xf, %edi
leaq 0xf1(%rip), %rsi        # 0x12b0
callq 0x1060
leaq -0x168(%rbp), %rdi
movq 0x2e0e(%rip), %rsi      # 0x3fe0
movl $0x160, %edx            # imm = 0x160
callq 0x1050
movq 0x2e0d(%rip), %rax      # 0x3ff0
movq (%rax), %rcx
movq %rcx, -0x1b8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x1b0(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x1a8(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
movl $0x4118, %esi           # imm = 0x4118
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0x1040
leaq -0x1a0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq $0x1, -0x78(%rbp)
movq %rsp, %rdi
movl $0x2c, %ecx
leaq -0x168(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x1030
movq %rax, -0x1c0(%rbp)
movq -0x1c0(%rbp), %rdi
leaq 0x2de9(%rip), %rsi      # 0x4058
callq 0x1070
movl %eax, -0x1c4(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x1080
leaq -0x1a0(%rbp), %rdi
callq *-0x170(%rbp)
movl -0x1c4(%rbp), %eax
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/tests/closed_exit_pipe.c
// Function: main
int main() {
  libforks_ServerConn conn;

  check(libforks_start(&conn) == libforks_OK);

  int exit_fd;
  pid_t child_pid;
  int socket_fd;

  libforks_Result r = libforks_fork(
    conn,
    &child_pid, // pid_ptr
    &socket_fd, // socket_fd_ptr
    &exit_fd, // exit_fd_ptr
    child_main
  );
  check(r == libforks_OK);

  close(exit_fd);
  write(socket_fd, "o", 1);
  check(write(socket_fd, "o", 1) == 1);

  // child exits now, but since exit_fd is closed we have to do this
  // dirty hack
  check(libforks_eval(conn, serv_wait) == libforks_OK);

  check(libforks_stop(conn) == libforks_OK);

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b10
cmpl $0x0, %eax
jne 0x132f
jmp 0x1347
leaq 0x2cce(%rip), %rdi      # 0x4004
leaq 0x2cec(%rip), %rsi      # 0x4029
movl $0x12, %edx
callq 0x1440
movq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
leaq -0x1c(%rbp), %rdx
leaq -0x14(%rbp), %rcx
leaq 0x122(%rip), %r8        # 0x1480
callq 0x22e0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x136e
jmp 0x1386
leaq 0x2ccd(%rip), %rdi      # 0x4042
leaq 0x2cad(%rip), %rsi      # 0x4029
movl $0x1f, %edx
callq 0x1440
movl -0x14(%rbp), %edi
callq 0x10d0
movl -0x1c(%rbp), %edi
leaq 0x2cbb(%rip), %rsi      # 0x4053
movl $0x1, %edx
callq 0x1080
movl -0x1c(%rbp), %edi
leaq 0x2ca7(%rip), %rsi      # 0x4053
movl $0x1, %edx
callq 0x1080
cmpq $0x1, %rax
jne 0x13be
jmp 0x13d6
leaq 0x2c90(%rip), %rdi      # 0x4055
leaq 0x2c5d(%rip), %rsi      # 0x4029
movl $0x23, %edx
callq 0x1440
movq -0x10(%rbp), %rdi
leaq 0x10f(%rip), %rsi       # 0x14f0
callq 0x26d0
cmpl $0x0, %eax
jne 0x13ed
jmp 0x1405
leaq 0x2c7f(%rip), %rdi      # 0x4073
leaq 0x2c2e(%rip), %rsi      # 0x4029
movl $0x27, %edx
callq 0x1440
movq -0x10(%rbp), %rdi
callq 0x2570
cmpl $0x0, %eax
jne 0x1415
jmp 0x142d
leaq 0x2c85(%rip), %rdi      # 0x40a1
leaq 0x2c06(%rip), %rsi      # 0x4029
movl $0x29, %edx
callq 0x1440
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: read_exact
__attribute__((warn_unused_result))
static int read_exact(int fd, void *data, size_t length) {
  ssize_t res = read(fd, data, length);
  if (res == -1) {
    return -1;
  }
  if (res != (ssize_t)length) {
    errno = EMSGSIZE;
    return -1;
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x1100
movq %rax, -0x20(%rbp)
cmpq $-0x1, -0x20(%rbp)
jne 0x1867
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x1885
callq 0x1050
movl $0x5a, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: write_exact
__attribute__((warn_unused_result))
static int write_exact(int fd, const void *data, size_t length) {
  ssize_t res = write(fd, data, length);
  if (res == -1) {
    return -1;
  }
  if (res != (ssize_t)length) {
    errno = EMSGSIZE;
    return -1;
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x1080
movq %rax, -0x20(%rbp)
cmpq $-0x1, -0x20(%rbp)
jne 0x1ad7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1afc
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x1af5
callq 0x1050
movl $0x5a, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1afc
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: libforks_start
libforks_Result libforks_start(libforks_ServerConn *conn_ptr) {
  libforks_Result res;
  pid_t main_proc_pid = getpid();

  int sockets[2];
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) {
    res = libforks_SOCKET_CREATION_ERROR;
    goto exit;
  }

  int server_pid = fork();
  if (server_pid == -1) {
    res = libforks_FORK_ERROR;
    goto del_sockets;
  }

  if (server_pid == 0) {
    // this is the server process
    close(sockets[1]);

    serv_Client *client = malloc(sizeof(serv_Client));
    if (!client) {
      serv_print_errno("malloc");
      serv_panic();
    }
    client->pid = main_proc_pid;
    client->main = true;
    client->socket = sockets[0];
    client->exit_fd = -1;
    client->next = NULL;

    serv_main(client);
    abort(); // not reached
  }

  ServerConn *conn = malloc(sizeof(ServerConn));
  if (!conn) {
    res = libforks_MALLOC_ERROR;
    goto kill_server;
  }

  close(sockets[0]);
  conn->server_pid = server_pid;
  conn->socket = sockets[1];

  conn_ptr->private = conn;
  res = libforks_OK;
  goto exit;

kill_server:
  kill(server_pid, SIGKILL);

del_sockets:
  close(sockets[0]);
  close(sockets[1]);

exit:
  return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
callq 0x1090
movl %eax, -0x10(%rbp)
leaq -0x18(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x1150
cmpl $-0x1, %eax
jne 0x1b47
movl $0xfffffffd, -0xc(%rbp) # imm = 0xFFFFFFFD
jmp 0x1c3a
callq 0x1200
movl %eax, -0x1c(%rbp)
cmpl $-0x1, -0x1c(%rbp)
jne 0x1b61
movl $0xfffffffb, -0xc(%rbp) # imm = 0xFFFFFFFB
jmp 0x1c2a
cmpl $0x0, -0x1c(%rbp)
jne 0x1bd0
movl -0x14(%rbp), %edi
callq 0x1c50
movl $0x18, %edi
callq 0x1170
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1b95
leaq 0x26c1(%rip), %rdi      # 0x424c
callq 0x1c90
callq 0x2830
movl -0x10(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movb $0x1, 0x4(%rax)
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x28(%rbp), %rdi
callq 0x1d20
movl $0x8, %edi
callq 0x1170
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1bee
movl $0xfffffffc, -0xc(%rbp) # imm = 0xFFFFFFFC
jmp 0x1c1d
movl -0x18(%rbp), %edi
callq 0x1c50
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0xc(%rbp)
jmp 0x1c3a
movl -0x1c(%rbp), %edi
movl $0x9, %esi
callq 0x1160
movl -0x18(%rbp), %edi
callq 0x1c50
movl -0x14(%rbp), %edi
callq 0x1c50
movl -0xc(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: checked_close
static int checked_close(int fd) {
  if (close(fd) != 0) {
    perror("libforks: close");
    abort();
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl -0x4(%rbp), %edi
callq 0x10d0
cmpl $0x0, %eax
je 0x1c79
leaq 0x27e6(%rip), %rdi      # 0x4455
callq 0x11c0
callq 0x1040
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_print_errno
static void serv_print_errno(const char *msg) {
  int e = errno;
  char buffer[256];
  assert(msg);
  snprintf(buffer, sizeof buffer, "libforks server: %s", msg);
  errno = e;
  perror(buffer);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
callq 0x1050
movl (%rax), %eax
movl %eax, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x1cb2
jmp 0x1cd1
leaq 0x2547(%rip), %rdi      # 0x4200
leaq 0x24f3(%rip), %rsi      # 0x41b3
movl $0x14e, %edx            # imm = 0x14E
leaq 0x2799(%rip), %rcx      # 0x4465
callq 0x10b0
leaq -0x110(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0x27a1(%rip), %rdx      # 0x4489
movb $0x0, %al
callq 0x10a0
movl -0xc(%rbp), %eax
movl %eax, -0x114(%rbp)
callq 0x1050
movl -0x114(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x110(%rbp), %rdi
callq 0x11c0
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: libforks_stop_server_only
libforks_Result libforks_stop_server_only(libforks_ServerConn conn_p) {
  ServerConn *conn = conn_p.private;

  ClientMessage req = {
    .type = ClientMessageType_STOP_SERVER_ONLY_REQUEST,
  };

  if (write_exact(conn->socket, &req, sizeof req) == -1) {
    return libforks_WRITE_ERROR;
  }

  return finalize_stop(conn);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq 0x1cb5(%rip), %rax      # 0x4140
movq %rax, -0x30(%rbp)
movq 0x1cb2(%rip), %rax      # 0x4148
movq %rax, -0x28(%rbp)
movq 0x1caf(%rip), %rax      # 0x4150
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x30(%rbp), %rsi
movl $0x18, %edx
callq 0x1aa0
cmpl $-0x1, %eax
jne 0x24c8
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x24d4
movq -0x18(%rbp), %rdi
callq 0x24e0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: finalize_stop
static libforks_Result finalize_stop(ServerConn *conn) {
  int status;
  if (waitpid(conn->server_pid, &status, 0) == -1) {
    return libforks_WAIT_ERROR;
  }

  assert(WIFEXITED(status) || WIFSIGNALED(status));

  close(conn->socket); // ignore error
  free(conn);
  return libforks_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x14(%rbp), %rsi
xorl %edx, %edx
callq 0x11a0
cmpl $-0x1, %eax
jne 0x250b
movl $0xfffffffa, -0x4(%rbp) # imm = 0xFFFFFFFA
jmp 0x2566
movl -0x14(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
je 0x2529
movl -0x14(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x252b
jmp 0x254a
leaq 0x213b(%rip), %rdi      # 0x466d
leaq 0x1c7a(%rip), %rsi      # 0x41b3
movl $0x457, %edx            # imm = 0x457
leaq 0x2280(%rip), %rcx      # 0x47c5
callq 0x10b0
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x1c50
movq -0x10(%rbp), %rdi
callq 0x1030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: libforks_stop
libforks_Result libforks_stop(libforks_ServerConn conn_p) {
  ServerConn *conn = conn_p.private;

  ClientMessage req = {
    .type = ClientMessageType_STOP_ALL_REQUEST,
  };
  if (write_exact(conn->socket, &req, sizeof req) == -1) {
    return libforks_WRITE_ERROR;
  }

  return finalize_stop(conn);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq 0x1bcd(%rip), %rax      # 0x4158
movq %rax, -0x30(%rbp)
movq 0x1bca(%rip), %rax      # 0x4160
movq %rax, -0x28(%rbp)
movq 0x1bc7(%rip), %rax      # 0x4168
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x30(%rbp), %rsi
movl $0x18, %edx
callq 0x1aa0
cmpl $-0x1, %eax
jne 0x25c8
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x25d4
movq -0x18(%rbp), %rdi
callq 0x24e0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: libforks_free_conn
libforks_Result libforks_free_conn(libforks_ServerConn conn_p) {
  ServerConn *conn = conn_p.private;
  close(conn->socket); // ignore error
  free(conn);
  return libforks_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x1c50
movq -0x10(%rbp), %rdi
callq 0x1030
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: libforks_kill_all
libforks_Result libforks_kill_all(libforks_ServerConn conn_p, int signal) {
  ServerConn *conn = conn_p.private;

  ClientMessage req = {
    .type = ClientMessageType_KILL_ALL_REQUEST,
    .u = {
      .kill_all_request = {
        .signal = signal
      },
    },
  };
  if (write_exact(conn->socket, &req, sizeof req) == -1) {
    return libforks_WRITE_ERROR;
  }

  ServerMessage res;
  if (read_exact(conn->socket, &res, sizeof res) == -1) {
    return libforks_READ_ERROR;
  }

  assert(res.type == ServerMessageType_KILL_SUCCESS);
  return libforks_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x3, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x38(%rbp), %rsi
movl $0x18, %edx
callq 0x1aa0
cmpl $-0x1, %eax
jne 0x2667
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x26b8
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x44(%rbp), %rsi
movl $0xc, %edx
callq 0x1830
cmpl $-0x1, %eax
jne 0x268a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x26b8
cmpl $0x2, -0x3c(%rbp)
jne 0x2692
jmp 0x26b1
leaq 0x1c80(%rip), %rdi      # 0x4319
leaq 0x1b13(%rip), %rsi      # 0x41b3
movl $0x494, %edx            # imm = 0x494
leaq 0x1c98(%rip), %rcx      # 0x4344
callq 0x10b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: libforks_eval
libforks_Result libforks_eval(libforks_ServerConn conn_p, void (*function)(void)) {
  ServerConn *conn = conn_p.private;

  ClientMessage req = {
    .type = ClientMessageType_EVAL_REQUEST,
    .u = {
      .eval_request = {
        .function = function
      },
    },
  };
  if (write_exact(conn->socket, &req, sizeof req) == -1) {
    return libforks_WRITE_ERROR;
  }

  ServerMessage res;
  if (read_exact(conn->socket, &res, sizeof res) == -1) {
    return libforks_READ_ERROR;
  }

  assert(res.type == ServerMessageType_EVAL_SUCCESS);
  return libforks_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x4, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x38(%rbp), %rsi
movl $0x18, %edx
callq 0x1aa0
cmpl $-0x1, %eax
jne 0x271a
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x276b
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x44(%rbp), %rsi
movl $0xc, %edx
callq 0x1830
cmpl $-0x1, %eax
jne 0x273d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x276b
cmpl $0x3, -0x3c(%rbp)
jne 0x2745
jmp 0x2764
leaq 0x1c34(%rip), %rdi      # 0x4380
leaq 0x1a60(%rip), %rsi      # 0x41b3
movl $0x4ac, %edx            # imm = 0x4AC
leaq 0x1c4c(%rip), %rcx      # 0x43ab
callq 0x10b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: libforks_result_string
const char *libforks_result_string(libforks_Result result) {
  switch (result) {
#define E(name) case libforks_##name: return #name;
    E(OK)
    E(READ_ERROR)
    E(WRITE_ERROR)
    E(SOCKET_CREATION_ERROR)
    E(MALLOC_ERROR)
    E(FORK_ERROR)
    E(WAIT_ERROR)
    E(TOO_MANY_CLIENTS_ERROR)
  }
  abort();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0xc(%rbp)
movl -0xc(%rbp), %eax
addl $0x7, %eax
movl %eax, %ecx
movq %rcx, -0x18(%rbp)
subl $0x7, %eax
ja 0x2818
movq -0x18(%rbp), %rax
leaq 0x1961(%rip), %rcx      # 0x4108
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1ac6(%rip), %rax      # 0x427d
movq %rax, -0x8(%rbp)
jmp 0x281d
leaq 0x1c2a(%rip), %rax      # 0x43ee
movq %rax, -0x8(%rbp)
jmp 0x281d
leaq 0x1c28(%rip), %rax      # 0x43f9
movq %rax, -0x8(%rbp)
jmp 0x281d
leaq 0x1c27(%rip), %rax      # 0x4405
movq %rax, -0x8(%rbp)
jmp 0x281d
leaq 0x1c30(%rip), %rax      # 0x441b
movq %rax, -0x8(%rbp)
jmp 0x281d
leaq 0x1c30(%rip), %rax      # 0x4428
movq %rax, -0x8(%rbp)
jmp 0x281d
leaq 0x1c2e(%rip), %rax      # 0x4433
movq %rax, -0x8(%rbp)
jmp 0x281d
leaq 0x1c2c(%rip), %rax      # 0x443e
movq %rax, -0x8(%rbp)
jmp 0x281d
callq 0x1040
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_print_error
__attribute__((format(printf, 1, 2)))
static void serv_print_error(const char *format, ...) {
  va_list ap;
  va_start(ap, format);
  // XXX `dprintf` is guaranteed to be async-signal-safe on OpenBSD
  // but not on other systems.
  dprintf(STDERR_FILENO, "libforks server: ");
  vdprintf(STDERR_FILENO, format, ap);
  dprintf(STDERR_FILENO, "\n");
  va_end(ap);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
testb %al, %al
je 0x2885
movaps %xmm0, -0xa0(%rbp)
movaps %xmm1, -0x90(%rbp)
movaps %xmm2, -0x80(%rbp)
movaps %xmm3, -0x70(%rbp)
movaps %xmm4, -0x60(%rbp)
movaps %xmm5, -0x50(%rbp)
movaps %xmm6, -0x40(%rbp)
movaps %xmm7, -0x30(%rbp)
movq %r9, -0xa8(%rbp)
movq %r8, -0xb0(%rbp)
movq %rcx, -0xb8(%rbp)
movq %rdx, -0xc0(%rbp)
movq %rsi, -0xc8(%rbp)
movq %rdi, -0x8(%rbp)
leaq -0xd0(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x30, -0x1c(%rbp)
movl $0x8, -0x20(%rbp)
leaq 0x1c01(%rip), %rsi      # 0x44d5
xorl %eax, %eax
movb %al, -0xd1(%rbp)
movl $0x2, %edi
movl %edi, -0xd8(%rbp)
callq 0x10e0
movl -0xd8(%rbp), %edi
movq -0x8(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0x11b0
movl -0xd8(%rbp), %edi
movb -0xd1(%rbp), %al
leaq 0x17cc(%rip), %rsi      # 0x40de
callq 0x10e0
addq $0xe0, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_sigchld_handler
static void serv_sigchld_handler(int sig_) {
  (void)sig_;

  // This function uses `serv_DEBUG` and `serv_print_errno` which
  // could theoretically be async-signal-unsafe. But that’s only
  // when debugging is enabled or if a fatal error occurs.

  int prev_errno = errno;

  // We know that some children have exited but we don’t know which ones.
  // We can list them by calling `waitpid(-1, …, …)` repeatedly.

  serv_DEBUG("received SIGCHLD\n");

  while (true) {
    int status;
    pid_t child_pid = waitpid(-1, &status, WNOHANG);
    if (child_pid == 0 || (child_pid == -1 && errno == ECHILD)) {
      // no more stopped children
      break;
    }

    if (child_pid == -1) {
      serv_print_errno("waitpid(2) system call in SIGCHLD handler");
      serv_panic();
    }

    assert(WIFEXITED(status) || WIFSIGNALED(status));

    serv_DEBUG("child %d exited, informing main loop\n", (int)child_pid);

    libforks_ExitEvent event = {
      .pid = child_pid,
      .wait_status = status,
    };
    if (write_exact(serv_exit_pipe[WRITE_END], &event, sizeof event) == -1) {
      serv_print_errno("write(2) system call in SIGCHLD handler");
      serv_panic();
    }
  }

  serv_DEBUG("SIGCHLD handling done\n");

  errno = prev_errno;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
callq 0x1050
movl (%rax), %eax
movl %eax, -0x8(%rbp)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq -0xc(%rbp), %rsi
movl $0x1, %edx
callq 0x11a0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x2961
cmpl $-0x1, -0x10(%rbp)
jne 0x2966
callq 0x1050
cmpl $0xa, (%rax)
jne 0x2966
jmp 0x29f7
cmpl $-0x1, -0x10(%rbp)
jne 0x297d
leaq 0x1cd0(%rip), %rdi      # 0x4643
callq 0x1c90
callq 0x2830
movl -0xc(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
je 0x299b
movl -0xc(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x299d
jmp 0x29bc
leaq 0x1cc9(%rip), %rdi      # 0x466d
leaq 0x1808(%rip), %rsi      # 0x41b3
movl $0x1b4, %edx            # imm = 0x1B4
leaq 0x1cdf(%rip), %rcx      # 0x4696
callq 0x10b0
movl -0x10(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x14(%rbp)
movl 0x4752(%rip), %edi      # 0x7120
leaq -0x18(%rbp), %rsi
movl $0x8, %edx
callq 0x1aa0
cmpl $-0x1, %eax
jne 0x29f2
leaq 0x1ccd(%rip), %rdi      # 0x46b5
callq 0x1c90
callq 0x2830
jmp 0x2935
movl -0x8(%rbp), %eax
movl %eax, -0x1c(%rbp)
callq 0x1050
movl -0x1c(%rbp), %ecx
movl %ecx, (%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_remove_client
static serv_Client *serv_remove_client(serv_Client **list_ptr, pid_t pid) {
  serv_Client **prev_ptr = list_ptr;
  serv_Client *client = *list_ptr;
  while (client) {
    if (client->pid == pid) {
      *prev_ptr = client->next;
      return client;
    }
    prev_ptr = &((*prev_ptr)->next);
    client = client->next;
  }
  return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2a76
movq -0x28(%rbp), %rax
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x2a59
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2a7e
movq -0x20(%rbp), %rax
movq (%rax), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x2a2e
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_connected_clients
static unsigned serv_connected_clients(const serv_Client *c) {
  unsigned count = 0;
  while (c) {
    if (c->socket != -1) {
      count++;
    }
    c = c->next;
  }
  return count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x2ac7
movq -0x8(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
je 0x2ab9
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x2a9f
movl -0xc(%rbp), %eax
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_find_client_by_socket
static serv_Client *serv_find_client_by_socket(serv_Client *l, int socket) {
  assert(socket >= 0);
  while (l) {
    if (l->socket == socket) {
      return l;
    }
    l = l->next;
  }
  return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x2ae7
jmp 0x2b06
leaq 0x1bef(%rip), %rdi      # 0x46dd
leaq 0x16be(%rip), %rsi      # 0x41b3
movl $0x18f, %edx            # imm = 0x18F
leaq 0x1be8(%rip), %rcx      # 0x46e9
callq 0x10b0
jmp 0x2b08
cmpq $0x0, -0x10(%rbp)
je 0x2b33
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x2b25
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2b3b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x2b08
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_recv
static ClientMessage serv_recv(int fd) {
  ClientMessage msg;

  if (read_exact(fd, &msg, sizeof msg) == -1) {
    serv_print_errno("read");
    serv_panic();
  }

  return msg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %esi, %eax
movq %rdi, %rsi
movq %rsi, %rdi
movq %rdi, -0x10(%rbp)
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %edi
movl $0x18, %edx
callq 0x1830
cmpl $-0x1, %eax
jne 0x2b8a
leaq 0x1ba5(%rip), %rdi      # 0x4725
callq 0x1c90
callq 0x2830
movq -0x10(%rbp), %rax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_handle_request
static void serv_handle_request(
    const ClientMessage *req,
    serv_Client **first_client_ptr, // in/out
    size_t *client_count_ptr, // in/out
    serv_Client *sender) {

  switch (req->type) {
  case ClientMessageType_STOP_ALL_REQUEST:
    serv_handle_stop_all_request(*first_client_ptr, sender);
    break;
  case ClientMessageType_STOP_SERVER_ONLY_REQUEST:
    serv_handle_stop_server_only_request();
    break;
  case ClientMessageType_KILL_ALL_REQUEST:
    serv_handle_kill_all_request(req, *first_client_ptr, sender);
    break;
  case ClientMessageType_FORK_REQUEST:
    serv_handle_fork_request(req, first_client_ptr, client_count_ptr, sender);
    break;
  case ClientMessageType_EVAL_REQUEST:
    serv_handle_eval_request(req, sender);
    break;
  default:
    serv_print_error("Bad message type");
    serv_panic();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x28(%rbp)
subq $0x4, %rax
ja 0x2c2e
movq -0x28(%rbp), %rax
leaq 0x1554(%rip), %rcx      # 0x4128
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x2c50
callq 0x2d20
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x2d30
jmp 0x2c41
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x2de0
jmp 0x2c41
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3350
jmp 0x2c41
leaq 0x1af5(%rip), %rdi      # 0x472a
movb $0x0, %al
callq 0x2850
callq 0x2830
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_handle_stop_all_request
__attribute__((noreturn))
static void serv_handle_stop_all_request(
    serv_Client *first_client,
    serv_Client *sender_client) {
  serv_DEBUG("STOP_ALL_REQUEST received\n");

  if (!sender_client->main) {
    // unfortunately we can't use wait(2) with our parent process
    serv_print_error(
      "Deadlock detected!\n"
      "Some libforks functions must be called from the process "
      "that started the fork server."
    );
    serv_panic();
  }

  // we don’t care about SIGCHLD anymore
  serv_uninstall_signal_handler(SIGCHLD);

  // We could send all the signals first and then wait
  // for termination. It’s a bit more complex but it
  // could be significantly faster.

  for (serv_Client *c = first_client; c; c = c->next) {
    if (c->pid != sender_client->pid) {
      serv_DEBUG("sending SIGTERM to %d\n", (int)c->pid);
      if (kill(c->pid, SIGTERM) == -1) {
        if (errno != ESRCH) {
          // ESRCH is normal if the process just exited for some
          // other reason.
          serv_print_errno("kill");
          serv_panic();
        }
      } else {
        serv_DEBUG("waiting for %d\n", (int)c->pid);
        int status;
        if (waitpid(c->pid, &status, 0) == -1) {
          serv_print_errno("waitpid");
          serv_panic();
        }
      }
    }
  }

  serv_DEBUG("all children exited, goodbye!\n");
  exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
testb $0x1, 0x4(%rax)
jne 0x2c7d
leaq 0x1aca(%rip), %rdi      # 0x473b
movb $0x0, %al
callq 0x2850
callq 0x2830
movl $0x11, %edi
callq 0x33b0
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x2d14
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x2d01
movq -0x18(%rbp), %rax
movl (%rax), %edi
movl $0xf, %esi
callq 0x1160
cmpl $-0x1, %eax
jne 0x2cd6
callq 0x1050
cmpl $0x3, (%rax)
je 0x2cd4
leaq 0x1ada(%rip), %rdi      # 0x47a4
callq 0x1c90
callq 0x2830
jmp 0x2cff
movq -0x18(%rbp), %rax
movl (%rax), %edi
leaq -0x1c(%rbp), %rsi
xorl %edx, %edx
callq 0x11a0
cmpl $-0x1, %eax
jne 0x2cfd
leaq 0x1ab6(%rip), %rdi      # 0x47a9
callq 0x1c90
callq 0x2830
jmp 0x2cff
jmp 0x2d01
jmp 0x2d03
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x2c8f
xorl %edi, %edi
callq 0x11d0
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_handle_kill_all_request
static void serv_handle_kill_all_request(
    const ClientMessage *req,
    serv_Client *first_client,
    serv_Client *sender) {
  serv_DEBUG("KILL_ALL_REQUEST received\n");

  {
    serv_Client *c = first_client;
    while (c) {
      if (c != sender) { // don’t kill the sender!
        if (kill(c->pid, req->u.kill_all_request.signal) == -1) {
          if (errno == ESRCH) {
            // The process has just exited for some other reason.
          } else {
            serv_print_errno("kill");
            serv_panic();
          }
        }
      }

      c = c->next;
    }
  }

  ServerMessage res = {
    .type = ServerMessageType_KILL_SUCCESS,
  };
  serv_send(sender->socket, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x2da2
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x2d94
movq -0x20(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movl (%rax), %esi
callq 0x1160
cmpl $-0x1, %eax
jne 0x2d92
callq 0x1050
cmpl $0x3, (%rax)
jne 0x2d7f
jmp 0x2d90
leaq 0x1a1e(%rip), %rdi      # 0x47a4
callq 0x1c90
callq 0x2830
jmp 0x2d92
jmp 0x2d94
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x2d4c
movq 0x13c7(%rip), %rax      # 0x4170
movq %rax, -0x2c(%rbp)
movl 0x13c5(%rip), %eax      # 0x4178
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x2c(%rbp), %rax
movq %rax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x3c(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x3410
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_handle_eval_request
static void serv_handle_eval_request(
    const ClientMessage *req,
    const serv_Client *sender) {
  serv_DEBUG("EVAL_REQUEST received\n");

  req->u.eval_request.function();

  ServerMessage res = {
    .type = ServerMessageType_EVAL_SUCCESS,
  };
  serv_send(sender->socket, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
callq *(%rax)
movq 0xe1b(%rip), %rax       # 0x4188
movq %rax, -0x1c(%rbp)
movl 0xe19(%rip), %eax       # 0x4190
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x1c(%rbp), %rax
movq %rax, -0x2c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x2c(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x3410
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_uninstall_signal_handler
static void serv_uninstall_signal_handler(int signal) {
  struct sigaction sa;
  sa.sa_handler = SIG_DFL;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  if (sigaction(signal, &sa, NULL) == -1) {
    serv_print_errno(NULL);
    serv_panic();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl %edi, -0x4(%rbp)
movq $0x0, -0xa0(%rbp)
movl $0x0, -0x18(%rbp)
leaq -0xa0(%rbp), %rdi
addq $0x8, %rdi
callq 0x1130
movl -0x4(%rbp), %edi
leaq -0xa0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x1070
cmpl $-0x1, %eax
jne 0x3406
xorl %eax, %eax
movl %eax, %edi
callq 0x1c90
callq 0x2830
addq $0xa0, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/motet-a[P]libforks/libforks.c
// Function: serv_send_fds
static void serv_send_fds(
    int fd,
    ServerMessage msg,
    int *fds,
    size_t fd_count) {
  int write_res = libforks_write_socket_fds(
    fd,
    &msg, sizeof msg,
    fds, fd_count
  );
  if (write_res == -1) {
    serv_print_errno("sendmsg");
    serv_panic();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rsi, -0x1c(%rbp)
movl %edx, -0x14(%rbp)
movq -0x1c(%rbp), %rax
movq %rax, -0xc(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl %edi, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl -0x20(%rbp), %edi
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
leaq -0xc(%rbp), %rsi
movl $0xc, %edx
callq 0x18a0
movl %eax, -0x34(%rbp)
cmpl $-0x1, -0x34(%rbp)
jne 0x34bb
leaq 0x130c(%rip), %rdi      # 0x47bd
callq 0x1c90
callq 0x2830
addq $0x40, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/blocksplitter.c
// Function: AddSorted
static void AddSorted(size_t value, size_t** out, size_t* outsize) {
  size_t i;
  ZOPFLI_APPEND_DATA(value, out, outsize);
  if (*outsize > 0) {
    for (i = 0; i < *outsize - 1; i++) {
      if ((*out)[i] > value) {
        size_t j;
        for (j = *outsize - 1; j > i; j--) {
          (*out)[j] = (*out)[j - 1];
        }
        (*out)[i] = value;
        break;
      }
    }
  }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x1a6a
movq 0x20(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x1a3c
movl $0x8, %edi
callq 0x1120
movq %rax, 0x8(%rsp)
jmp 0x1a5d
movq 0x28(%rsp), %rax
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax), %rsi
shlq %rsi
shlq $0x3, %rsi
callq 0x1140
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x20(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
cmpq $0x0, (%rax)
jbe 0x1b5e
movq $0x0, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1b5c
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpq 0x30(%rsp), %rax
jbe 0x1b47
movq 0x20(%rsp), %rax
movq (%rax), %rax
subq $0x1, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
jbe 0x1b2f
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x1aed
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x1b5c
jmp 0x1b49
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0x1aaa
jmp 0x1b5e
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/blocksplitter.c
// Function: FindLargestSplittableBlock
static int FindLargestSplittableBlock(
    size_t llsize, const unsigned char* done,
    const size_t* splitpoints, size_t npoints,
    size_t* lstart, size_t* lend) {
  size_t longest = 0;
  int found = 0;
  size_t i;
  for (i = 0; i <= npoints; i++) {
    size_t start = i == 0 ? 0 : splitpoints[i - 1];
    size_t end = i == npoints ? llsize - 1 : splitpoints[i];
    if (!done[start] && end - start > longest) {
      *lstart = start;
      *lend = end;
      found = 1;
      longest = end - start;
    }
  }
  return found;
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq %rdx, -0x18(%rsp)
movq %rcx, -0x20(%rsp)
movq %r8, -0x28(%rsp)
movq %r9, -0x30(%rsp)
movq $0x0, -0x38(%rsp)
movl $0x0, -0x3c(%rsp)
movq $0x0, -0x48(%rsp)
movq -0x48(%rsp), %rax
cmpq -0x20(%rsp), %rax
ja 0x1c8a
cmpq $0x0, -0x48(%rsp)
jne 0x1bc9
xorl %eax, %eax
movq %rax, -0x60(%rsp)
jmp 0x1be0
movq -0x18(%rsp), %rax
movq -0x48(%rsp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rsp)
movq -0x60(%rsp), %rax
movq %rax, -0x50(%rsp)
movq -0x48(%rsp), %rax
cmpq -0x20(%rsp), %rax
jne 0x1c06
movq -0x8(%rsp), %rax
subq $0x1, %rax
movq %rax, -0x68(%rsp)
jmp 0x1c19
movq -0x18(%rsp), %rax
movq -0x48(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rsp)
movq -0x68(%rsp), %rax
movq %rax, -0x58(%rsp)
movq -0x10(%rsp), %rax
movq -0x50(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x1c75
movq -0x58(%rsp), %rax
subq -0x50(%rsp), %rax
cmpq -0x38(%rsp), %rax
jbe 0x1c75
movq -0x50(%rsp), %rcx
movq -0x28(%rsp), %rax
movq %rcx, (%rax)
movq -0x58(%rsp), %rcx
movq -0x30(%rsp), %rax
movq %rcx, (%rax)
movl $0x1, -0x3c(%rsp)
movq -0x58(%rsp), %rax
subq -0x50(%rsp), %rax
movq %rax, -0x38(%rsp)
jmp 0x1c77
movq -0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rsp)
jmp 0x1ba8
movl -0x3c(%rsp), %eax
retq
nop
// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/blocksplitter.c
// Function: ZopfliBlockSplitSimple
void ZopfliBlockSplitSimple(const unsigned char* in,
                            size_t instart, size_t inend,
                            size_t blocksize,
                            size_t** splitpoints, size_t* npoints) {
  size_t i = instart;
  while (i < inend) {
    ZOPFLI_APPEND_DATA(i, splitpoints, npoints);
    i += blocksize;
  }
  (void)in;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x30(%rsp), %rax
jae 0x22af
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x2273
movq 0x18(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x2245
movl $0x8, %edi
callq 0x1120
movq %rax, 0x8(%rsp)
jmp 0x2266
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq 0x18(%rsp), %rax
movq (%rax), %rsi
shlq %rsi
shlq $0x3, %rsi
callq 0x1140
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
addq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x21fc
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
nop
// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/cache.c
// Function: ZopfliInitCache
void ZopfliInitCache(size_t blocksize, ZopfliLongestMatchCache* lmc) {
  size_t i;
  lmc->length = (unsigned short*)malloc(sizeof(unsigned short) * blocksize);
  lmc->dist = (unsigned short*)malloc(sizeof(unsigned short) * blocksize);
  /* Rather large amount of memory. */
  lmc->sublen = (unsigned char*)malloc(ZOPFLI_CACHE_LENGTH * 3 * blocksize);

  /* length > 0 and dist 0 is invalid combination, which indicates on purpose
  that this cache value is not filled in yet. */
  for (i = 0; i < blocksize; i++) lmc->length[i] = 1;
  for (i = 0; i < blocksize; i++) lmc->dist[i] = 0;
  for (i = 0; i < ZOPFLI_CACHE_LENGTH * blocksize * 3; i++) lmc->sublen[i] = 0;
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq 0x10(%rsp), %rdi
shlq %rdi
callq 0x1120
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rdi
shlq %rdi
callq 0x1120
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
imulq $0x18, 0x10(%rsp), %rdi
callq 0x1120
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, (%rsp)
movq (%rsp), %rax
cmpq 0x10(%rsp), %rax
jae 0x2349
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rsp), %rcx
movw $0x1, (%rax,%rcx,2)
movq (%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
jmp 0x231e
movq $0x0, (%rsp)
movq (%rsp), %rax
cmpq 0x10(%rsp), %rax
jae 0x237d
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rsp), %rcx
movw $0x0, (%rax,%rcx,2)
movq (%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
jmp 0x2351
movq $0x0, (%rsp)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
shlq $0x3, %rcx
imulq $0x3, %rcx, %rcx
cmpq %rcx, %rax
jae 0x23ba
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq (%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
jmp 0x2385
addq $0x18, %rsp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/cache.c
// Function: ZopfliMaxCachedSublen
unsigned ZopfliMaxCachedSublen(const ZopfliLongestMatchCache* lmc,
                               size_t pos, size_t length) {
  unsigned char* cache;
#if ZOPFLI_CACHE_LENGTH == 0
  return 0;
#endif
  cache = &lmc->sublen[ZOPFLI_CACHE_LENGTH * pos * 3];
  (void)length;
  if (cache[1] == 0 && cache[2] == 0) return 0;  /* No sublen cached. */
  return cache[(ZOPFLI_CACHE_LENGTH - 1) * 3] + 3;
}

// Assembly:
movq %rdi, -0x10(%rsp)
movq %rsi, -0x18(%rsp)
movq %rdx, -0x20(%rsp)
movq -0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rsp), %rcx
shlq $0x3, %rcx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rsp)
movq -0x28(%rsp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x2643
movq -0x28(%rsp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x2643
movl $0x0, -0x4(%rsp)
jmp 0x2653
movq -0x28(%rsp), %rax
movzbl 0x15(%rax), %eax
addl $0x3, %eax
movl %eax, -0x4(%rsp)
movl -0x4(%rsp), %eax
retq
nopl (%rax,%rax)