#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ val;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ get_host_address(char *, struct sockaddr_in *, int /*<<< orphan*/ *);
scalar_t__ getsockname(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ ip2str(struct sockaddr_in *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ log_msg(char *, int, int, int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
unsigned short ntohs(int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int socket_listen(unsigned short *port, char *listenip, int queue) {
  int sfd = -1;
  struct sockaddr_in addr;
  int addrlen = sizeof(addr);
  int val = 1;
  if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    log_msg(
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/share.c",
        72, 1, errno, "can't create listener socket");
    goto failure;
  }
  if (port && *port) {
    if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)) <
        0)
      log_msg("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/"
              "share.c",
              78, 1, 0, "Warning: failed to set SO_REUSEADDR option on socket");
  }
  memset(&addr, 0, sizeof(addr));
  if (listenip != NULL) {
    if (get_host_address(listenip, &addr, NULL) < 0)
      log_msg("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/"
              "share.c",
              84, 1, 0, "can't resolve listen address '%s'", listenip);
  } else {
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
  }
  addr.sin_port = (port ? htons(*port) : 0);
  log_msg(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/share.c",
      91, 3, 0, "listening on %s", ip2str(&addr));
  if (bind(sfd, (struct sockaddr *)&addr, addrlen) < 0) {
    log_msg(
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/share.c",
        94, 1, errno, "listener bind failed");
    goto failure;
  }
  if (listen(sfd, queue) < 0) {
    log_msg(
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/share.c",
        99, 1, errno, "listen failed");
    goto failure;
  }
  if (port) {
    memset(&addr, 0, sizeof(addr));
    if (getsockname(sfd, (struct sockaddr *)&addr, (socklen_t *)&addrlen)) {
      log_msg("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/"
              "share.c",
              106, 0, errno, "can't get local port number");
      goto failure;
    }
    *port = ntohs(addr.sin_port);
  }
  return sfd;
failure:
  if (sfd != -1)
    close(sfd);
  return -1;
}


