#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*/ their;
struct sockaddr_storage {
  int dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ my;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ TCP_NODELAY;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(unsigned int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ process_ctr_msg(int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void s_run(unsigned int port) {
  int fd;
  struct sockaddr_in my;
  int flag = 1;
  fd = socket(PF_INET, SOCK_STREAM, 0);
  if (fd < 0) {
    perror("Socket open failed");
    return;
  }
  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(int)) ==
      -1) {
    perror("setsockopt");
    exit(1);
  }
  my.sin_addr.s_addr = INADDR_ANY;
  my.sin_family = AF_INET;
  my.sin_port = htons(port);
  if (bind(fd, (struct sockaddr *)&my, sizeof(my)) != 0) {
    perror("Socket bind failed");
    return;
  }
  if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) ==
      -1) {
    printf("Cannot disable Nagle! Exit\n");
    exit(1);
  }
  if (listen(fd, 50) == -1) {
    perror("Cannot listen");
    return;
  }
  while (1) {
    struct sockaddr_storage their;
    socklen_t sz = sizeof(their);
    int confd = accept(fd, (struct sockaddr *)&their, &sz);
    if (confd == -1) {
      perror("cannot accept connection");
      return;
    }
    if (setsockopt(confd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
                   sizeof(int)) == -1) {
      printf("Cannot disable Nagle! Exit\n");
      exit(1);
    }
    process_ctr_msg(confd);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<s_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11e9 <s_run+0x49>
lea    0xe21(%rip),%rdi
call   1090 <perror@plt>
jmp    136f <s_run+0x1cf>
mov    -0x8(%rbp),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    122c <s_run+0x8c>
lea    0xdf6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
je     127b <s_run+0xdb>
lea    0xdad(%rip),%rdi
call   1090 <perror@plt>
jmp    136f <s_run+0x1cf>
mov    -0x8(%rbp),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12be <s_run+0x11e>
lea    0xd82(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x32,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    12e5 <s_run+0x145>
lea    0xd72(%rip),%rdi
call   1090 <perror@plt>
jmp    136f <s_run+0x1cf>
jmp    12ea <s_run+0x14a>
movl   $0x4,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    131f <s_run+0x17f>
lea    0xd46(%rip),%rdi
call   1090 <perror@plt>
jmp    136f <s_run+0x1cf>
mov    -0x28(%rbp),%edi
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
mov    0x2cae(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1362 <s_run+0x1c2>
lea    0xcde(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%edi
call   1060 <process_ctr_msg@plt>
jmp    12ea <s_run+0x14a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
movl   $0x1,0xc(%rsp)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
jns    11ef <s_run+0x4f>
lea    0xe24(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <perror@plt>
mov    %eax,%r14d
mov    0x2def(%rip),%rax
mov    (%rax),%esi
mov    0x2da6(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1367 <s_run+0x1c7>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
jne    12aa <s_run+0x10a>
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    0x2d74(%rip),%r13
mov    0x0(%r13),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1351 <s_run+0x1b1>
mov    %r14d,%edi
mov    $0x32,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    12b6 <s_run+0x116>
lea    0xd8c(%rip),%rdi
jmp    133d <s_run+0x19d>
lea    0xd6d(%rip),%rdi
jmp    133d <s_run+0x19d>
movl   $0x4,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   10a0 <accept@plt>
cmp    $0xffffffff,%eax
je     1336 <s_run+0x196>
mov    %eax,%ebx
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
mov    0x0(%r13),%edx
mov    %ebx,%edi
mov    %r15,%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1351 <s_run+0x1b1>
mov    %ebx,%edi
call   1060 <process_ctr_msg@plt>
movl   $0x4,0x8(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
call   10a0 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    12f0 <s_run+0x150>
lea    0xd02(%rip),%rdi
call   1090 <perror@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd00(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xca5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [19 x i8] c"Socket open failed\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
@.str.2 = [19 x i8] c"Socket bind failed\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.3 = [28 x i8] c"Cannot disable Nagle! Exit\0A\00"
@.str.4 = [14 x i8] c"Cannot listen\00"
@.str.5 = [25 x i8] c"cannot accept connection\00"
define void @s_run(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %5
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %79
16: ; preds = %1
%17 = load i32, i32* %3
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = bitcast i32* %5 to i8*
%21 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i8* %20, i32 4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = load i32, i32* @INADDR_ANY
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %30, i32* %31
%32 = load i32, i32* %2
%33 = call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* %3
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%37 = call i64 @bind(i32 %35, %struct.sockaddr* %36, i32 12)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %26
%40 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %79
41: ; preds = %26
%42 = load i32, i32* %3
%43 = load i32, i32* @IPPROTO_TCP
%44 = load i32, i32* @TCP_NODELAY
%45 = bitcast i32* %5 to i8*
%46 = call i32 @setsockopt(i32 %42, i32 %43, i32 %44, i8* %45, i32 4)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %41
%52 = load i32, i32* %3
%53 = call i32 @listen(i32 %52, i32 50)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %79
57: ; preds = %51
br label %58
58: ; preds = %57, %76
store i32 4, i32* %7
%59 = load i32, i32* %3
%60 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%61 = call i32 @accept(i32 %59, %struct.sockaddr* %60, i32* %7)
store i32 %61, i32* %8
%62 = load i32, i32* %8
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %58
%65 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %79
66: ; preds = %58
%67 = load i32, i32* %8
%68 = load i32, i32* @IPPROTO_TCP
%69 = load i32, i32* @TCP_NODELAY
%70 = bitcast i32* %5 to i8*
%71 = call i32 @setsockopt(i32 %67, i32 %68, i32 %69, i8* %70, i32 4)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %66
%74 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %66
%77 = load i32, i32* %8
%78 = call i32 @process_ctr_msg(i32 %77)
br label %58
79: ; preds = %64, %55, %39, %14
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [19 x i8] c"Socket open failed\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [11 x i8] c"setsockopt\00"
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
@.str.2 = [19 x i8] c"Socket bind failed\00"
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@.str.4 = [14 x i8] c"Cannot listen\00"
@.str.5 = [25 x i8] c"cannot accept connection\00"
@str.6 = [27 x i8] c"Cannot disable Nagle! Exit\00"
define void @s_run(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca %struct.sockaddr_storage
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %68
14: ; preds = %1
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_REUSEADDR
%17 = call i32 @setsockopt(i32 %10, i32 %15, i32 %16, i8* %7, i32 4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %25, i32* %26
%27 = call i32 @htons(i32 %0)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%30 = call i64 @bind(i32 %10, %struct.sockaddr* %29, i32 12)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %22
%33 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %68
34: ; preds = %22
%35 = load i32, i32* @IPPROTO_TCP
%36 = load i32, i32* @TCP_NODELAY
%37 = call i32 @setsockopt(i32 %10, i32 %35, i32 %36, i8* %7, i32 4)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = call i32 @listen(i32 %10, i32 50)
%44 = icmp eq i32 %43, -1
br i1 %44, label %51, label %45
45: ; preds = %42
%46 = bitcast %struct.sockaddr_storage* %4 to i8*
%47 = bitcast i32* %5 to i8*
%48 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
store i32 4, i32* %5
%49 = call i32 @accept(i32 %10, %struct.sockaddr* %48, i32* %5)
%50 = icmp eq i32 %49, -1
br i1 %50, label %53, label %55
51: ; preds = %42
%52 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %68
53: ; preds = %64, %45
%54 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %68
55: ; preds = %45, %64
%56 = phi i32 [ %66, %64 ], [ %49, %45 ]
%57 = load i32, i32* @IPPROTO_TCP
%58 = load i32, i32* @TCP_NODELAY
%59 = call i32 @setsockopt(i32 %56, i32 %57, i32 %58, i8* %7, i32 4)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %55
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %55
%65 = call i32 @process_ctr_msg(i32 %56)
store i32 4, i32* %5
%66 = call i32 @accept(i32 %10, %struct.sockaddr* %48, i32* %5)
%67 = icmp eq i32 %66, -1
br i1 %67, label %53, label %55
68: ; preds = %53, %51, %32, %12
ret void
}