#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*/ socklen_t;
typedef int /*<<< orphan*/ serverAddress;
typedef int /*<<< orphan*/ clientAddress;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int func(int);
int /*<<< orphan*/ getData(int, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sendData(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, portno = 51719, client;
  char buffer[1024];
  struct sockaddr_in serverAddress, clientAddress;
  int n;
  int data;
  printf("using port #%d\n", portno);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("ERROR opening socket");
  }
  bzero((char *)&serverAddress, sizeof(serverAddress));
  serverAddress.sin_family = AF_INET;
  serverAddress.sin_addr.s_addr = INADDR_ANY;
  serverAddress.sin_port = htons(portno);
  if (bind(sockfd, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) <
      0) {
    perror("ERROR on binding");
  }
  listen(sockfd, 5);
  client = sizeof(clientAddress);
  while (1) {
    printf("waiting for new client...\n");
    if ((newsockfd = accept(sockfd, (struct sockaddr *)&clientAddress,
                            (socklen_t *)&client)) < 0) {
      perror("ERROR on accept");
    }
    printf("opened new communication with client\n");
    while (1) {
      getData(newsockfd, buffer);
      printf("got %d\n", data);
      if (strcmp(buffer, "quit") == 0) {
        printf("got quit\n");
        break;
      }
      data = func(data);
      printf("sending back %d\n", data);
      sendData(newsockfd, data);
    }
    close(newsockfd);
    if (strcmp(buffer, "quit") == 0)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xca07,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1233 <main+0x63>
lea    0xde2(%rip),%rdi
call   10b0 <perror@plt>
lea    -0x430(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x42c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x430(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    129a <main+0xca>
lea    0xd90(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
movl   $0xc,-0x20(%rbp)
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12e7 <main+0x117>
lea    0xd6f(%rip),%rdi
call   10b0 <perror@plt>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
call   1030 <getData@plt>
mov    -0x448(%rbp),%esi
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1348 <main+0x178>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1380 <main+0x1b0>
mov    -0x448(%rbp),%edi
call   1080 <func@plt>
mov    %eax,-0x448(%rbp)
mov    -0x448(%rbp),%esi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x448(%rbp),%esi
call   10f0 <sendData@plt>
jmp    12f5 <main+0x125>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
lea    -0x420(%rbp),%rdi
lea    0xcf9(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13aa <main+0x1da>
jmp    13af <main+0x1df>
jmp    12ae <main+0xde>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
lea    0xe08(%rip),%rdi
mov    $0xca07,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2ddd(%rip),%r14
mov    (%r14),%edi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1380 <main+0x1a0>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0xca07,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
test   %rax,%rax
js     1391 <main+0x1b1>
mov    %ebp,0x8(%rsp)
mov    %ebp,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%r13
lea    0xdae(%rip),%r14
lea    0xe03(%rip),%r15
lea    0xda8(%rip),%rbp
jmp    12d7 <main+0xf7>
nopl   0x0(%rax,%rax,1)
lea    0xde7(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     136c <main+0x18c>
lea    0xd81(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10e0 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
js     135e <main+0x17e>
lea    0xd76(%rip),%rdi
call   1040 <puts@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r13,%rsi
call   1030 <getData@plt>
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12b0 <main+0xd0>
mov    %r12d,%edi
call   1090 <func@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %r12d,%esi
call   1100 <sendData@plt>
jmp    1310 <main+0x130>
lea    0xcd1(%rip),%rdi
call   10c0 <perror@plt>
jmp    12fc <main+0x11c>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc89(%rip),%rdi
call   10c0 <perror@plt>
jmp    1228 <main+0x48>
lea    0xc8d(%rip),%rdi
call   10c0 <perror@plt>
jmp    1274 <main+0x94>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"using port #%d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [17 x i8] c"ERROR on binding\00"
@.str.4 = [16 x i8] c"ERROR on accept\00"
@.str.6 = [8 x i8] c"got %d\0A\00"
@.str.7 = [5 x i8] c"quit\00"
@.str.9 = [17 x i8] c"sending back %d\0A\00"
@str = [26 x i8] c"waiting for new client...\00"
@str.10 = [37 x i8] c"opened new communication with client\00"
@str.11 = [9 x i8] c"got quit\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 51719)
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = call i32 @bzero(i8* %9, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 51719)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %24, i32* %25
%26 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%27 = call i64 @bind(i32 %14, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %18
%32 = call i32 @listen(i32 %14, i32 5)
store i32 12, i32* %3
%33 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
br label %34
34: ; preds = %47, %31
%35 = phi i32 [ undef, %31 ], [ %48, %47 ]
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%37 = call i32 @accept(i32 %14, %struct.sockaddr* %33, i32* %3)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.10, i64 0, i64 0))
%43 = call i32 @getData(i32 %37, i8* %8)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%45 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %53, %41
%48 = phi i32 [ %35, %41 ], [ %55, %53 ]
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.11, i64 0, i64 0))
%50 = call i32 @close(i32 %37)
%51 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %62, label %34
53: ; preds = %41, %53
%54 = phi i32 [ %55, %53 ], [ %35, %41 ]
%55 = call i32 @func(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %55)
%57 = call i32 @sendData(i32 %37, i32 %55)
%58 = call i32 @getData(i32 %37, i8* %8)
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %55)
%60 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %47, label %53
62: ; preds = %47
ret i32 0
}