#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;
};
struct msghdr {
  int msg_iovlen;
  struct iovec *msg_iov;
};
struct iovec {
  char *iov_base;
  int iov_len;
};
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ iovec_buf2;
typedef int /*<<< orphan*/ iovec_buf1;
typedef int /*<<< orphan*/ iovec_buf0;
typedef int /*<<< orphan*/ iovec;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct msghdr *, char, int);
int recvmsg(int, struct msghdr *, int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int main(void) {
  int sock;
  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    fprintf(stderr, "socket() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_port = htons(8000);
  inet_aton("127.0.0.1", &addr.sin_addr);
  if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    fprintf(stderr, "connect() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  char *req = "GET / HTTP/1.0\r\n\r\n";
  send(sock, req, sizeof(char) * strlen(req), 0);
  char iovec_buf0[20];
  char iovec_buf1[30];
  char iovec_buf2[40];
  struct iovec iovec[3];
  iovec[0].iov_base = iovec_buf0;
  iovec[0].iov_len = sizeof(iovec_buf0);
  iovec[1].iov_base = iovec_buf1;
  iovec[1].iov_len = sizeof(iovec_buf1);
  iovec[2].iov_base = iovec_buf2;
  iovec[2].iov_len = sizeof(iovec_buf2);
  struct msghdr msg;
  memset(&msg, '\0', sizeof(msg));
  msg.msg_iov = iovec;
  msg.msg_iovlen = sizeof(iovec) / sizeof(struct iovec);
  if (recvmsg(sock, &msg, -1) != -1)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1221 <main+0x81>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd4(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0xd4(%rbp),%edi
mov    %rax,%rdx
lea    0xdf5(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1393 <main+0x1f3>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rsi
lea    0xdd1(%rip),%rdi
call   1080 <inet_aton@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    12a8 <main+0x108>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd8(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0xd8(%rbp),%edi
mov    %rax,%rdx
lea    0xd8e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1393 <main+0x1f3>
lea    0xd88(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xe4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xe4(%rbp),%edi
mov    -0xe0(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0xc0(%rbp)
movl   $0x14,-0xb8(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xb0(%rbp)
movl   $0x1e,-0xa8(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
movl   $0x28,-0x98(%rbp)
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0xc0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
movl   $0x3,-0xd0(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0xffffffff,%edx
call   1090 <recvmsg@plt>
cmp    $0xffffffff,%eax
je     1387 <main+0x1e7>
mov    0x2c3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1393 <main+0x1f3>
mov    0x2c22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
mov    0x2e37(%rip),%r14
mov    (%r14),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12ad <main+0x10d>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe25(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1080 <inet_aton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     12cd <main+0x12d>
lea    0xe1c(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0x50(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x14,0x28(%rsp)
lea    0x70(%rsp),%rax
mov    %rax,0x30(%rsp)
movl   $0x1e,0x38(%rsp)
lea    0x90(%rsp),%rax
mov    %rax,0x40(%rsp)
movl   $0x28,0x48(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0x20(%rsp),%rax
mov    %rax,0x18(%rsp)
movl   $0x3,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xffffffff,%edx
call   1090 <recvmsg@plt>
cmp    $0xffffffff,%eax
jne    12f5 <main+0x155>
mov    0x2d05(%rip),%rax
jmp    12fc <main+0x15c>
mov    0x2d1c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd35(%rip),%rsi
jmp    12eb <main+0x14b>
mov    0x2cfc(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd35(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i32, %struct.iovec* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"socket() failed: %s\0A.\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [23 x i8] c"connect() failed: %s\0A.\00"
@.str.3 = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i8*
%5 = alloca [20 x i8]
%6 = alloca [30 x i8]
%7 = alloca [40 x i8]
%8 = alloca [3 x %struct.iovec]
%9 = alloca %struct.msghdr
store i32 0, i32* %1
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = load i32, i32* @IPPROTO_TCP
%13 = call i32 @socket(i32 %10, i32 %11, i32 %12)
store i32 %13, i32* %2
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %1
br label %73
21: ; preds = %0
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 8000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%27 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %26)
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i64 @connect(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %21
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
store i32 %37, i32* %1
br label %73
38: ; preds = %21
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %4
%39 = load i32, i32* %2
%40 = load i8*, i8** %4
%41 = load i8*, i8** %4
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = mul i64 1, %43
%45 = trunc i64 %44 to i32
%46 = call i32 @send(i32 %39, i8* %40, i32 %45, i32 0)
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%48 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%49 = getelementptr inbounds %struct.iovec, %struct.iovec* %48, i32 0, i32 0
store i8* %47, i8** %49
%50 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%51 = getelementptr inbounds %struct.iovec, %struct.iovec* %50, i32 0, i32 1
store i32 20, i32* %51
%52 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%53 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 1
%54 = getelementptr inbounds %struct.iovec, %struct.iovec* %53, i32 0, i32 0
store i8* %52, i8** %54
%55 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 1
%56 = getelementptr inbounds %struct.iovec, %struct.iovec* %55, i32 0, i32 1
store i32 30, i32* %56
%57 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%58 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 2
%59 = getelementptr inbounds %struct.iovec, %struct.iovec* %58, i32 0, i32 0
store i8* %57, i8** %59
%60 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 2
%61 = getelementptr inbounds %struct.iovec, %struct.iovec* %60, i32 0, i32 1
store i32 40, i32* %61
%62 = call i32 @memset(%struct.msghdr* %9, i8 signext 0, i32 16)
%63 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%64 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 1
store %struct.iovec* %63, %struct.iovec** %64
%65 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 0
store i32 3, i32* %65
%66 = load i32, i32* %2
%67 = call i32 @recvmsg(i32 %66, %struct.msghdr* %9, i32 -1)
%68 = icmp ne i32 %67, -1
br i1 %68, label %69, label %71
69: ; preds = %38
%70 = load i32, i32* @EXIT_FAILURE
store i32 %70, i32* %1
br label %73
71: ; preds = %38
%72 = load i32, i32* @EXIT_SUCCESS
store i32 %72, i32* %1
br label %73
73: ; preds = %71, %69, %32, %15
%74 = load i32, i32* %1
ret i32 %74
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i32, %struct.iovec* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"socket() failed: %s\0A.\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [23 x i8] c"connect() failed: %s\0A.\00"
@.str.3 = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [20 x i8]
%3 = alloca [30 x i8]
%4 = alloca [40 x i8]
%5 = alloca [3 x %struct.iovec]
%6 = alloca %struct.msghdr
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = load i32, i32* @IPPROTO_TCP
%10 = tail call i32 @socket(i32 %7, i32 %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
br label %60
18: ; preds = %0
%19 = bitcast %struct.sockaddr_in* %1 to i8*
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 8000)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%25 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %24)
%26 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%27 = call i64 @connect(i32 %10, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
br label %58
35: ; preds = %18
%36 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @send(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 0)
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%39 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%40 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%41 = bitcast [3 x %struct.iovec]* %5 to i8*
%42 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0
%43 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0, i32 0
store i8* %38, i8** %43
%44 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0, i32 1
store i32 20, i32* %44
%45 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 1, i32 0
store i8* %39, i8** %45
%46 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 1, i32 1
store i32 30, i32* %46
%47 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 2, i32 0
store i8* %40, i8** %47
%48 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 2, i32 1
store i32 40, i32* %48
%49 = bitcast %struct.msghdr* %6 to i8*
%50 = call i32 @memset(%struct.msghdr* %6, i8 signext 0, i32 16)
%51 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 1
store %struct.iovec* %42, %struct.iovec** %51
%52 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 0
store i32 3, i32* %52
%53 = call i32 @recvmsg(i32 %10, %struct.msghdr* %6, i32 -1)
%54 = icmp eq i32 %53, -1
%55 = load i32, i32* @EXIT_SUCCESS
%56 = load i32, i32* @EXIT_FAILURE
%57 = select i1 %54, i32 %55, i32 %56
br label %58
58: ; preds = %35, %29
%59 = phi i32 [ %34, %29 ], [ %57, %35 ]
br label %60
60: ; preds = %58, %12
%61 = phi i32 [ %17, %12 ], [ %59, %58 ]
ret i32 %61
}