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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int errno;
int getsockname(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main() {
  int client_fd = socket(AF_INET, SOCK_STREAM, 0);
  if (-1 == client_fd) {
    printf("socket failed, code:%d, msg:%s\n", errno, strerror(errno));
    return -1;
  }
  struct sockaddr_in client_addr;
  bzero(&client_addr, sizeof(client_addr));
  client_addr.sin_port = htons(10005);
  client_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  client_addr.sin_family = AF_INET;
  int ret =
      connect(client_fd, (struct sockaddr *)&client_addr, sizeof(client_addr));
  if (-1 == ret) {
    printf("connect failed, code:%d, msg:%s\n", errno, strerror(errno));
    return -1;
  }
  socklen_t len = 0;
  ret = getsockname(client_fd, (struct sockaddr *)&client_addr, &len);
  if (-1 == ret) {
    printf("getsockname failed, code:%d, msg:%s\n", errno, strerror(errno));
    return -1;
  }
  int loop = 0;
  char read_buf[1024];
  char send_msg[1024];
  while (loop < 5) {
    loop++;
    send_msg[0] = '\0';
    int write_len = write(client_fd, send_msg, strlen(send_msg));
    if (-1 == write_len) {
      printf("write failed, code:%d, msg:%s\n", errno, strerror(errno));
      return -1;
    }
    int read_len = read(client_fd, read_buf, 1024);
    read_buf[read_len] = 0;
    if (0 == read_len) {
      printf("i read 0 byte, code:%d, msg:%s\n", errno, strerror(errno));
      return -1;
    }
    printf("%s\n", read_buf);
    sleep(5);
  }
  printf("i am here!%d\n", ret);
  close(client_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    124c <main+0x7c>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x83c(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x83c(%rbp),%esi
mov    %rax,%rdx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b6 <main+0x2e6>
lea    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    $0x2715,%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
lea    0xdb2(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    12e4 <main+0x114>
mov    0x2d25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x840(%rbp)
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x840(%rbp),%esi
mov    %rax,%rdx
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b6 <main+0x2e6>
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10b0 <getsockname@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    134c <main+0x17c>
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x844(%rbp)
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x844(%rbp),%esi
mov    %rax,%rdx
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b6 <main+0x2e6>
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    1496 <main+0x2c6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movb   $0x0,-0x830(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x854(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x850(%rbp)
lea    -0x830(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x854(%rbp),%edi
mov    -0x850(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x834(%rbp)
mov    $0xffffffff,%eax
cmp    -0x834(%rbp),%eax
jne    13fb <main+0x22b>
mov    0x2c0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x858(%rbp)
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x858(%rbp),%esi
mov    %rax,%rdx
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b6 <main+0x2e6>
mov    -0x8(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x838(%rbp)
movslq -0x838(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
xor    %eax,%eax
cmp    -0x838(%rbp),%eax
jne    1472 <main+0x2a2>
mov    0x2b97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x85c(%rbp)
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x85c(%rbp),%esi
mov    %rax,%rdx
lea    0xc30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b6 <main+0x2e6>
lea    -0x430(%rbp),%rsi
lea    0xbec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x5,%edi
call   10e0 <sleep@plt>
jmp    1353 <main+0x183>
mov    -0x1c(%rbp),%esi
lea    0xc0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x828,%rsp
mov    0x2df4(%rip),%rbx
mov    (%rbx),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     1496 <main+0x2b6>
mov    %eax,%r15d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    $0x2715,%edi
call   1060 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0xde7(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     14af <main+0x2cf>
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r15d,%edi
call   10c0 <getsockname@plt>
cmp    $0xffffffff,%eax
je     14e1 <main+0x301>
mov    %eax,%r14d
movb   $0x0,0x420(%rsp)
lea    0x420(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     14c8 <main+0x2e8>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1090 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
test   %eax,%eax
je     14fa <main+0x31a>
lea    0x20(%rsp),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10f0 <sleep@plt>
movb   $0x0,0x420(%rsp)
lea    0x420(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     14c8 <main+0x2e8>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1090 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
test   %eax,%eax
je     14fa <main+0x31a>
lea    0x20(%rsp),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10f0 <sleep@plt>
movb   $0x0,0x420(%rsp)
lea    0x420(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     14c8 <main+0x2e8>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1090 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
test   %eax,%eax
je     14fa <main+0x31a>
lea    0x20(%rsp),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10f0 <sleep@plt>
movb   $0x0,0x420(%rsp)
lea    0x420(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     14c8 <main+0x2e8>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1090 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
test   %eax,%eax
je     14fa <main+0x31a>
lea    0x20(%rsp),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10f0 <sleep@plt>
movb   $0x0,0x420(%rsp)
lea    0x420(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     14c8 <main+0x2e8>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1090 <read@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
test   %eax,%eax
je     14fa <main+0x31a>
lea    0x20(%rsp),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10f0 <sleep@plt>
lea    0xc32(%rip),%rdi
xor    %ebp,%ebp
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   1080 <close@plt>
jmp    1522 <main+0x342>
mov    0x2b33(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xb53(%rip),%rdi
jmp    1511 <main+0x331>
mov    0x2b1a(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xb64(%rip),%rdi
jmp    1511 <main+0x331>
mov    0x2b01(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xb91(%rip),%rdi
jmp    1511 <main+0x331>
mov    0x2ae8(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xb53(%rip),%rdi
jmp    1511 <main+0x331>
mov    0x2acf(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xb7e(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r14
pop    %r15
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
@.str = [32 x i8] c"socket failed, code:%d, msg:%s\0A\00"
@errno = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [33 x i8] c"connect failed, code:%d, msg:%s\0A\00"
@.str.3 = [37 x i8] c"getsockname failed, code:%d, msg:%s\0A\00"
@.str.4 = [31 x i8] c"write failed, code:%d, msg:%s\0A\00"
@.str.5 = [32 x i8] c"i read 0 byte, code:%d, msg:%s\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [14 x i8] c"i am here!%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp eq i32 -1, %14
br i1 %15, label %16, label %21
16: ; preds = %0
%17 = load i32, i32* @errno
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %19)
store i32 -1, i32* %1
br label %94
21: ; preds = %0
%22 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%23 = call i32 @htons(i32 10005)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %28, i32* %29
%30 = load i32, i32* %2
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%32 = call i32 @connect(i32 %30, %struct.sockaddr* %31, i32 12)
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = icmp eq i32 -1, %33
br i1 %34, label %35, label %40
35: ; preds = %21
%36 = load i32, i32* @errno
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %36, i8* %38)
store i32 -1, i32* %1
br label %94
40: ; preds = %21
store i32 0, i32* %5
%41 = load i32, i32* %2
%42 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%43 = call i32 @getsockname(i32 %41, %struct.sockaddr* %42, i32* %5)
store i32 %43, i32* %4
%44 = load i32, i32* %4
%45 = icmp eq i32 -1, %44
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = load i32, i32* @errno
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %47, i8* %49)
store i32 -1, i32* %1
br label %94
51: ; preds = %40
store i32 0, i32* %6
br label %52
52: ; preds = %85, %51
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 5
br i1 %54, label %55, label %89
55: ; preds = %52
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8 0, i8* %58
%59 = load i32, i32* %2
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = call i32 @write(i32 %59, i8* %60, i32 %62)
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = icmp eq i32 -1, %64
br i1 %65, label %66, label %71
66: ; preds = %55
%67 = load i32, i32* @errno
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %67, i8* %69)
store i32 -1, i32* %1
br label %94
71: ; preds = %55
%72 = load i32, i32* %2
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%74 = call i32 @read(i32 %72, i8* %73, i32 1024)
store i32 %74, i32* %10
%75 = load i32, i32* %10
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %76
store i8 0, i8* %77
%78 = load i32, i32* %10
%79 = icmp eq i32 0, %78
br i1 %79, label %80, label %85
80: ; preds = %71
%81 = load i32, i32* @errno
%82 = load i32, i32* @errno
%83 = call i8* @strerror(i32 %82)
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %81, i8* %83)
store i32 -1, i32* %1
br label %94
85: ; preds = %71
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %86)
%88 = call i32 @sleep(i32 5)
br label %52
89: ; preds = %52
%90 = load i32, i32* %4
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %90)
%92 = load i32, i32* %2
%93 = call i32 @close(i32 %92)
store i32 0, i32* %1
br label %94
94: ; preds = %89, %80, %66, %46, %35, %16
%95 = load i32, i32* %1
ret i32 %95
}

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
@.str = [32 x i8] c"socket failed, code:%d, msg:%s\0A\00"
@errno = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [33 x i8] c"connect failed, code:%d, msg:%s\0A\00"
@.str.3 = [37 x i8] c"getsockname failed, code:%d, msg:%s\0A\00"
@.str.4 = [31 x i8] c"write failed, code:%d, msg:%s\0A\00"
@.str.5 = [32 x i8] c"i read 0 byte, code:%d, msg:%s\0A\00"
@.str.7 = [14 x i8] c"i am here!%d\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %11)
br label %111
13: ; preds = %0
%14 = bitcast %struct.sockaddr_in* %1 to i8*
%15 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%16 = tail call i32 @htons(i32 10005)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %16, i32* %17
%18 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = call i32 @connect(i32 %7, %struct.sockaddr* %22, i32 12)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %13
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %26, i8* %27)
br label %109
29: ; preds = %13
%30 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%31 = call i32 @getsockname(i32 %7, %struct.sockaddr* %22, i32* %2)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %34, i8* %35)
br label %107
37: ; preds = %29
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8 0, i8* %39
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @write(i32 %7, i8* %39, i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %89, %78, %67, %56, %37
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %44, i8* %45)
br label %105
47: ; preds = %37
%48 = call i32 @read(i32 %7, i8* %38, i32 1024)
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %49
store i8 0, i8* %50
%51 = icmp eq i32 %48, 0
br i1 %51, label %52, label %56
52: ; preds = %95, %84, %73, %62, %47
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %53, i8* %54)
br label %105
56: ; preds = %47
%57 = call i32 @puts(i8* %38)
%58 = call i32 @sleep(i32 5)
store i8 0, i8* %39
%59 = call i32 @strlen(i8* %39)
%60 = call i32 @write(i32 %7, i8* %39, i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %43, label %62
62: ; preds = %56
%63 = call i32 @read(i32 %7, i8* %38, i32 1024)
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %64
store i8 0, i8* %65
%66 = icmp eq i32 %63, 0
br i1 %66, label %52, label %67
67: ; preds = %62
%68 = call i32 @puts(i8* %38)
%69 = call i32 @sleep(i32 5)
store i8 0, i8* %39
%70 = call i32 @strlen(i8* %39)
%71 = call i32 @write(i32 %7, i8* %39, i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %43, label %73
73: ; preds = %67
%74 = call i32 @read(i32 %7, i8* %38, i32 1024)
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %75
store i8 0, i8* %76
%77 = icmp eq i32 %74, 0
br i1 %77, label %52, label %78
78: ; preds = %73
%79 = call i32 @puts(i8* %38)
%80 = call i32 @sleep(i32 5)
store i8 0, i8* %39
%81 = call i32 @strlen(i8* %39)
%82 = call i32 @write(i32 %7, i8* %39, i32 %81)
%83 = icmp eq i32 %82, -1
br i1 %83, label %43, label %84
84: ; preds = %78
%85 = call i32 @read(i32 %7, i8* %38, i32 1024)
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %86
store i8 0, i8* %87
%88 = icmp eq i32 %85, 0
br i1 %88, label %52, label %89
89: ; preds = %84
%90 = call i32 @puts(i8* %38)
%91 = call i32 @sleep(i32 5)
store i8 0, i8* %39
%92 = call i32 @strlen(i8* %39)
%93 = call i32 @write(i32 %7, i8* %39, i32 %92)
%94 = icmp eq i32 %93, -1
br i1 %94, label %43, label %95
95: ; preds = %89
%96 = call i32 @read(i32 %7, i8* %38, i32 1024)
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %97
store i8 0, i8* %98
%99 = icmp eq i32 %96, 0
br i1 %99, label %52, label %100
100: ; preds = %95
%101 = call i32 @puts(i8* %38)
%102 = call i32 @sleep(i32 5)
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %31)
%104 = call i32 @close(i32 %7)
br label %105
105: ; preds = %52, %43, %100
%106 = phi i32 [ 0, %100 ], [ -1, %43 ], [ -1, %52 ]
br label %107
107: ; preds = %105, %33
%108 = phi i32 [ -1, %33 ], [ %106, %105 ]
br label %109
109: ; preds = %107, %25
%110 = phi i32 [ -1, %25 ], [ %108, %107 ]
br label %111
111: ; preds = %109, %9
%112 = phi i32 [ -1, %9 ], [ %110, %109 ]
ret i32 %112
}