#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 /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  struct sockaddr_in sin;
  char buf[256];
  int len;
  int s, new_s;
  bzero((char *)&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = INADDR_ANY;
  sin.sin_port = htons(5432);
  if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("simplex-talk: socket");
    exit(1);
  }
  if ((bind(s, (struct sockaddr *)&sin, sizeof(sin))) < 0) {
    perror("simple-talk: bind");
    exit(1);
  }
  listen(s, 5);
  while (1) {
    if ((new_s = accept(s, (struct sockaddr *)&sin, &len)) < 0) {
      perror("simplex-talk: accpet");
      exit(1);
    }
    while (len = recv(new_s, buf, sizeof(buf), 0)) {
      fputs(buf, stdout);
    }
    close(new_s);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x1538,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x128(%rbp)
cmp    $0x0,%eax
jge    123a <main+0x8a>
lea    0xdd5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x128(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    126e <main+0xbe>
lea    0xdb6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x128(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
mov    -0x128(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x124(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x12c(%rbp)
cmp    $0x0,%eax
jge    12b9 <main+0x109>
lea    0xd7d(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12be <main+0x10e>
mov    -0x12c(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x124(%rbp)
cmp    $0x0,%eax
je     1300 <main+0x150>
lea    -0x120(%rbp),%rdi
mov    0x2ccc(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    12be <main+0x10e>
mov    -0x12c(%rbp),%edi
call   1060 <close@plt>
jmp    127e <main+0xce>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x1538,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    1221 <main+0x71>
lea    0xde4(%rip),%rdi
jmp    12d7 <main+0x127>
mov    %eax,%r15d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
jns    1246 <main+0x96>
lea    0xdd4(%rip),%rdi
jmp    12d7 <main+0x127>
mov    %r15d,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r15d,%edi
call   10b0 <accept@plt>
test   %eax,%eax
js     12d0 <main+0x120>
mov    %eax,%ebp
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r12
mov    0x2d3f(%rip),%r13
jmp    129c <main+0xec>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jne    1290 <main+0xe0>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   10b0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    129c <main+0xec>
lea    0xd50(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

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
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"simplex-talk: socket\00"
@.str.1 = [18 x i8] c"simple-talk: bind\00"
@.str.2 = [21 x i8] c"simplex-talk: accpet\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast %struct.sockaddr_in* %6 to i8*
%12 = call i32 @bzero(i8* %11, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = call i32 @htons(i32 5432)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @PF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %9
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %2
%28 = load i32, i32* %9
%29 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%30 = call i64 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
%36 = load i32, i32* %9
%37 = call i32 @listen(i32 %36, i32 5)
br label %38
38: ; preds = %35, %56
%39 = load i32, i32* %9
%40 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%41 = call i32 @accept(i32 %39, %struct.sockaddr* %40, i32* %8)
store i32 %41, i32* %10
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
br label %47
47: ; preds = %52, %46
%48 = load i32, i32* %10
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%50 = call i32 @recv(i32 %48, i8* %49, i32 256, i32 0)
store i32 %50, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%54 = load i32, i32* @stdout
%55 = call i32 @fputs(i8* %53, i32 %54)
br label %47
56: ; preds = %47
%57 = load i32, i32* %10
%58 = call i32 @close(i32 %57)
br label %38
}

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
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [21 x i8] c"simplex-talk: socket\00"
@.str.1 = [18 x i8] c"simple-talk: bind\00"
@.str.2 = [21 x i8] c"simplex-talk: accpet\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
%9 = call i32 @bzero(i8* %6, i32 12)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 5432)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @PF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i64 @bind(i32 %18, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %23
%31 = call i32 @listen(i32 %18, i32 5)
%32 = call i32 @accept(i32 %18, %struct.sockaddr* %24, i32* %5)
%33 = icmp slt i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %30, %46
%35 = phi i32 [ %48, %46 ], [ %32, %30 ]
%36 = call i32 @recv(i32 %35, i8* %7, i32 256, i32 0)
store i32 %36, i32* %5
%37 = icmp eq i32 %36, 0
br i1 %37, label %46, label %41
38: ; preds = %46, %30
%39 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %34, %41
%42 = load i32, i32* @stdout
%43 = call i32 @fputs(i8* %7, i32 %42)
%44 = call i32 @recv(i32 %35, i8* %7, i32 256, i32 0)
store i32 %44, i32* %5
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %41
46: ; preds = %41, %34
%47 = call i32 @close(i32 %35)
%48 = call i32 @accept(i32 %18, %struct.sockaddr* %24, i32* %5)
%49 = icmp slt i32 %48, 0
br i1 %49, label %38, label %34
}