#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*/ tp;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct forth_instance {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int st_pop(struct forth_instance *);
int /*<<< orphan*/ st_push(struct forth_instance *, int);
void openlistener(struct forth_instance *fi) {
  int tp, sd, port;
  struct sockaddr_in my_addr;
  port = st_pop(fi);
  if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    st_push(fi, (int)0);
    return;
  }
  setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &tp, sizeof(tp));
  my_addr.sin_family = AF_INET;
  my_addr.sin_port = htons(port);
  my_addr.sin_addr.s_addr = INADDR_ANY;
  memset(&(my_addr.sin_zero), 0, 8);
  if (bind(sd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
    st_push(fi, (int)0);
    return;
  }
  if (listen(sd, 15) == -1) {
    st_push(fi, (int)0);
    return;
  }
  st_push(fi, (int)sd);
}


x86 assembly (clang, -O0):
<openlistener>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <st_pop@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    11cd <openlistener+0x4d>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1090 <st_push@plt>
jmp    1280 <openlistener+0x100>
mov    -0x10(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    124e <openlistener+0xce>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1090 <st_push@plt>
jmp    1280 <openlistener+0x100>
mov    -0x10(%rbp),%edi
mov    $0xf,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    1274 <openlistener+0xf4>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1090 <st_push@plt>
jmp    1280 <openlistener+0x100>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1090 <st_push@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openlistener>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1060 <st_pop@plt>
mov    %eax,%ebx
mov    0x2e45(%rip),%r15
mov    (%r15),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     123a <openlistener+0xba>
mov    %eax,%ebp
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     124e <openlistener+0xce>
mov    %ebp,%edi
mov    $0xf,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
je     124e <openlistener+0xce>
mov    %r14,%rdi
mov    %ebp,%esi
jmp    1253 <openlistener+0xd3>
mov    %r14,%rdi
xor    %esi,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <st_push@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <st_push@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.forth_instance = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
define void @openlistener(%struct.forth_instance* %0) {
%2 = alloca %struct.forth_instance*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
store %struct.forth_instance* %0, %struct.forth_instance** %2
%7 = load %struct.forth_instance*, %struct.forth_instance** %2
%8 = call i32 @st_pop(%struct.forth_instance* %7)
store i32 %8, i32* %5
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load %struct.forth_instance*, %struct.forth_instance** %2
%15 = call i32 @st_push(%struct.forth_instance* %14, i32 0)
br label %49
16: ; preds = %1
%17 = load i32, i32* %4
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i32* %3, i32 4)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 3
store i32 %21, i32* %22
%23 = load i32, i32* %5
%24 = call i32 @htons(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%30 = call i32 @memset(i32* %29, i32 0, i32 8)
%31 = load i32, i32* %4
%32 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%33 = call i32 @bind(i32 %31, %struct.sockaddr* %32, i32 4)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %16
%36 = load %struct.forth_instance*, %struct.forth_instance** %2
%37 = call i32 @st_push(%struct.forth_instance* %36, i32 0)
br label %49
38: ; preds = %16
%39 = load i32, i32* %4
%40 = call i32 @listen(i32 %39, i32 15)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load %struct.forth_instance*, %struct.forth_instance** %2
%44 = call i32 @st_push(%struct.forth_instance* %43, i32 0)
br label %49
45: ; preds = %38
%46 = load %struct.forth_instance*, %struct.forth_instance** %2
%47 = load i32, i32* %4
%48 = call i32 @st_push(%struct.forth_instance* %46, i32 %47)
br label %49
49: ; preds = %45, %42, %35, %13
ret void
}

LLVM IR (-O2):
%struct.forth_instance = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
define void @openlistener(%struct.forth_instance* %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = tail call i32 @st_pop(%struct.forth_instance* %0)
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = tail call i32 @st_push(%struct.forth_instance* %0, i32 0)
br label %37
13: ; preds = %1
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_REUSEADDR
%16 = call i32 @setsockopt(i32 %9, i32 %14, i32 %15, i32* %2, i32 4)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %17, i32* %18
%19 = call i32 @htons(i32 %6)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%24 = call i32 @memset(i32* %23, i32 0, i32 8)
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @bind(i32 %9, %struct.sockaddr* %25, i32 4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %13
%29 = call i32 @st_push(%struct.forth_instance* %0, i32 0)
br label %37
30: ; preds = %13
%31 = call i32 @listen(i32 %9, i32 15)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @st_push(%struct.forth_instance* %0, i32 0)
br label %37
35: ; preds = %30
%36 = call i32 @st_push(%struct.forth_instance* %0, i32 %9)
br label %37
37: ; preds = %35, %33, %28, %11
ret void
}