#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;
};
typedef int /*<<< orphan*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int accept_connection(int, struct sockaddr_in);
int /*<<< orphan*/ bind_socket(int, struct sockaddr_in);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int create_socket();
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ get_message(int, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_message(int, char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int main(int argc, char const *argv[]) {
  struct sockaddr_in server_addr;
  struct sockaddr_in client_addr;
  int socket_server;
  int socket_client;
  char in_buf[256];
  char out_buf[256];
  bzero(in_buf, 256);
  bzero(out_buf, 256);
  socket_server = create_socket();
  bzero((char *)&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = INADDR_ANY;
  server_addr.sin_port = htons(4711);
  bind_socket(socket_server, server_addr);
  listen(socket_server, 5);
  socket_client = accept_connection(socket_server, client_addr);
  while (1) {
    printf("waiting for reply...\n");
    bzero(in_buf, 256);
    get_message(socket_client, in_buf);
    printf("client sayz: %s\n", in_buf);
    printf("Message to client: ");
    bzero(out_buf, 256);
    fgets(out_buf, 256, stdin);
    if (strcmp(out_buf, "quit\n") == 0) {
      break;
    }
    printf("sending: %s\n", out_buf);
    send_message(socket_client, out_buf);
  }
  close(socket_client);
  close(socket_server);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
lea    -0x240(%rbp),%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
mov    $0x0,%al
call   10d0 <create_socket@plt>
mov    %eax,-0x34(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x1267,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x248(%rbp)
mov    -0x250(%rbp),%rsi
mov    -0x248(%rbp),%edx
call   1040 <bind_socket@plt>
mov    -0x34(%rbp),%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rax
mov    %rax,-0x260(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x258(%rbp)
mov    -0x260(%rbp),%rsi
mov    -0x258(%rbp),%edx
call   10b0 <accept_connection@plt>
mov    %eax,-0x38(%rbp)
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
mov    -0x38(%rbp),%edi
lea    -0x140(%rbp),%rsi
call   1030 <get_message@plt>
lea    -0x140(%rbp),%rsi
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x240(%rbp),%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
lea    -0x240(%rbp),%rdi
mov    0x2cd6(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1090 <fgets@plt>
lea    -0x240(%rbp),%rdi
lea    0xd17(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1338 <main+0x178>
jmp    1361 <main+0x1a1>
lea    -0x240(%rbp),%rsi
lea    0xcfb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%edi
lea    -0x240(%rbp),%rsi
call   1070 <send_message@plt>
jmp    129a <main+0xda>
mov    -0x38(%rbp),%edi
call   1080 <close@plt>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
lea    0x120(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   10f0 <bzero@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10f0 <bzero@plt>
xor    %eax,%eax
call   10e0 <create_socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%r15d
mov    %r15d,0x18(%rsp)
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x1267,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    %r15d,%edx
call   1040 <bind_socket@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
mov    %ebp,0xc(%rsp)
mov    %ebp,%edi
call   10c0 <accept_connection@plt>
mov    %eax,%ebp
mov    0x2d67(%rip),%r15
lea    0xda5(%rip),%r12
lea    0xda4(%rip),%r13
nopw   0x0(%rax,%rax,1)
lea    0xda1(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
mov    $0x100,%esi
call   10f0 <bzero@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <get_message@plt>
lea    0xd46(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd46(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   10f0 <bzero@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     131b <main+0x14b>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <send_message@plt>
jmp    1290 <main+0xc0>
mov    %ebp,%edi
call   1090 <close@plt>
mov    0xc(%rsp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [22 x i8] c"waiting for reply...\0A\00"
@.str.1 = [17 x i8] c"client sayz: %s\0A\00"
@.str.2 = [20 x i8] c"Message to client: \00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"quit\0A\00"
@.str.4 = [13 x i8] c"sending: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca [256 x i8]
%12 = alloca { i64, i32 }
%13 = alloca { i64, i32 }
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%15 = call i32 @bzero(i8* %14, i32 256)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%17 = call i32 @bzero(i8* %16, i32 256)
%18 = call i32 (...) @create_socket()
store i32 %18, i32* %8
%19 = bitcast %struct.sockaddr_in* %6 to i8*
%20 = call i32 @bzero(i8* %19, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = call i32 @htons(i32 4711)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* %8
%29 = bitcast { i64, i32 }* %12 to i8*
%30 = bitcast %struct.sockaddr_in* %6 to i8*
%31 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %12, i32 0, i32 0
%32 = load i64, i64* %31
%33 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %12, i32 0, i32 1
%34 = load i32, i32* %33
%35 = call i32 @bind_socket(i32 %28, i64 %32, i32 %34)
%36 = load i32, i32* %8
%37 = call i32 @listen(i32 %36, i32 5)
%38 = load i32, i32* %8
%39 = bitcast { i64, i32 }* %13 to i8*
%40 = bitcast %struct.sockaddr_in* %7 to i8*
%41 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %13, i32 0, i32 0
%42 = load i64, i64* %41
%43 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %13, i32 0, i32 1
%44 = load i32, i32* %43
%45 = call i32 @accept_connection(i32 %38, i64 %42, i32 %44)
store i32 %45, i32* %9
br label %46
46: ; preds = %2, %65
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%49 = call i32 @bzero(i8* %48, i32 256)
%50 = load i32, i32* %9
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%52 = call i32 @get_message(i32 %50, i8* %51)
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%57 = call i32 @bzero(i8* %56, i32 256)
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%59 = load i32, i32* @stdin
%60 = call i32 @fgets(i8* %58, i32 256, i32 %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%62 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %46
br label %71
65: ; preds = %46
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %66)
%68 = load i32, i32* %9
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%70 = call i32 @send_message(i32 %68, i8* %69)
br label %46
71: ; preds = %64
%72 = load i32, i32* %9
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %8
%75 = call i32 @close(i32 %74)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [17 x i8] c"client sayz: %s\0A\00"
@.str.2 = [20 x i8] c"Message to client: \00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"quit\0A\00"
@.str.4 = [13 x i8] c"sending: %s\0A\00"
@str = [21 x i8] c"waiting for reply...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = call i32 @bzero(i8* %7, i32 256)
%10 = call i32 @bzero(i8* %8, i32 256)
%11 = tail call i32 (...) @create_socket()
%12 = call i32 @bzero(i8* %6, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 4711)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %3 to i64*
%20 = load i64, i64* %19
%21 = tail call i32 @bind_socket(i32 %11, i64 %20, i32 %13)
%22 = tail call i32 @listen(i32 %11, i32 5)
%23 = tail call i32 @accept_connection(i32 %11, i64 undef, i32 undef)
br label %24
24: ; preds = %35, %2
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%26 = call i32 @bzero(i8* %7, i32 256)
%27 = call i32 @get_message(i32 %23, i8* %7)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @bzero(i8* %8, i32 256)
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %8, i32 256, i32 %31)
%33 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %24
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%37 = call i32 @send_message(i32 %23, i8* %8)
br label %24
38: ; preds = %24
%39 = call i32 @close(i32 %23)
%40 = call i32 @close(i32 %11)
ret i32 0
}