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

/* Variables and functions */
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, unsigned int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
scalar_t__ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ puts(char *);
int rand();
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  char *advice[] = {
      "Take smaller bites\r\n",
      "Go for the tight jeans. No they do NOT make you look fat.\r\n",
      "One word: inappropriate\r\n",
      "Just for today, be honest. Tell your boss what you *really* think\r\n",
      "You might want to rethink that haircut\r\n"};
  int listener_d = socket(PF_INET, SOCK_STREAM, 0);
  int reuse = 1;
  if (setsockopt(listener_d, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse,
                 sizeof(int)) == -1) {
    error("Can't set the reuse option on the socket");
  }
  struct sockaddr_in name;
  name.sin_family = PF_INET;
  name.sin_port = (in_port_t)htons(30000);
  name.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(listener_d, (struct sockaddr *)&name, sizeof(name)) == -1) {
    error("Can't bind the port");
  }
  listen(listener_d, 10);
  puts("Waiting for connection");
  while (1) {
    struct sockaddr_storage client_addr;
    unsigned int address_size = sizeof(client_addr);
    int connect_d =
        accept(listener_d, (struct sockaddr *)&client_addr, &address_size);
    char *msg = advice[rand() % 5];
    send(connect_d, msg, strlen(msg), 0);
    close(connect_d);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1090 <memset@plt>
lea    0xdf0(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xdfa(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe2b(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe3a(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x44(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
lea    -0x48(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    129c <main+0xbc>
lea    0xe41(%rip),%rdi
call   10d0 <error@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    $0x7530,%edi
call   1060 <htons@plt>
mov    %rax,-0x58(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x60(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12ed <main+0x10d>
lea    0xe19(%rip),%rdi
call   10d0 <error@plt>
mov    -0x44(%rbp),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
movl   $0x4,-0x6c(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x68(%rbp),%rsi
lea    -0x6c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x70(%rbp)
mov    $0x0,%al
call   10f0 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x78(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x70(%rbp),%edi
call   10a0 <close@plt>
jmp    1306 <main+0x126>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
lea    0xe1d(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe26(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xe56(%rip),%rax
mov    %rax,0x40(%rsp)
lea    0xe64(%rip),%rax
mov    %rax,0x48(%rsp)
lea    0xe9c(%rip),%rax
mov    %rax,0x50(%rsp)
mov    0x2da9(%rip),%rbx
mov    (%rbx),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%r15d
movl   $0x1,0xc(%rsp)
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
mov    0x2d74(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1272 <main+0xa2>
lea    0xe6b(%rip),%rdi
call   10c0 <error@plt>
mov    (%rbx),%eax
mov    %eax,0x28(%rsp)
mov    $0x7530,%edi
call   1060 <htons@plt>
mov    %rax,0x20(%rsp)
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x18(%rsp)
lea    0x18(%rsp),%rsi
mov    %r15d,%edi
mov    $0x18,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12bc <main+0xec>
lea    0xe4a(%rip),%rdi
call   10c0 <error@plt>
mov    %r15d,%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r12
nop
movl   $0x4,0x8(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   10d0 <accept@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10e0 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
cltq
mov    0x30(%rsp,%rax,8),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebp,%edi
call   1090 <close@plt>
jmp    12e0 <main+0x110>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Take smaller bites\0D\0A\00"
@.str.1 = [60 x i8] c"Go for the tight jeans. No they do NOT make you look fat.\0D\0A\00"
@.str.2 = [26 x i8] c"One word: inappropriate\0D\0A\00"
@.str.3 = [68 x i8] c"Just for today, be honest. Tell your boss what you *really* think\0D\0A\00"
@.str.4 = [41 x i8] c"You might want to rethink that haircut\0D\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [41 x i8] c"Can't set the reuse option on the socket\00"
@INADDR_ANY = global i32 0
@.str.6 = [20 x i8] c"Can't bind the port\00"
@.str.7 = [23 x i8] c"Waiting for connection\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_storage
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [5 x i8*]* %6 to i8*
%15 = bitcast i8* %14 to [5 x i8*]*
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %15, i32 0, i32 0
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %15, i32 0, i32 1
store i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %15, i32 0, i32 2
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i32 0, i32 0), i8** %18
%19 = getelementptr inbounds [5 x i8*], [5 x i8*]* %15, i32 0, i32 3
store i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i32 0, i32 0), i8** %19
%20 = getelementptr inbounds [5 x i8*], [5 x i8*]* %15, i32 0, i32 4
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i32 0, i32 0), i8** %20
%21 = load i32, i32* @PF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %7
store i32 1, i32* %8
%24 = load i32, i32* %7
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEADDR
%27 = bitcast i32* %8 to i8*
%28 = call i32 @setsockopt(i32 %24, i32 %25, i32 %26, i8* %27, i32 4)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %2
%31 = call i32 @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %2
%33 = load i32, i32* @PF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %33, i32* %34
%35 = call i64 @htons(i32 30000)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i64 %35, i64* %36
%37 = load i32, i32* @INADDR_ANY
%38 = call i32 @htonl(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i32 %38, i32* %40
%41 = load i32, i32* %7
%42 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%43 = call i32 @bind(i32 %41, %struct.sockaddr* %42, i32 24)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %32
%46 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %47
47: ; preds = %45, %32
%48 = load i32, i32* %7
%49 = call i32 @listen(i32 %48, i32 10)
%50 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %51
51: ; preds = %47, %51
store i32 4, i32* %11
%52 = load i32, i32* %7
%53 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr*
%54 = call i32 @accept(i32 %52, %struct.sockaddr* %53, i32* %11)
store i32 %54, i32* %12
%55 = call i32 (...) @rand()
%56 = srem i32 %55, 5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 %57
%59 = load i8*, i8** %58
store i8* %59, i8** %13
%60 = load i32, i32* %12
%61 = load i8*, i8** %13
%62 = load i8*, i8** %13
%63 = call i32 @strlen(i8* %62)
%64 = call i32 @send(i32 %60, i8* %61, i32 %63, i32 0)
%65 = load i32, i32* %12
%66 = call i32 @close(i32 %65)
br label %51
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i64, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Take smaller bites\0D\0A\00"
@.str.1 = [60 x i8] c"Go for the tight jeans. No they do NOT make you look fat.\0D\0A\00"
@.str.2 = [26 x i8] c"One word: inappropriate\0D\0A\00"
@.str.3 = [68 x i8] c"Just for today, be honest. Tell your boss what you *really* think\0D\0A\00"
@.str.4 = [41 x i8] c"You might want to rethink that haircut\0D\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [41 x i8] c"Can't set the reuse option on the socket\00"
@INADDR_ANY = global i32 0
@.str.6 = [20 x i8] c"Can't bind the port\00"
@.str.7 = [23 x i8] c"Waiting for connection\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i8*]
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = bitcast [5 x i8*]* %3 to i8*
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8** %13
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = call i32 @setsockopt(i32 %16, i32 %18, i32 %19, i8* %17, i32 4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = bitcast %struct.sockaddr_in* %5 to i8*
%26 = load i32, i32* @PF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %26, i32* %27
%28 = call i64 @htons(i32 30000)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i64 %28, i64* %29
%30 = load i32, i32* @INADDR_ANY
%31 = call i32 @htonl(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %31, i32* %32
%33 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%34 = call i32 @bind(i32 %16, %struct.sockaddr* %33, i32 24)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %24
%37 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %36, %24
%39 = call i32 @listen(i32 %16, i32 10)
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%41 = bitcast %struct.sockaddr_storage* %6 to i8*
%42 = bitcast i32* %7 to i8*
%43 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
br label %44
44: ; preds = %44, %38
store i32 4, i32* %7
%45 = call i32 @accept(i32 %16, %struct.sockaddr* %43, i32* %7)
%46 = call i32 (...) @rand()
%47 = srem i32 %46, 5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 @strlen(i8* %50)
%52 = call i32 @send(i32 %45, i8* %50, i32 %51, i32 0)
%53 = call i32 @close(i32 %45)
br label %44
}