#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_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ keepInterval;
typedef int /*<<< orphan*/ keepIdle;
typedef int /*<<< orphan*/ keepCount;
typedef int /*<<< orphan*/ keepAlive;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SOL_TCP;
int /*<<< orphan*/ SO_KEEPALIVE;
int /*<<< orphan*/ TCP_KEEPCNT;
int /*<<< orphan*/ TCP_KEEPIDLE;
int /*<<< orphan*/ TCP_KEEPINTVL;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              void *, int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sockfd, n;
  char recvline[4096], sendline[4096];
  struct sockaddr_in servaddr;
  if (argc != 2 && argc != 3) {
    printf("usage: tcpclient <ipaddress> <lable>\n");
    printf("lable:                              \n");
    printf("       L1: shutdown. \n");
    printf("       L2: close. \n");
    printf("       L3: shutdown->close. \n");
    exit(0);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("create socket error: %s(errno: %d) \n", strerror(errno), errno);
    exit(0);
  }
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(8888);
  if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) {
    printf("inet_pton error for %s\n", argv[1]);
    exit(0);
  }
  int keepAlive = 1;
  int keepIdle = 60;
  int keepInterval = 5;
  int keepCount = 3;
  setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepAlive,
             sizeof(keepAlive));
  setsockopt(sockfd, SOL_TCP, TCP_KEEPIDLE, (void *)&keepIdle,
             sizeof(keepIdle));
  setsockopt(sockfd, SOL_TCP, TCP_KEEPINTVL, (void *)&keepInterval,
             sizeof(keepInterval));
  setsockopt(sockfd, SOL_TCP, TCP_KEEPCNT, (void *)&keepCount,
             sizeof(keepCount));
  if (3 <= argc) {
    if (0 == strcmp(argv[2], "L1"))
      goto L1;
    if (0 == strcmp(argv[2], "L2"))
      goto L2;
    if (0 == strcmp(argv[2], "L3"))
      goto L3;
  }
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    printf("connect error: %s(errno: %d) \n", strerror(errno), errno);
    exit(0);
  }
  printf("send msg to server: \n");
  fgets(sendline, 4096, stdin);
  if (send(sockfd, sendline, strlen(sendline), 0) < 0) {
    printf("send msg error: %s(errno: %d) \n", strerror(errno), errno);
    exit(0);
  }
  close(sockfd);
  goto L4;
L1:
  shutdown(sockfd, SHUT_RDWR);
  goto L4;
L2:
  close(sockfd);
  goto L4;
L3:
  shutdown(sockfd, SHUT_RDWR);
  close(sockfd);
  goto L4;
L4:
  sleep(120);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     127a <main+0x7a>
