#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 */
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 socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SIGCHLD;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ child(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int listen(int, int);
scalar_t__ memdlopen_init();
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *);
int main(void) {
  struct sockaddr_in addr;
  int c, enable, s;
  socklen_t len;
  if (memdlopen_init() != 0)
    exit(1);
  if (signal(SIGCHLD, SIG_IGN) == SIG_ERR)
    err(1, "signal");
  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1)
    err(1, "socket");
  enable = 1;
  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) == -1)
    err(1, "setsockopt(SO_REUSEADDR)");
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = INADDR_ANY;
  addr.sin_port = htons(1234);
  if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) == -1)
    err(1, "bind");
  if (listen(s, 1) == -1)
    err(1, "listen");
  len = sizeof(addr);
  while (1) {
    c = accept(s, (struct sockaddr *)&addr, &len);
    if (c == -1) {
      warn("accept");
      continue;
    }
    child(s, c);
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <memdlopen_init@plt>
cmp    $0x0,%rax
je     11ea <main+0x2a>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
mov    0x2da8(%rip),%rcx
cmp    (%rcx),%rax
jne    1222 <main+0x62>
mov    $0x1,%edi
lea    0xde3(%rip),%rsi
call   1090 <err@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1259 <main+0x99>
mov    $0x1,%edi
lea    0xdb3(%rip),%rsi
call   1090 <err@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    129e <main+0xde>
mov    $0x1,%edi
lea    0xd75(%rip),%rsi
call   1090 <err@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x4d2,%edi
call   1070 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12ee <main+0x12e>
mov    $0x1,%edi
lea    0xd3e(%rip),%rsi
call   1090 <err@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1315 <main+0x155>
mov    $0x1,%edi
lea    0xd1c(%rip),%rsi
call   1090 <err@plt>
movl   $0xc,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    134a <main+0x18a>
lea    0xcf3(%rip),%rdi
call   1040 <warn@plt>
jmp    131c <main+0x15c>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <child@plt>
jmp    131c <main+0x15c>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1050 <memdlopen_init@plt>
test   %rax,%rax
jne    1335 <main+0x175>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%rax
jne    120f <main+0x4f>
lea    0xdfb(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x2dca(%rip),%r14
mov    (%r14),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1241 <main+0x81>
lea    0xdd0(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
movl   $0x1,0x4(%rsp)
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
mov    0x2d4f(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1283 <main+0xc3>
lea    0xd95(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x4d2,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12cc <main+0x10c>
lea    0xd65(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12ee <main+0x12e>
lea    0xd48(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
movl   $0xc,(%rsp)
lea    0x8(%rsp),%r14
mov    %rsp,%r15
lea    0xd2f(%rip),%r12
jmp    1319 <main+0x159>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <child@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10c0 <accept@plt>
cmp    $0xffffffff,%eax
jne    1310 <main+0x150>
mov    %r12,%rdi
call   1040 <warn@plt>
jmp    1319 <main+0x159>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIG_ERR = global i64 0
@.str = [7 x i8] c"signal\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [25 x i8] c"setsockopt(SO_REUSEADDR)\00"
@INADDR_ANY = global i32 0
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [7 x i8] c"accept\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 (...) @memdlopen_init()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* @SIGCHLD
%13 = load i32, i32* @SIG_IGN
%14 = call i64 @signal(i32 %12, i32 %13)
%15 = load i64, i64* @SIG_ERR
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
store i32 1, i32* %4
%28 = load i32, i32* %5
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_REUSEADDR
%31 = call i32 @setsockopt(i32 %28, i32 %29, i32 %30, i32* %4, i32 4)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @err(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %27
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %36, i32* %37
%38 = load i32, i32* @INADDR_ANY
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i32 %38, i32* %40
%41 = call i32 @htons(i32 1234)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %41, i32* %42
%43 = load i32, i32* %5
%44 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%45 = call i32 @bind(i32 %43, %struct.sockaddr* %44, i32 12)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %35
%48 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %35
%50 = load i32, i32* %5
%51 = call i32 @listen(i32 %50, i32 1)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
store i32 12, i32* %6
br label %56
56: ; preds = %55, %62, %64
%57 = load i32, i32* %5
%58 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%59 = call i32 @accept(i32 %57, %struct.sockaddr* %58, i32* %6)
store i32 %59, i32* %3
%60 = load i32, i32* %3
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %56
64: ; preds = %56
%65 = load i32, i32* %5
%66 = load i32, i32* %3
%67 = call i32 @child(i32 %65, i32 %66)
br label %56
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIG_ERR = global i64 0
@.str = [7 x i8] c"signal\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [25 x i8] c"setsockopt(SO_REUSEADDR)\00"
@INADDR_ANY = global i32 0
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [7 x i8] c"accept\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i64 (...) @memdlopen_init()
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* @SIGCHLD
%13 = load i32, i32* @SIG_IGN
%14 = tail call i64 @signal(i32 %12, i32 %13)
%15 = load i64, i64* @SIG_ERR
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = tail call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
store i32 1, i32* %2
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_REUSEADDR
%29 = call i32 @setsockopt(i32 %22, i32 %27, i32 %28, i32* %2, i32 4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @err(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %36, i32* %37
%38 = call i32 @htons(i32 1234)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %38, i32* %39
%40 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%41 = call i32 @bind(i32 %22, %struct.sockaddr* %40, i32 12)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %33
%44 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %33
%46 = call i32 @listen(i32 %22, i32 1)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
store i32 12, i32* %3
br label %51
51: ; preds = %56, %50
%52 = call i32 @accept(i32 %22, %struct.sockaddr* %40, i32* %3)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %57
br label %51
57: ; preds = %51
%58 = call i32 @child(i32 %22, i32 %52)
br label %56
}