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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int serv_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  struct sockaddr_in serv_addr;
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  serv_addr.sin_port = htons(1234);
  bind(serv_sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  listen(serv_sock, 30);
  struct sockaddr_in clnt_addr;
  socklen_t clnt_addr_size = sizeof(struct sockaddr_in);
  char buffer[100] = {0};
  int clnt_sock =
      accept(serv_sock, (struct sockaddr *)&clnt_addr, &clnt_addr_size);
  sleep(10);
  printf("after sleep\n");
  int recv_len = recv(clnt_sock, buffer, 100, 0);
  send(clnt_sock, buffer, recv_len, 0);
  close(clnt_sock);
  close(serv_sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xde8(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x4d2,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x1e,%esi
call   10a0 <listen@plt>
movl   $0xc,-0x2c(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x94(%rbp)
mov    $0xa,%edi
call   10d0 <sleep@plt>
lea    0xd7e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x94(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x98(%rbp)
mov    -0x94(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0x98(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x94(%rbp),%edi
call   1080 <close@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    0x2e16(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
lea    0xdf0(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    %ebx,%edi
mov    $0x1e,%esi
call   10a0 <listen@plt>
movl   $0xc,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movl   $0x0,0x90(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10c0 <accept@plt>
mov    %eax,%ebp
mov    $0xa,%edi
call   10d0 <sleep@plt>
lea    0xd6d(%rip),%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [13 x i8] c"after sleep\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = load i32, i32* @IPPROTO_TCP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %2
%13 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 1234)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = load i32, i32* %2
%25 = call i32 @listen(i32 %24, i32 30)
store i32 12, i32* %5
%26 = bitcast [100 x i8]* %6 to i8*
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = call i32 @accept(i32 %27, %struct.sockaddr* %28, i32* %5)
store i32 %29, i32* %7
%30 = call i32 @sleep(i32 10)
%31 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* %7
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%34 = call i32 @recv(i32 %32, i8* %33, i32 100, i32 0)
store i32 %34, i32* %8
%35 = load i32, i32* %7
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%37 = load i32, i32* %8
%38 = call i32 @send(i32 %35, i8* %36, i32 %37, i32 0)
%39 = load i32, i32* %7
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %2
%42 = call i32 @close(i32 %41)
ret i32 0
}

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
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@str = [12 x i8] c"after sleep\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = bitcast %struct.sockaddr_in* %1 to i8*
%10 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = 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* %1, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = call i32 @htons(i32 1234)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%18 = call i32 @bind(i32 %8, %struct.sockaddr* %17, i32 12)
%19 = call i32 @listen(i32 %8, i32 30)
%20 = bitcast %struct.sockaddr_in* %2 to i8*
%21 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%23 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%24 = call i32 @accept(i32 %8, %struct.sockaddr* %23, i32* %3)
%25 = call i32 @sleep(i32 10)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%27 = call i32 @recv(i32 %24, i8* %22, i32 100, i32 0)
%28 = call i32 @send(i32 %24, i8* %22, i32 %27, i32 0)
%29 = call i32 @close(i32 %24)
%30 = call i32 @close(i32 %8)
ret i32 0
}