#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*/ F_SETFL;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
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 /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int sock;
  if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 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 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);
  fcntl(sock, F_SETFL, O_NONBLOCK);
  if (recvmsg(sock, &msg, 0) != -1)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1211 <main+0x81>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0xc4(%rbp),%edi
mov    %rax,%rdx
lea    0xe05(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1353 <main+0x1c3>
mov    0x2dd0(%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    0xde1(%rip),%rdi
call   1070 <inet_aton@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    1298 <main+0x108>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc8(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0xc8(%rbp),%edi
mov    %rax,%rdx
lea    0xd9e(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1353 <main+0x1c3>
lea    -0x30(%rbp),%rax
mov    %rax,-0xb0(%rbp)
movl   $0x14,-0xa8(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0xa0(%rbp)
movl   $0x1e,-0x98(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
movl   $0x28,-0x88(%rbp)
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0xb0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
movl   $0x3,-0xc0(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cb4(%rip),%rax
mov    (%rax),%esi
mov    0x2ccb(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
xor    %edx,%edx
call   1080 <recvmsg@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1b7>
mov    0x2c73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1353 <main+0x1c3>
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
mov    0x2e47(%rip),%r14
mov    (%r14),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1296 <main+0x106>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe35(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1070 <inet_aton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     12b6 <main+0x126>
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   1050 <memset@plt>
lea    0x20(%rsp),%rax
mov    %rax,0x18(%rsp)
movl   $0x3,0x10(%rsp)
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1080 <recvmsg@plt>
cmp    $0xffffffff,%eax
jne    12de <main+0x14e>
mov    0x2d14(%rip),%rax
jmp    12e5 <main+0x155>
mov    0x2d2b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd4c(%rip),%rsi
jmp    12d4 <main+0x144>
mov    0x2d0b(%rip),%rax
mov    (%rax),%ebx
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd4c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2ccb(%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_DGRAM = global i32 0
@IPPROTO_UDP = 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"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [20 x i8]
%5 = alloca [30 x i8]
%6 = alloca [40 x i8]
%7 = alloca [3 x %struct.iovec]
%8 = alloca %struct.msghdr
store i32 0, i32* %1
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_UDP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %1
br label %68
20: ; preds = %0
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 8000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%26 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %25)
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @connect(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %20
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
store i32 %36, i32* %1
br label %68
37: ; preds = %20
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%39 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 0
%40 = getelementptr inbounds %struct.iovec, %struct.iovec* %39, i32 0, i32 0
store i8* %38, i8** %40
%41 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 0
%42 = getelementptr inbounds %struct.iovec, %struct.iovec* %41, i32 0, i32 1
store i32 20, i32* %42
%43 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%44 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 1
%45 = getelementptr inbounds %struct.iovec, %struct.iovec* %44, i32 0, i32 0
store i8* %43, i8** %45
%46 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 1
%47 = getelementptr inbounds %struct.iovec, %struct.iovec* %46, i32 0, i32 1
store i32 30, i32* %47
%48 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%49 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 2
%50 = getelementptr inbounds %struct.iovec, %struct.iovec* %49, i32 0, i32 0
store i8* %48, i8** %50
%51 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 2
%52 = getelementptr inbounds %struct.iovec, %struct.iovec* %51, i32 0, i32 1
store i32 40, i32* %52
%53 = call i32 @memset(%struct.msghdr* %8, i8 signext 0, i32 16)
%54 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %7, i64 0, i64 0
%55 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 1
store %struct.iovec* %54, %struct.iovec** %55
%56 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 0
store i32 3, i32* %56
%57 = load i32, i32* %2
%58 = load i32, i32* @F_SETFL
%59 = load i32, i32* @O_NONBLOCK
%60 = call i32 @fcntl(i32 %57, i32 %58, i32 %59)
%61 = load i32, i32* %2
%62 = call i32 @recvmsg(i32 %61, %struct.msghdr* %8, i32 0)
%63 = icmp ne i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %37
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %1
br label %68
66: ; preds = %37
%67 = load i32, i32* @EXIT_SUCCESS
store i32 %67, i32* %1
br label %68
68: ; preds = %66, %64, %31, %14
%69 = load i32, i32* %1
ret i32 %69
}

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_DGRAM = global i32 0
@IPPROTO_UDP = 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"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@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_DGRAM
%9 = load i32, i32* @IPPROTO_UDP
%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 %61
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 %59
35: ; preds = %18
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%37 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%39 = bitcast [3 x %struct.iovec]* %5 to i8*
%40 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0
%41 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0, i32 0
store i8* %36, i8** %41
%42 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 0, i32 1
store i32 20, i32* %42
%43 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 1, i32 0
store i8* %37, i8** %43
%44 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 1, i32 1
store i32 30, i32* %44
%45 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 2, i32 0
store i8* %38, i8** %45
%46 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %5, i64 0, i64 2, i32 1
store i32 40, i32* %46
%47 = bitcast %struct.msghdr* %6 to i8*
%48 = call i32 @memset(%struct.msghdr* %6, i8 signext 0, i32 16)
%49 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 1
store %struct.iovec* %40, %struct.iovec** %49
%50 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 0
store i32 3, i32* %50
%51 = load i32, i32* @F_SETFL
%52 = load i32, i32* @O_NONBLOCK
%53 = call i32 @fcntl(i32 %10, i32 %51, i32 %52)
%54 = call i32 @recvmsg(i32 %10, %struct.msghdr* %6, i32 0)
%55 = icmp eq i32 %54, -1
%56 = load i32, i32* @EXIT_SUCCESS
%57 = load i32, i32* @EXIT_FAILURE
%58 = select i1 %55, i32 %56, i32 %57
br label %59
59: ; preds = %35, %29
%60 = phi i32 [ %34, %29 ], [ %58, %35 ]
br label %61
61: ; preds = %59, %12
%62 = phi i32 [ %17, %12 ], [ %60, %59 ]
ret i32 %62
}