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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  struct sockaddr_in stSockAddr;
  int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (-1 == SocketFD) {
    perror("can not create socket");
    exit(EXIT_FAILURE);
  }
  memset(&stSockAddr, 0, sizeof(stSockAddr));
  stSockAddr.sin_family = AF_INET;
  stSockAddr.sin_port = htons(1100);
  stSockAddr.sin_addr.s_addr = INADDR_ANY;
  if (-1 ==
      bind(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr))) {
    perror("error bind failed");
    close(SocketFD);
    exit(EXIT_FAILURE);
  }
  if (-1 == listen(SocketFD, 10)) {
    perror("error listen failed");
    close(SocketFD);
    exit(EXIT_FAILURE);
  }
  for (;;) {
    int ConnectFD = accept(SocketFD, NULL, NULL);
    if (0 > ConnectFD) {
      perror("error accept failed");
      close(SocketFD);
      exit(EXIT_FAILURE);
    }
    sleep(10);
    if (-1 == shutdown(ConnectFD, SHUT_RDWR)) {
      perror("can not shutdown socket");
      close(ConnectFD);
      exit(EXIT_FAILURE);
    }
    close(ConnectFD);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    120a <main+0x5a>
lea    0xe09(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x44c,%edi
call   1040 <htons@plt>
mov    %eax,-0xc(%rbp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1281 <main+0xd1>
lea    0xdb0(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   1070 <listen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12bf <main+0x10f>
lea    0xd84(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    12c4 <main+0x114>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10a0 <accept@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jle    1303 <main+0x153>
lea    0xd54(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    $0xa,%edi
call   10c0 <sleep@plt>
mov    -0x18(%rbp),%edi
mov    0x2cd9(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    134f <main+0x19f>
lea    0xd1c(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
jmp    12c4 <main+0x114>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
jne    11ee <main+0x3e>
lea    0xe1c(%rip),%rdi
call   1090 <perror@plt>
jmp    12c5 <main+0x115>
mov    %eax,%r14d
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0x44c,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    1248 <main+0x98>
lea    0xdd0(%rip),%rdi
jmp    12b8 <main+0x108>
mov    %r14d,%edi
mov    $0xa,%esi
call   1070 <listen@plt>
cmp    $0xffffffff,%eax
jne    1263 <main+0xb3>
lea    0xdc7(%rip),%rdi
jmp    12b8 <main+0x108>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <accept@plt>
test   %eax,%eax
js     12b1 <main+0x101>
mov    %eax,%ebp
mov    0x2d74(%rip),%rbx
nopl   0x0(%rax)
mov    $0xa,%edi
call   10c0 <sleep@plt>
mov    (%rbx),%esi
mov    %ebp,%edi
call   1030 <shutdown@plt>
cmp    $0xffffffff,%eax
je     12d3 <main+0x123>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1280 <main+0xd0>
lea    0xd84(%rip),%rdi
call   1090 <perror@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xd76(%rip),%rdi
call   1090 <perror@plt>
mov    %ebp,%edi
jmp    12c0 <main+0x110>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [22 x i8] c"can not create socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [18 x i8] c"error bind failed\00"
@.str.2 = [20 x i8] c"error listen failed\00"
@.str.3 = [20 x i8] c"error accept failed\00"
@SHUT_RDWR = global i32 0
@.str.4 = [24 x i8] c"can not shutdown socket\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = call i32 @socket(i32 %5, i32 %6, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 -1, %9
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 1100)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* %3
%25 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%26 = call i32 @bind(i32 %24, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i32 -1, %26
br i1 %27, label %28, label %34
28: ; preds = %15
%29 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* %3
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %15
%35 = load i32, i32* %3
%36 = call i32 @listen(i32 %35, i32 10)
%37 = icmp eq i32 -1, %36
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* %3
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %34
br label %45
45: ; preds = %68, %44
%46 = load i32, i32* %3
%47 = call i32 @accept(i32 %46, i32* null, i32* null)
store i32 %47, i32* %4
%48 = load i32, i32* %4
%49 = icmp sgt i32 0, %48
br i1 %49, label %50, label %56
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %3
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %45
%57 = call i32 @sleep(i32 10)
%58 = load i32, i32* %4
%59 = load i32, i32* @SHUT_RDWR
%60 = call i32 @shutdown(i32 %58, i32 %59)
%61 = icmp eq i32 -1, %60
br i1 %61, label %62, label %68
62: ; preds = %56
%63 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%64 = load i32, i32* %4
%65 = call i32 @close(i32 %64)
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %56
%69 = load i32, i32* %4
%70 = call i32 @close(i32 %69)
br label %45
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [22 x i8] c"can not create socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [18 x i8] c"error bind failed\00"
@.str.2 = [20 x i8] c"error listen failed\00"
@.str.3 = [20 x i8] c"error accept failed\00"
@SHUT_RDWR = global i32 0
@.str.4 = [24 x i8] c"can not shutdown socket\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = load i32, i32* @IPPROTO_TCP
%6 = tail call i32 @socket(i32 %3, i32 %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 1100)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i32 @bind(i32 %6, %struct.sockaddr* %20, i32 12)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %12
%24 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @close(i32 %6)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %12
%29 = call i32 @listen(i32 %6, i32 10)
%30 = icmp eq i32 %29, -1
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = call i32 @accept(i32 %6, i32* null, i32* null)
%33 = icmp slt i32 %32, 0
br i1 %33, label %39, label %44
34: ; preds = %28
%35 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @close(i32 %6)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %55, %31
%40 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @close(i32 %6)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %31, %55
%45 = phi i32 [ %57, %55 ], [ %32, %31 ]
%46 = call i32 @sleep(i32 10)
%47 = load i32, i32* @SHUT_RDWR
%48 = call i32 @shutdown(i32 %45, i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @close(i32 %45)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %44
%56 = call i32 @close(i32 %45)
%57 = call i32 @accept(i32 %6, i32* null, i32* null)
%58 = icmp slt i32 %57, 0
br i1 %58, label %39, label %44
}