cmpl   $0x3,-0x8(%rbp)
je     127a <main+0x7a>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12ce <main+0xce>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
mov    0x2ce9(%rip),%rax
mov    (%rax),%edx
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x2030(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2028(%rbp)
mov    $0x22b8,%edi
call   1060 <htons@plt>
mov    %eax,-0x202c(%rbp)
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x2030(%rbp),%rdx
call   10d0 <inet_pton@plt>
cmp    $0x0,%rax
jg     1344 <main+0x144>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
movl   $0x1,-0x2034(%rbp)
movl   $0x3c,-0x2038(%rbp)
movl   $0x5,-0x203c(%rbp)
movl   $0x3,-0x2040(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c6a(%rip),%rax
mov    (%rax),%esi
mov    0x2c09(%rip),%rax
mov    (%rax),%edx
lea    -0x2034(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
mov    0x2c2b(%rip),%rax
mov    (%rax),%esi
mov    0x2bf2(%rip),%rax
mov    (%rax),%edx
lea    -0x2038(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
mov    0x2c04(%rip),%rax
mov    (%rax),%esi
mov    0x2bf3(%rip),%rax
mov    (%rax),%edx
lea    -0x203c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
mov    0x2bdd(%rip),%rax
mov    (%rax),%esi
mov    0x2bc4(%rip),%rax
mov    (%rax),%edx
lea    -0x2040(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
jg     1490 <main+0x290>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xcad(%rip),%rsi
call   10c0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    143d <main+0x23d>
jmp    1584 <main+0x384>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc89(%rip),%rsi
call   10c0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1464 <main+0x264>
jmp    159a <main+0x39a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xc65(%rip),%rsi
call   10c0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    148b <main+0x28b>
jmp    15a7 <main+0x3a7>
jmp    1490 <main+0x290>
mov    -0x14(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    14dd <main+0x2dd>
mov    0x2aeb(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
mov    0x2ada(%rip),%rax
mov    (%rax),%edx
lea    0xc0c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xc16(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x2020(%rbp),%rdi
mov    0x2ad7(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   10b0 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x204c(%rbp)
lea    -0x2020(%rbp),%rax
mov    %rax,-0x2048(%rbp)
lea    -0x2020(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x204c(%rbp),%edi
mov    -0x2048(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    1577 <main+0x377>
mov    0x2a51(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
mov    0x2a40(%rip),%rax
mov    (%rax),%edx
lea    0xba7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
jmp    15c0 <main+0x3c0>
mov    -0x14(%rbp),%edi
mov    0x2a62(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
jmp    15c0 <main+0x3c0>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
jmp    15c0 <main+0x3c0>
mov    -0x14(%rbp),%edi
mov    0x2a3f(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    $0x78,%edi
call   1110 <sleep@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1020,%rsp
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1273 <main+0x63>
mov    %rsi,%r12
mov    %edi,%ebp
mov    0x2da3(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
jns    12b6 <main+0xa6>
mov    0x2d4e(%rip),%rbx
mov    (%rbx),%edi
call   1110 <strerror@plt>
mov    (%rbx),%edx
lea    0xd9e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x22b8,%edi
call   1070 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%rbx),%edi
mov    0x8(%r12),%rsi
mov    %r15,%rdx
call   10e0 <inet_pton@plt>
test   %rax,%rax
jg     130f <main+0xff>
mov    0x8(%r12),%rsi
lea    0xd24(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
movl   $0x1,0xc(%rsp)
movl   $0x3c,0x8(%rsp)
movl   $0x5,0x4(%rsp)
movl   $0x3,(%rsp)
mov    0x2cab(%rip),%rax
mov    (%rax),%esi
mov    0x2c4a(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    0x2c6e(%rip),%rbx
mov    (%rbx),%esi
mov    0x2c35(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    (%rbx),%esi
mov    0x2c3f(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    (%rbx),%esi
mov    0x2c19(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x3,%ebp
jb     1429 <main+0x219>
mov    0x10(%r12),%rdi
lea    0xc7a(%rip),%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    13e3 <main+0x1d3>
mov    0x2c1c(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1050 <shutdown@plt>
jmp    14c3 <main+0x2b3>
mov    0x10(%r12),%rdi
lea    0xc51(%rip),%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     14bb <main+0x2ab>
mov    0x10(%r12),%rdi
lea    0xc3a(%rip),%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
jne    1429 <main+0x219>
mov    0x2bd6(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1050 <shutdown@plt>
jmp    14bb <main+0x2ab>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1100 <connect@plt>
test   %rax,%rax
jns    145c <main+0x24c>
mov    0x2b59(%rip),%rbx
mov    (%rbx),%edi
call   1110 <strerror@plt>
mov    (%rbx),%edx
lea    0xbef(%rip),%rdi
jmp    1262 <main+0x52>
lea    0xc22(%rip),%rdi
call   1030 <puts@plt>
mov    0x2b61(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
test   %rax,%rax
jns    14bb <main+0x2ab>
mov    0x2afa(%rip),%rbx
mov    (%rbx),%edi
call   1110 <strerror@plt>
mov    (%rbx),%edx
lea    0xbaf(%rip),%rdi
jmp    1262 <main+0x52>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    $0x78,%edi
call   1120 <sleep@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [38 x i8] c"usage: tcpclient <ipaddress> <lable>\0A\00"
@.str.1 = [38 x i8] c"lable: \0A\00"
@.str.2 = [23 x i8] c" L1: shutdown. \0A\00"
@.str.3 = [20 x i8] c" L2: close. \0A\00"
@.str.4 = [30 x i8] c" L3: shutdown->close. \0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [37 x i8] c"create socket error: %s(errno: %d) \0A\00"
@errno = global i32 0
@.str.6 = [24 x i8] c"inet_pton error for %s\0A\00"
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@SOL_TCP = global i32 0
@TCP_KEEPIDLE = global i32 0
@TCP_KEEPINTVL = global i32 0
@TCP_KEEPCNT = global i32 0
@.str.7 = [3 x i8] c"L1\00"
@.str.8 = [3 x i8] c"L2\00"
@.str.9 = [3 x i8] c"L3\00"
@.str.10 = [31 x i8] c"connect error: %s(errno: %d) \0A\00"
@.str.11 = [22 x i8] c"send msg to server: \0A\00"
@stdin = global i32 0
@.str.12 = [32 x i8] c"send msg error: %s(errno: %d) \0A\00"
@SHUT_RDWR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca [4096 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %27
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 3
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %17, %2
%28 = load i32, i32* @AF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = load i32, i32* @errno
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %34, i32 %35)
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %27
%39 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %40, i32* %41
%42 = call i32 @htons(i32 8888)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %42, i32* %43
%44 = load i32, i32* @AF_INET
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%49 = call i64 @inet_pton(i32 %44, i8* %47, i32* %48)
%50 = icmp sle i64 %49, 0
br i1 %50, label %51, label %57
51: ; preds = %38
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 0)
unreachable
57: ; preds = %38
store i32 1, i32* %11
store i32 60, i32* %12
store i32 5, i32* %13
store i32 3, i32* %14
%58 = load i32, i32* %6
%59 = load i32, i32* @SOL_SOCKET
%60 = load i32, i32* @SO_KEEPALIVE
%61 = bitcast i32* %11 to i8*
%62 = call i32 @setsockopt(i32 %58, i32 %59, i32 %60, i8* %61, i32 4)
%63 = load i32, i32* %6
%64 = load i32, i32* @SOL_TCP
%65 = load i32, i32* @TCP_KEEPIDLE
%66 = bitcast i32* %12 to i8*
%67 = call i32 @setsockopt(i32 %63, i32 %64, i32 %65, i8* %66, i32 4)
%68 = load i32, i32* %6
%69 = load i32, i32* @SOL_TCP
%70 = load i32, i32* @TCP_KEEPINTVL
%71 = bitcast i32* %13 to i8*
%72 = call i32 @setsockopt(i32 %68, i32 %69, i32 %70, i8* %71, i32 4)
%73 = load i32, i32* %6
%74 = load i32, i32* @SOL_TCP
%75 = load i32, i32* @TCP_KEEPCNT
%76 = bitcast i32* %14 to i8*
%77 = call i32 @setsockopt(i32 %73, i32 %74, i32 %75, i8* %76, i32 4)
%78 = load i32, i32* %4
%79 = icmp sle i32 3, %78
br i1 %79, label %80, label %102
80: ; preds = %57
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 2
%83 = load i8*, i8** %82
%84 = call i64 @strcmp(i8* %83, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%85 = icmp eq i64 0, %84
br i1 %85, label %86, label %87
86: ; preds = %80
br label %133
87: ; preds = %80
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 2
%90 = load i8*, i8** %89
%91 = call i64 @strcmp(i8* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%92 = icmp eq i64 0, %91
br i1 %92, label %93, label %94
93: ; preds = %87
br label %137
94: ; preds = %87
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 2
%97 = load i8*, i8** %96
%98 = call i64 @strcmp(i8* %97, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%99 = icmp eq i64 0, %98
br i1 %99, label %100, label %101
100: ; preds = %94
br label %140
101: ; preds = %94
br label %102
102: ; preds = %101, %57
%103 = load i32, i32* %6
%104 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%105 = call i64 @connect(i32 %103, %struct.sockaddr* %104, i32 12)
%106 = icmp slt i64 %105, 0
br i1 %106, label %107, label %113
107: ; preds = %102
%108 = load i32, i32* @errno
%109 = call i8* @strerror(i32 %108)
%110 = load i32, i32* @errno
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i8* %109, i32 %110)
%112 = call i32 @exit(i32 0)
unreachable
113: ; preds = %102
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
%115 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%116 = load i32, i32* @stdin
%117 = call i32 @fgets(i8* %115, i32 4096, i32 %116)
%118 = load i32, i32* %6
%119 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%120 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%121 = call i32 @strlen(i8* %120)
%122 = call i64 @send(i32 %118, i8* %119, i32 %121, i32 0)
%123 = icmp slt i64 %122, 0
br i1 %123, label %124, label %130
124: ; preds = %113
%125 = load i32, i32* @errno
%126 = call i8* @strerror(i32 %125)
%127 = load i32, i32* @errno
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %126, i32 %127)
%129 = call i32 @exit(i32 0)
unreachable
130: ; preds = %113
%131 = load i32, i32* %6
%132 = call i32 @close(i32 %131)
br label %146
133: ; preds = %86
%134 = load i32, i32* %6
%135 = load i32, i32* @SHUT_RDWR
%136 = call i32 @shutdown(i32 %134, i32 %135)
br label %146
137: ; preds = %93
%138 = load i32, i32* %6
%139 = call i32 @close(i32 %138)
br label %146
140: ; preds = %100
%141 = load i32, i32* %6
%142 = load i32, i32* @SHUT_RDWR
%143 = call i32 @shutdown(i32 %141, i32 %142)
%144 = load i32, i32* %6
%145 = call i32 @close(i32 %144)
br label %146
146: ; preds = %140, %137, %133, %130
%147 = call i32 @sleep(i32 120)
%148 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [37 x i8] c"create socket error: %s(errno: %d) \0A\00"
@errno = global i32 0
@.str.6 = [24 x i8] c"inet_pton error for %s\0A\00"
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@SOL_TCP = global i32 0
@TCP_KEEPIDLE = global i32 0
@TCP_KEEPINTVL = global i32 0
@TCP_KEEPCNT = global i32 0
@.str.7 = [3 x i8] c"L1\00"
@.str.8 = [3 x i8] c"L2\00"
@.str.9 = [3 x i8] c"L3\00"
@.str.10 = [31 x i8] c"connect error: %s(errno: %d) \0A\00"
@stdin = global i32 0
@.str.12 = [32 x i8] c"send msg error: %s(errno: %d) \0A\00"
@SHUT_RDWR = global i32 0
@str = [21 x i8] c"send msg to server: \00"
@str.13 = [37 x i8] c"usage: tcpclient <ipaddress> <lable>\00"
@str.14 = [37 x i8] c"lable: \00"
@str.15 = [22 x i8] c" L1: shutdown. \00"
@str.16 = [19 x i8] c" L2: close. \00"
@str.17 = [29 x i8] c" L3: shutdown->close. \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = and i32 %0, -2
%12 = icmp eq i32 %11, 2
br i1 %12, label %20, label %13
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.13, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.14, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.15, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.16, i64 0, i64 0))
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.17, i64 0, i64 0))
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = load i32, i32* @errno
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %27, i32 %28)
%30 = tail call i32 @exit(i32 0)
unreachable
31: ; preds = %20
%32 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %33, i32* %34
%35 = call i32 @htons(i32 8888)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %35, i32* %36
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds i8*, i8** %1, i64 1
%39 = load i8*, i8** %38
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%41 = call i64 @inet_pton(i32 %37, i8* %39, i32* %40)
%42 = icmp slt i64 %41, 1
br i1 %42, label %43, label %47
43: ; preds = %31
%44 = load i8*, i8** %38
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %31
%48 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%49 = bitcast i32* %6 to i8*
store i32 60, i32* %6
%50 = bitcast i32* %7 to i8*
store i32 5, i32* %7
%51 = bitcast i32* %8 to i8*
store i32 3, i32* %8
%52 = load i32, i32* @SOL_SOCKET
%53 = load i32, i32* @SO_KEEPALIVE
%54 = call i32 @setsockopt(i32 %23, i32 %52, i32 %53, i8* %48, i32 4)
%55 = load i32, i32* @SOL_TCP
%56 = load i32, i32* @TCP_KEEPIDLE
%57 = call i32 @setsockopt(i32 %23, i32 %55, i32 %56, i8* %49, i32 4)
%58 = load i32, i32* @SOL_TCP
%59 = load i32, i32* @TCP_KEEPINTVL
%60 = call i32 @setsockopt(i32 %23, i32 %58, i32 %59, i8* %50, i32 4)
%61 = load i32, i32* @SOL_TCP
%62 = load i32, i32* @TCP_KEEPCNT
%63 = call i32 @setsockopt(i32 %23, i32 %61, i32 %62, i8* %51, i32 4)
%64 = icmp ugt i32 %0, 2
br i1 %64, label %65, label %78
65: ; preds = %47
%66 = getelementptr inbounds i8*, i8** %1, i64 2
%67 = load i8*, i8** %66
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %103, label %70
70: ; preds = %65
%71 = load i8*, i8** %66
%72 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %106, label %74
74: ; preds = %70
%75 = load i8*, i8** %66
%76 = call i64 @strcmp(i8* %75, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %108, label %78
78: ; preds = %74, %47
%79 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%80 = call i64 @connect(i32 %23, %struct.sockaddr* %79, i32 12)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %88
82: ; preds = %78
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = load i32, i32* @errno
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i8* %84, i32 %85)
%87 = call i32 @exit(i32 0)
unreachable
88: ; preds = %78
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%90 = load i32, i32* @stdin
%91 = call i32 @fgets(i8* %9, i32 4096, i32 %90)
%92 = call i32 @strlen(i8* %9)
%93 = call i64 @send(i32 %23, i8* %9, i32 %92, i32 0)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %101
95: ; preds = %88
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = load i32, i32* @errno
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %97, i32 %98)
%100 = call i32 @exit(i32 0)
unreachable
101: ; preds = %88
%102 = call i32 @close(i32 %23)
br label %112
103: ; preds = %65
%104 = load i32, i32* @SHUT_RDWR
%105 = call i32 @shutdown(i32 %23, i32 %104)
br label %112
106: ; preds = %70
%107 = call i32 @close(i32 %23)
br label %112
108: ; preds = %74
%109 = load i32, i32* @SHUT_RDWR
%110 = call i32 @shutdown(i32 %23, i32 %109)
%111 = call i32 @close(i32 %23)
br label %112
112: ; preds = %108, %106, %103, %101
%113 = call i32 @sleep(i32 120)
%114 = call i32 @exit(i32 0)
unreachable
}