#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;
};
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ rbuf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EALREADY;
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, void *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int inet_pton(int /*<<< orphan*/, char *, void *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int);
scalar_t__ setnonblock(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int sd = socket(AF_INET, SOCK_STREAM, 0);
  if (sd < 0) {
    perror("socket()");
    return -1;
  }
  if (setnonblock(sd) < 0) {
    fprintf(stderr, "setnonblock() failed!\n");
    return -1;
  }
  struct sockaddr_in server_addr;
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(8080);
  if (inet_pton(AF_INET, "127.0.0.1", (void *)&server_addr.sin_addr) != 1) {
    perror("inet_pton()");
    return -1;
  }
  int ret = connect(sd, (void *)&server_addr, sizeof(server_addr));
  if (ret < 0 && errno != EINPROGRESS && errno != EALREADY) {
    perror("connect()");
    return -1;
  }
  char rbuf[1024], sbuf[1024] = "hello world";
  while (1) {
    int ret = write(sd, sbuf, 11);
    printf("ret=%d\n", ret);
    ret = read(sd, rbuf, sizeof(rbuf));
    rbuf[ret] = 0;
    printf("ret=%d %s\n", ret, rbuf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1207 <main+0x57>
lea    0xe0a(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1d6>
mov    -0x14(%rbp),%edi
call   10a0 <setnonblock@plt>
cmp    $0x0,%rax
jge    123a <main+0x8a>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1d6>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
lea    0xdb9(%rip),%rsi
call   1090 <inet_pton@plt>
cmp    $0x1,%eax
je     128d <main+0xdd>
lea    0xdae(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1d6>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12f7 <main+0x147>
mov    0x2d06(%rip),%rax
mov    (%rax),%rax
mov    0x2d24(%rip),%rcx
cmp    (%rcx),%rax
je     12f7 <main+0x147>
mov    0x2cec(%rip),%rax
mov    (%rax),%rax
mov    0x2cf2(%rip),%rcx
cmp    (%rcx),%rax
je     12f7 <main+0x147>
lea    0xd50(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1d6>
lea    -0x830(%rbp),%rdi
lea    0xd5b(%rip),%rsi
mov    $0x400,%edx
call   1080 <memcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    %eax,-0x834(%rbp)
mov    -0x834(%rbp),%esi
lea    0xd0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x834(%rbp)
movslq -0x834(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x834(%rbp),%esi
lea    -0x430(%rbp),%rdx
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    130f <main+0x15f>
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
mov    0x2e22(%rip),%rbx
mov    (%rbx),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12e8 <main+0x138>
mov    %eax,%ebp
mov    %eax,%edi
call   10a0 <setnonblock@plt>
test   %rax,%rax
js     12d1 <main+0x121>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
lea    0xe11(%rip),%rsi
mov    %rsp,%rdx
call   1090 <inet_pton@plt>
cmp    $0x1,%eax
jne    12f1 <main+0x141>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %eax,%eax
jns    1259 <main+0xa9>
mov    0x2d7e(%rip),%rax
mov    (%rax),%rax
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%rax
je     1259 <main+0xa9>
mov    0x2d78(%rip),%rcx
cmp    (%rcx),%rax
jne    12fa <main+0x14a>
lea    0xe00(%rip),%rsi
lea    0x410(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
call   1080 <memcpy@plt>
lea    0xdc4(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xdc0(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
movslq %eax,%rsi
movb   $0x0,0x10(%rsp,%rsi,1)
mov    %r12,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1290 <main+0xe0>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1306 <main+0x156>
lea    0xd11(%rip),%rdi
jmp    1301 <main+0x151>
lea    0xd32(%rip),%rdi
jmp    1301 <main+0x151>
lea    0xd35(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [9 x i8] c"socket()\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"setnonblock() failed!\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [12 x i8] c"inet_pton()\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@EALREADY = global i64 0
@.str.4 = [10 x i8] c"connect()\00"
@__const.main.sbuf = [1024 x i8] c"hello world\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.5 = [8 x i8] c"ret=%d\0A\00"
@.str.6 = [11 x i8] c"ret=%d %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
19: ; preds = %2
%20 = load i32, i32* %6
%21 = call i64 @setnonblock(i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
26: ; preds = %19
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @htons(i32 8080)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %29, i32* %30
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%33 = bitcast i32* %32 to i8*
%34 = call i32 @inet_pton(i32 %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
38: ; preds = %26
%39 = load i32, i32* %6
%40 = bitcast %struct.sockaddr_in* %7 to i8*
%41 = call i32 @connect(i32 %39, i8* %40, i32 12)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %54
44: ; preds = %38
%45 = load i64, i64* @errno
%46 = load i64, i64* @EINPROGRESS
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %44
%49 = load i64, i64* @errno
%50 = load i64, i64* @EALREADY
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %71
54: ; preds = %48, %44, %38
%55 = bitcast [1024 x i8]* %10 to i8*
br label %56
56: ; preds = %54, %56
%57 = load i32, i32* %6
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%59 = call i32 @write(i32 %57, i8* %58, i32 11)
store i32 %59, i32* %11
%60 = load i32, i32* %11
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %6
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%64 = call i32 @read(i32 %62, i8* %63, i32 1024)
store i32 %64, i32* %11
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %66
store i8 0, i8* %67
%68 = load i32, i32* %11
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%70 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %68, i8* %69)
br label %56
71: ; preds = %52, %36, %23, %17
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [9 x i8] c"socket()\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"setnonblock() failed!\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [12 x i8] c"inet_pton()\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@EALREADY = global i64 0
@.str.4 = [10 x i8] c"connect()\00"
@__const.main.sbuf = [1024 x i8] c"hello world\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.5 = [8 x i8] c"ret=%d\0A\00"
@.str.6 = [11 x i8] c"ret=%d %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %50
12: ; preds = %2
%13 = tail call i64 @setnonblock(i32 %8)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %50
18: ; preds = %12
%19 = bitcast %struct.sockaddr_in* %3 to i8*
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 8080)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* @AF_INET
%25 = call i32 @inet_pton(i32 %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %47
27: ; preds = %18
%28 = call i32 @connect(i32 %8, i8* %19, i32 12)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINPROGRESS
%33 = icmp eq i64 %31, %32
%34 = load i64, i64* @EALREADY
%35 = icmp eq i64 %31, %34
%36 = select i1 %33, i1 true, i1 %35
br i1 %36, label %37, label %47
37: ; preds = %30, %27
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
br label %40
40: ; preds = %40, %37
%41 = call i32 @write(i32 %8, i8* %39, i32 11)
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = call i32 @read(i32 %8, i8* %38, i32 1024)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %44
store i8 0, i8* %45
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %43, i8* %38)
br label %40
47: ; preds = %30, %18
%48 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %18 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %30 ]
%49 = call i32 @perror(i8* %48)
br label %50
50: ; preds = %47, %15, %10
ret i32 -1
}