x86 assembly (clang, -O0):
<socket_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0xc,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    124a <socket_listen+0x7a>
mov    0x2d9c(%rip),%rax
mov    (%rax),%ecx
lea    0xdd3(%rip),%rdi
mov    $0x48,%esi
mov    $0x1,%edx
lea    0xe48(%rip),%r8
mov    $0x0,%al
call   1090 <log_msg@plt>
jmp    1496 <socket_listen+0x2c6>
cmpq   $0x0,-0x10(%rbp)
je     12b9 <socket_listen+0xe9>
mov    -0x10(%rbp),%rax
movzwl (%rax),%eax
cmp    $0x0,%eax
je     12b9 <socket_listen+0xe9>
mov    -0x20(%rbp),%edi
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
mov    0x2d40(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12b4 <socket_listen+0xe4>
lea    0xd66(%rip),%rdi
mov    $0x4e,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
lea    0xdf6(%rip),%r8
mov    $0x0,%al
call   1090 <log_msg@plt>
jmp    12b9 <socket_listen+0xe9>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
je     1319 <socket_listen+0x149>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <get_host_address@plt>
cmp    $0x0,%rax
jge    1314 <socket_listen+0x144>
mov    -0x18(%rbp),%r9
lea    0xd06(%rip),%rdi
mov    $0x54,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
lea    0xdcb(%rip),%r8
mov    $0x0,%al
call   1090 <log_msg@plt>
jmp    1336 <socket_listen+0x166>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1355 <socket_listen+0x185>
mov    -0x10(%rbp),%rax
movzwl (%rax),%edi
call   1040 <htons@plt>
mov    %eax,-0x3c(%rbp)
jmp    135f <socket_listen+0x18f>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    135f <socket_listen+0x18f>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
call   1080 <ip2str@plt>
mov    %eax,%r9d
lea    0xc88(%rip),%rdi
mov    $0x5b,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
lea    0xd6f(%rip),%r8
mov    $0x0,%al
call   1090 <log_msg@plt>
mov    -0x20(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    13d8 <socket_listen+0x208>
mov    0x2c0e(%rip),%rax
mov    (%rax),%ecx
lea    0xc45(%rip),%rdi
mov    $0x5e,%esi
mov    $0x1,%edx
lea    0xd3e(%rip),%r8
mov    $0x0,%al
call   1090 <log_msg@plt>
jmp    1496 <socket_listen+0x2c6>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    141a <socket_listen+0x24a>
mov    0x2bcc(%rip),%rax
mov    (%rax),%ecx
lea    0xc03(%rip),%rdi
mov    $0x63,%esi
mov    $0x1,%edx
lea    0xd11(%rip),%r8
mov    $0x0,%al
call   1090 <log_msg@plt>
jmp    1496 <socket_listen+0x2c6>
cmpq   $0x0,-0x10(%rbp)
je     148b <socket_listen+0x2bb>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10e0 <getsockname@plt>
cmp    $0x0,%rax
je     1479 <socket_listen+0x2a9>
mov    0x2b6a(%rip),%rax
mov    (%rax),%ecx
lea    0xba1(%rip),%rdi
mov    $0x6a,%esi
xor    %edx,%edx
lea    0xcc0(%rip),%r8
mov    $0x0,%al
call   1090 <log_msg@plt>
jmp    1496 <socket_listen+0x2c6>
mov    -0x30(%rbp),%edi
call   10c0 <ntohs@plt>
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14af <socket_listen+0x2df>
cmpl   $0xffffffff,-0x20(%rbp)
je     14a8 <socket_listen+0x2d8>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_listen>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%r14
movl   $0xc,0x1c(%rsp)
movl   $0x1,0x18(%rsp)
mov    0x2de4(%rip),%r12
mov    (%r12),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     12ce <socket_listen+0xfe>
test   %r14,%r14
je     1270 <socket_listen+0xa0>
cmpw   $0x0,(%r14)
je     1270 <socket_listen+0xa0>
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
lea    0x18(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    1270 <socket_listen+0xa0>
lea    0xdaa(%rip),%rdi
lea    0xe46(%rip),%r8
mov    $0x4e,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1090 <log_msg@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
test   %rbp,%rbp
je     1304 <socket_listen+0x134>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
xor    %edx,%edx
call   10b0 <get_host_address@plt>
test   %rax,%rax
jns    12be <socket_listen+0xee>
lea    0xd5f(%rip),%rdi
lea    0xe30(%rip),%r8
mov    $0x54,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %rbp,%r9
xor    %eax,%eax
call   1090 <log_msg@plt>
test   %r14,%r14
je     1323 <socket_listen+0x153>
movzwl (%r14),%edi
call   1040 <htons@plt>
jmp    1325 <socket_listen+0x155>
mov    0x2ceb(%rip),%rax
mov    (%rax),%ecx
lea    0xd22(%rip),%rdi
lea    0xda1(%rip),%r8
mov    $0x48,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1090 <log_msg@plt>
cmp    $0xffffffff,%ebx
jne    1418 <socket_listen+0x248>
jmp    141f <socket_listen+0x24f>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
test   %r14,%r14
jne    12c3 <socket_listen+0xf3>
xor    %eax,%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <ip2str@plt>
lea    0xcc3(%rip),%rdi
lea    0xdb6(%rip),%r8
mov    $0x5b,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
mov    %eax,%r9d
xor    %eax,%eax
call   1090 <log_msg@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     13d2 <socket_listen+0x202>
mov    %ebx,%edi
mov    %r15d,%esi
call   10a0 <listen@plt>
test   %rax,%rax
js     13f0 <socket_listen+0x220>
test   %r14,%r14
je     1424 <socket_listen+0x254>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
lea    0x1c(%rsp),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
call   10e0 <getsockname@plt>
test   %rax,%rax
je     1433 <socket_listen+0x263>
mov    0x2c07(%rip),%rax
mov    (%rax),%ecx
lea    0xc3e(%rip),%rdi
lea    0xd64(%rip),%r8
mov    $0x6a,%esi
xor    %edx,%edx
jmp    1411 <socket_listen+0x241>
mov    0x2be7(%rip),%rax
mov    (%rax),%ecx
lea    0xc1e(%rip),%rdi
lea    0xd21(%rip),%r8
mov    $0x5e,%esi
jmp    140c <socket_listen+0x23c>
mov    0x2bc9(%rip),%rax
mov    (%rax),%ecx
lea    0xc00(%rip),%rdi
lea    0xd18(%rip),%r8
mov    $0x63,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1090 <log_msg@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%edi
call   10c0 <ntohs@plt>
mov    %ax,(%r14)
jmp    1424 <socket_listen+0x254>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/share.c\00"
@errno = global i32 0
@.str.1 = [29 x i8] c"can't create listener socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [53 x i8] c"Warning: failed to set SO_REUSEADDR option on socket\00"
@.str.3 = [34 x i8] c"can't resolve listen address '%s'\00"
@INADDR_ANY = global i32 0
@.str.4 = [16 x i8] c"listening on %s\00"
@.str.5 = [21 x i8] c"listener bind failed\00"
@.str.6 = [14 x i8] c"listen failed\00"
@.str.7 = [28 x i8] c"can't get local port number\00"
define i32 @socket_listen(i16* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i16*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
store i16* %0, i16** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 -1, i32* %8
store i32 12, i32* %10
store i32 1, i32* %11
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i32, i32* @errno
%18 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 72, i32 1, i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %104
19: ; preds = %3
%20 = load i16*, i16** %5
%21 = icmp ne i16* %20, null
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = load i16*, i16** %5
%24 = load i16, i16* %23
%25 = zext i16 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %22
%28 = load i32, i32* %8
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_REUSEADDR
%31 = bitcast i32* %11 to i8*
%32 = call i64 @setsockopt(i32 %28, i32 %29, i32 %30, i8* %31, i32 4)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 78, i32 1, i32 0, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %27
br label %37
37: ; preds = %36, %22, %19
%38 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = load i8*, i8** %6
%43 = call i64 @get_host_address(i8* %42, %struct.sockaddr_in* %9, i32* null)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i8*, i8** %6
%47 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 84, i32 1, i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %45, %41
br label %56
49: ; preds = %37
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i32, i32* @INADDR_ANY
%53 = call i32 @htonl(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
store i32 %53, i32* %55
br label %56
56: ; preds = %49, %48
%57 = load i16*, i16** %5
%58 = icmp ne i16* %57, null
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = load i16*, i16** %5
%61 = load i16, i16* %60
%62 = call i32 @htons(i16 zeroext %61)
br label %64
63: ; preds = %56
br label %64
64: ; preds = %63, %59
%65 = phi i32 [ %62, %59 ], [ 0, %63 ]
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %65, i32* %66
%67 = call i32 @ip2str(%struct.sockaddr_in* %9)
%68 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 91, i32 3, i32 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %8
%70 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%71 = load i32, i32* %10
%72 = call i64 @bind(i32 %69, %struct.sockaddr* %70, i32 %71)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %64
%75 = load i32, i32* @errno
%76 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 94, i32 1, i32 %75, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %104
77: ; preds = %64
%78 = load i32, i32* %8
%79 = load i32, i32* %7
%80 = call i64 @listen(i32 %78, i32 %79)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %77
%83 = load i32, i32* @errno
%84 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 99, i32 1, i32 %83, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %104
85: ; preds = %77
%86 = load i16*, i16** %5
%87 = icmp ne i16* %86, null
br i1 %87, label %88, label %102
88: ; preds = %85
%89 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%90 = load i32, i32* %8
%91 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%92 = call i64 @getsockname(i32 %90, %struct.sockaddr* %91, i32* %10)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %88
%95 = load i32, i32* @errno
%96 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 106, i32 0, i32 %95, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %104
97: ; preds = %88
%98 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%99 = load i32, i32* %98
%100 = call zeroext i16 @ntohs(i32 %99)
%101 = load i16*, i16** %5
store i16 %100, i16* %101
br label %102
102: ; preds = %97, %85
%103 = load i32, i32* %8
store i32 %103, i32* %4
br label %111
104: ; preds = %94, %82, %74, %16
%105 = load i32, i32* %8
%106 = icmp ne i32 %105, -1
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = load i32, i32* %8
%109 = call i32 @close(i32 %108)
br label %110
110: ; preds = %107, %104
store i32 -1, i32* %4
br label %111
111: ; preds = %110, %102
%112 = load i32, i32* %4
ret i32 %112
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bierdaci/egui/refs/heads/master/msg/share.c\00"
@errno = global i32 0
@.str.1 = [29 x i8] c"can't create listener socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [53 x i8] c"Warning: failed to set SO_REUSEADDR option on socket\00"
@.str.3 = [34 x i8] c"can't resolve listen address '%s'\00"
@INADDR_ANY = global i32 0
@.str.4 = [16 x i8] c"listening on %s\00"
@.str.5 = [21 x i8] c"listener bind failed\00"
@.str.6 = [14 x i8] c"listen failed\00"
@.str.7 = [28 x i8] c"can't get local port number\00"
define i32 @socket_listen(i16* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%9 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %72, label %14
14: ; preds = %3
%15 = icmp eq i16* %0, null
br i1 %15, label %26, label %16
16: ; preds = %14
%17 = load i16, i16* %0
%18 = icmp eq i16 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %16
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_REUSEADDR
%22 = call i64 @setsockopt(i32 %12, i32 %20, i32 %21, i8* %9, i32 4)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 78, i32 1, i32 0, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %19, %24, %16, %14
%27 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%28 = icmp eq i8* %1, null
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = call i64 @get_host_address(i8* %1, %struct.sockaddr_in* %4, i32* null)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 84, i32 1, i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %40
34: ; preds = %26
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %35, i32* %36
%37 = load i32, i32* @INADDR_ANY
%38 = call i32 @htonl(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %38, i32* %39
br label %40
40: ; preds = %29, %32, %34
br i1 %15, label %44, label %41
41: ; preds = %40
%42 = load i16, i16* %0
%43 = call i32 @htons(i16 zeroext %42)
br label %44
44: ; preds = %40, %41
%45 = phi i32 [ %43, %41 ], [ 0, %40 ]
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %45, i32* %46
%47 = call i32 @ip2str(%struct.sockaddr_in* %4)
%48 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 91, i32 3, i32 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%50 = call i64 @bind(i32 %12, %struct.sockaddr* %49, i32 12)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = load i32, i32* @errno
%54 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 94, i32 1, i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %76
55: ; preds = %44
%56 = call i64 @listen(i32 %12, i32 %2)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* @errno
%60 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 99, i32 1, i32 %59, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %76
61: ; preds = %55
br i1 %15, label %78, label %62
62: ; preds = %61
%63 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%64 = call i64 @getsockname(i32 %12, %struct.sockaddr* %49, i32* %5)
%65 = icmp eq i64 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %62
%67 = load i32, i32* @errno
%68 = call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 106, i32 0, i32 %67, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %76
69: ; preds = %62
%70 = load i32, i32* %46
%71 = call zeroext i16 @ntohs(i32 %70)
store i16 %71, i16* %0
br label %78
72: ; preds = %3
%73 = load i32, i32* @errno
%74 = tail call i32 (i8*, i32, i32, i32, i8*, ...) @log_msg(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 72, i32 1, i32 %73, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%75 = icmp eq i32 %12, -1
br i1 %75, label %78, label %76
76: ; preds = %52, %58, %66, %72
%77 = call i32 @close(i32 %12)
br label %78
78: ; preds = %72, %76, %61, %69
%79 = phi i32 [ %12, %69 ], [ %12, %61 ], [ -1, %76 ], [ -1, %72 ]
ret i32 %79
}