#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 */

/* Type definitions */
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hint;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOMAXCONN;
int accept(int, struct sockaddr *, int *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  struct addrinfo hint, *result;
  struct sockaddr remote;
  int res, sfd, fd;
  char buf[100];
  memset(&hint, 0, sizeof(hint));
  hint.ai_family = AF_INET;
  hint.ai_socktype = SOCK_STREAM;
  hint.ai_protocol = 0;
  hint.ai_flags = AI_PASSIVE;
  res = getaddrinfo(NULL, "8080", &hint, &result);
  if (res != 0) {
    perror("error : cannot get socket address!\n");
    exit(1);
  }
  sfd = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
  if (sfd == -1) {
    perror("error : cannot get socket file descriptor!\n");
    exit(1);
  }
  res = bind(sfd, result->ai_addr, result->ai_addrlen);
  if (res == -1) {
    perror("error : cannot bind the socket with the given address!\n");
    exit(1);
  }
  res = listen(sfd, SOMAXCONN);
  if (res == -1) {
    perror("error : cannot listen at the given socket!\n");
    exit(1);
  }
  while (1) {
    int len = sizeof(struct sockaddr);
    fd = accept(sfd, &remote, &len);
    res = read(fd, buf, sizeof(buf));
    printf("user data : %s\n", buf);
    sleep(10);
    strcpy(buf, "Hello Client");
    res = write(fd, buf, sizeof(buf));
    printf("send data : %s\n", buf);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd0(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     1260 <main+0x90>
lea    0xdb4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rdx
call   10f0 <socket@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    129e <main+0xce>
lea    0xd9a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x48(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1090 <bind@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    12d6 <main+0x106>
lea    0xd8e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x48(%rbp),%edi
mov    0x2cf0(%rip),%rax
mov    (%rax),%esi
call   1080 <listen@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    130a <main+0x13a>
lea    0xd92(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    130f <main+0x13f>
movl   $0x4,-0xb4(%rbp)
mov    -0x48(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0xb4(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %eax,-0x44(%rbp)
lea    -0xb0(%rbp),%rsi
lea    0xd65(%rip),%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
call   10e0 <sleep@plt>
lea    -0xb0(%rbp),%rdi
lea    0xd58(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4c(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x64,%edx
call   1040 <write@plt>
mov    %eax,-0x44(%rbp)
lea    -0xb0(%rbp),%rsi
lea    0xd3b(%rip),%rdi
call   1050 <printf@plt>
jmp    130f <main+0x13f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
movq   $0x0,0x28(%rsp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
lea    0xdd4(%rip),%rsi
lea    0x10(%rsp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
jne    1318 <main+0x148>
mov    0x10(%rsp),%rax
mov    0x14(%rax),%edi
mov    0x10(%rax),%esi
mov    0x8(%rax),%rdx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     1321 <main+0x151>
mov    %eax,%ebp
mov    0x10(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     132a <main+0x15a>
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
je     1333 <main+0x163>
lea    0x40(%rsp),%rbx
lea    0xe18(%rip),%r12
lea    0xe21(%rip),%r13
lea    0xe27(%rip),%r14
nop
movl   $0x4,0xc(%rsp)
mov    %ebp,%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10b0 <accept@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0xa,%edi
call   10e0 <sleep@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1040 <write@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    12b0 <main+0xe0>
lea    0xce6(%rip),%rdi
jmp    133a <main+0x16a>
lea    0xd01(%rip),%rdi
jmp    133a <main+0x16a>
lea    0xd24(%rip),%rdi
jmp    133a <main+0x16a>
lea    0xd53(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i64, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"8080\00"
@.str.1 = [36 x i8] c"error : cannot get socket address!\0A\00"
@.str.2 = [44 x i8] c"error : cannot get socket file descriptor!\0A\00"
@.str.3 = [56 x i8] c"error : cannot bind the socket with the given address!\0A\00"
@SOMAXCONN = global i32 0
@.str.4 = [44 x i8] c"error : cannot listen at the given socket!\0A\00"
@.str.5 = [16 x i8] c"user data : %s\0A\00"
@.str.6 = [13 x i8] c"Hello Client\00"
@.str.7 = [16 x i8] c"send data : %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.sockaddr
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [100 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 32)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_STREAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i64 0, i64* %19
%20 = load i32, i32* @AI_PASSIVE
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store i32 %20, i32* %21
%22 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = load %struct.addrinfo*, %struct.addrinfo** %7
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i32 0, i32 4
%31 = load i32, i32* %30
%32 = load %struct.addrinfo*, %struct.addrinfo** %7
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i32 0, i32 3
%34 = load i32, i32* %33
%35 = load %struct.addrinfo*, %struct.addrinfo** %7
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 2
%37 = load i64, i64* %36
%38 = call i32 @socket(i32 %31, i32 %34, i64 %37)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %28
%42 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %28
%45 = load i32, i32* %10
%46 = load %struct.addrinfo*, %struct.addrinfo** %7
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = load %struct.addrinfo*, %struct.addrinfo** %7
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @bind(i32 %45, i32 %48, i32 %51)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %44
%56 = call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %44
%59 = load i32, i32* %10
%60 = load i32, i32* @SOMAXCONN
%61 = call i32 @listen(i32 %59, i32 %60)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %67
64: ; preds = %58
%65 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %58
br label %68
68: ; preds = %67, %68
store i32 4, i32* %13
%69 = load i32, i32* %10
%70 = call i32 @accept(i32 %69, %struct.sockaddr* %8, i32* %13)
store i32 %70, i32* %11
%71 = load i32, i32* %11
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%73 = call i32 @read(i32 %71, i8* %72, i32 100)
store i32 %73, i32* %9
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%75 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %74)
%76 = call i32 @sleep(i32 10)
%77 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%78 = call i32 @strcpy(i8* %77, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%79 = load i32, i32* %11
%80 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%81 = call i32 @write(i32 %79, i8* %80, i32 100)
store i32 %81, i32* %9
%82 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%83 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %82)
br label %68
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i64, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str = [5 x i8] c"8080\00"
@.str.1 = [36 x i8] c"error : cannot get socket address!\0A\00"
@.str.2 = [44 x i8] c"error : cannot get socket file descriptor!\0A\00"
@.str.3 = [56 x i8] c"error : cannot bind the socket with the given address!\0A\00"
@SOMAXCONN = global i32 0
@.str.4 = [44 x i8] c"error : cannot listen at the given socket!\0A\00"
@.str.5 = [16 x i8] c"user data : %s\0A\00"
@.str.6 = [13 x i8] c"Hello Client\00"
@.str.7 = [16 x i8] c"send data : %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.sockaddr
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = bitcast %struct.sockaddr* %5 to i8*
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%12 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i64 0, i64* %17
%18 = load i32, i32* @AI_PASSIVE
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %18, i32* %19
%20 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load %struct.addrinfo*, %struct.addrinfo** %4
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 4
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 3
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 2
%32 = load i64, i64* %31
%33 = call i32 @socket(i32 %28, i32 %30, i64 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %25
%36 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %25
%39 = load %struct.addrinfo*, %struct.addrinfo** %4
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @bind(i32 %33, i32 %41, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %38
%47 = call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %38
%50 = load i32, i32* @SOMAXCONN
%51 = call i32 @listen(i32 %33, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = bitcast i32* %7 to i8*
br label %58
55: ; preds = %49
%56 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %53, %58
store i32 4, i32* %7
%59 = call i32 @accept(i32 %33, %struct.sockaddr* %5, i32* %7)
%60 = call i32 @read(i32 %59, i8* %11, i32 100)
%61 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %11)
%62 = call i32 @sleep(i32 10)
%63 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%64 = call i32 @write(i32 %59, i8* %11, i32 100)
%65 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %11)
br label %58
}