// File: /workspace/github_c_makefile_star2_O0/inolen[P]gdb_server/./gdb_server.h
// Function: gdb_server_create_listen
static int gdb_server_create_listen(gdb_server_t *sv, int port) {
  int ret = 0;

  for (;;) {
    // create the socket to monitor for connections on
    sv->listen = socket(PF_INET, SOCK_STREAM, 0);
    if (sv->listen == INVALID_SOCKET) {
      GDB_SERVER_LOG("Failed to create gdb socket");
      ret = -1;
      break;
    }

    // enable reusing of the address / port
    int on = 1;
    if (setsockopt(sv->listen, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) ==
        SOCKET_ERROR) {
      GDB_SERVER_LOG("Failed to set socket options for gdb socket");
      ret = -1;
      break;
    }

    // bind the socket to an address / port
    struct sockaddr_in listen_addr_in = {};
    listen_addr_in.sin_family = AF_INET;
    listen_addr_in.sin_port = htons(port);
    listen_addr_in.sin_addr.s_addr = INADDR_ANY;

    const struct sockaddr *listen_addr =
        (const struct sockaddr *)&listen_addr_in;
    socklen_t listen_addr_in_len = sizeof(listen_addr_in);

    if (bind(sv->listen, listen_addr, listen_addr_in_len) == SOCKET_ERROR) {
      GDB_SERVER_LOG("Failed to bind gdb socket");
      ret = -1;
      break;
    }

    // start listening
    if (listen(sv->listen, 1) == SOCKET_ERROR) {
      GDB_SERVER_LOG("Failed to listen to gdb socket");
      ret = -1;
      break;
    }

    GDB_SERVER_LOG("GDB server started on localhost:%d", port);

    break;
  }

  // cleanup if necessary
  if (ret == -1) {
    shutdown(sv->listen, SHUT_RDWR);
    sv->listen = INVALID_SOCKET;
  }

  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x31e0
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
jne 0x7df4
leaq 0x3085(%rip), %rdi      # 0xae66
movb $0x0, %al
callq 0x30d0
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
jmp 0x7ee2
movl $0x1, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x14(%rbp), %rcx
movl $0x4, %r8d
callq 0x3070
cmpl $-0x1, %eax
jne 0x7e3a
leaq 0x305c(%rip), %rdi      # 0xae83
movb $0x0, %al
callq 0x30d0
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
jmp 0x7ee2
leaq -0x24(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3100
movw $0x2, -0x24(%rbp)
movl -0xc(%rbp), %eax
movzwl %ax, %edi
callq 0x30b0
movw %ax, -0x22(%rbp)
movl $0x0, -0x20(%rbp)
leaq -0x24(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x10, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x30(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x31a0
cmpl $-0x1, %eax
jne 0x7ea4
leaq 0x301c(%rip), %rdi      # 0xaeb0
movb $0x0, %al
callq 0x30d0
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
jmp 0x7ee2
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movl $0x1, %esi
callq 0x3170
cmpl $-0x1, %eax
jne 0x7ed1
leaq 0x300a(%rip), %rdi      # 0xaecb
movb $0x0, %al
callq 0x30d0
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
jmp 0x7ee2
movl -0xc(%rbp), %esi
leaq 0x3010(%rip), %rdi      # 0xaeeb
movb $0x0, %al
callq 0x30d0
cmpl $-0x1, -0x10(%rbp)
jne 0x7f04
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movl $0x2, %esi
callq 0x3090
movq -0x8(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movl -0x10(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)