#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 {
  char sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
long recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int main(int argc, const char *argv[]) {
  struct sockaddr_in server_addr;
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(11332);
  server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  bzero(&(server_addr.sin_zero), 8);
  int server_socket = socket(AF_INET, SOCK_STREAM, 0);
  if (server_socket == -1) {
    perror("socket error");
    return 1;
  }
  int bind_result =
      bind(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr));
  if (bind_result == -1) {
    perror("bind error");
    return 1;
  }
  if (listen(server_socket, 5) == -1) {
    perror("listen error");
    return 1;
  }
  struct sockaddr_in client_address;
  socklen_t address_len;
  int client_socket =
      accept(server_socket, (struct sockaddr *)&client_address, &address_len);
  if (client_socket == -1) {
    perror("accept error");
    return -1;
  }
  char recv_msg[1024];
  char reply_msg[1024];
  while (1) {
    bzero(recv_msg, 1024);
    bzero(reply_msg, 1024);
    printf("reply:");
    scanf("%s", reply_msg);
    send(client_socket, reply_msg, 1024, 0);
    long byte_num = recv(client_socket, recv_msg, 1024, 0);
    recv_msg[byte_num] = '\0';
    printf("client said:%s\n", recv_msg);
    if (strcmp(recv_msg, "quit") == 0)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x2c44,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
lea    0xdf7(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   10d0 <bzero@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    125d <main+0x8d>
lea    0xdbe(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x1f3>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <bind@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1293 <main+0xc3>
lea    0xd95(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x1f3>
mov    -0x24(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    12c1 <main+0xf1>
lea    0xd72(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <main+0x1f3>
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    12f6 <main+0x126>
lea    0xd4a(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c3 <main+0x1f3>
jmp    12fb <main+0x12b>
lea    -0x440(%rbp),%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
lea    -0x840(%rbp),%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x840(%rbp),%rsi
lea    0xd0a(%rip),%rdi
call   10a0 <scanf@plt>
mov    -0x40(%rbp),%edi
lea    -0x840(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x40(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x848(%rbp)
mov    -0x848(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x440(%rbp),%rsi
lea    0xcb8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x440(%rbp),%rdi
lea    0xcb3(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13b7 <main+0x1e7>
jmp    13bc <main+0x1ec>
jmp    12fb <main+0x12b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    0x2e00(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x14(%rsp)
mov    $0x2c44,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0xdfd(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   10d0 <bzero@plt>
mov    (%rbx),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     133b <main+0x16b>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     1344 <main+0x174>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
je     134d <main+0x17d>
lea    0x20(%rsp),%rsi
lea    0x1c(%rsp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
cmp    $0xffffffff,%eax
je     1360 <main+0x190>
mov    %eax,%ebp
lea    0x30(%rsp),%rbx
lea    0x430(%rsp),%r14
lea    0xdac(%rip),%r12
lea    0xda8(%rip),%r13
lea    0xdb1(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
mov    %r14,%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
lea    0xd6b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   10a0 <scanf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12b0 <main+0xe0>
xor    %eax,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc8(%rip),%rdi
jmp    1354 <main+0x184>
lea    0xccc(%rip),%rdi
jmp    1354 <main+0x184>
lea    0xcce(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%eax
jmp    1329 <main+0x159>
lea    0xcc8(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1329 <main+0x159>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [11 x i8] c"bind error\00"
@.str.3 = [13 x i8] c"listen error\00"
@.str.4 = [13 x i8] c"accept error\00"
@.str.5 = [7 x i8] c"reply:\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [16 x i8] c"client said:%s\0A\00"
@.str.8 = [5 x i8] c"quit\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca [1024 x i8]
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 3
store i32 %15, i32* %16
%17 = call i32 @htons(i32 11332)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%23 = call i32 @bzero(i8* %22, i32 8)
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %78
31: ; preds = %2
%32 = load i32, i32* %7
%33 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%34 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 16)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %78
39: ; preds = %31
%40 = load i32, i32* %7
%41 = call i32 @listen(i32 %40, i32 5)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %78
45: ; preds = %39
%46 = load i32, i32* %7
%47 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%48 = call i32 @accept(i32 %46, %struct.sockaddr* %47, i32* %10)
store i32 %48, i32* %11
%49 = load i32, i32* %11
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %78
53: ; preds = %45
br label %54
54: ; preds = %53, %76
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%56 = call i32 @bzero(i8* %55, i32 1024)
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%58 = call i32 @bzero(i8* %57, i32 1024)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%61 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %60)
%62 = load i32, i32* %11
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%64 = call i32 @send(i32 %62, i8* %63, i32 1024, i32 0)
%65 = load i32, i32* %11
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%67 = call i64 @recv(i32 %65, i8* %66, i32 1024, i32 0)
store i64 %67, i64* %14
%68 = load i64, i64* %14
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 %68
store i8 0, i8* %69
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %70)
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%73 = call i64 @strcmp(i8* %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %54
br label %77
76: ; preds = %54
br label %54
77: ; preds = %75
store i32 0, i32* %3
br label %78
78: ; preds = %77, %51, %43, %37, %29
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.1 = [13 x i8] c"socket error\00"
@.str.2 = [11 x i8] c"bind error\00"
@.str.3 = [13 x i8] c"listen error\00"
@.str.4 = [13 x i8] c"accept error\00"
@.str.5 = [7 x i8] c"reply:\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [16 x i8] c"client said:%s\0A\00"
@.str.8 = [5 x i8] c"quit\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 11332)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = call i32 @bzero(i8* %8, i32 8)
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %58
22: ; preds = %2
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i32 @bind(i32 %18, %struct.sockaddr* %23, i32 16)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %58
28: ; preds = %22
%29 = call i32 @listen(i32 %18, i32 5)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %58
33: ; preds = %28
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%35 = bitcast i32* %5 to i8*
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%37 = call i32 @accept(i32 %18, %struct.sockaddr* %36, i32* %5)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %56
41: ; preds = %33
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
br label %44
44: ; preds = %44, %41
%45 = call i32 @bzero(i8* %42, i32 1024)
%46 = call i32 @bzero(i8* %43, i32 1024)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %43)
%49 = call i32 @send(i32 %37, i8* %43, i32 1024, i32 0)
%50 = call i64 @recv(i32 %37, i8* %42, i32 1024, i32 0)
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %50
store i8 0, i8* %51
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %42)
%53 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %44
55: ; preds = %44
br label %56
56: ; preds = %55, %39
%57 = phi i32 [ -1, %39 ], [ 0, %55 ]
br label %58
58: ; preds = %26, %31, %56, %20
%59 = phi i32 [ 1, %20 ], [ 1, %26 ], [ 1, %31 ], [ %57, %56 ]
ret i32 %59
}