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

/* 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;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int readv(int, struct iovec *, int);
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);
  }
  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);
  fcntl(sock, F_SETFL, O_NONBLOCK);
  if (readv(sock, iovec, sizeof(iovec) / sizeof(struct iovec)) != -1)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11d1 <main+0x81>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    %rax,%rdx
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125e <main+0x10e>
lea    -0x20(%rbp),%rax
mov    %rax,-0xa0(%rbp)
movl   $0x14,-0x98(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x90(%rbp)
movl   $0x1e,-0x88(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
movl   $0x28,-0x78(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    -0x8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x3,%edx
call   1050 <readv@plt>
cmp    $0xffffffff,%eax
je     1252 <main+0x102>
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125e <main+0x10e>
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xa0,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11e9 <main+0x99>
mov    %eax,%ebx
lea    0x30(%rsp),%rax
mov    %rax,(%rsp)
movl   $0x14,0x8(%rsp)
lea    0x50(%rsp),%rax
mov    %rax,0x10(%rsp)
movl   $0x1e,0x18(%rsp)
lea    0x70(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x28,0x28(%rsp)
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1050 <readv@plt>
cmp    $0xffffffff,%eax
jne    1211 <main+0xc1>
mov    0x2dc1(%rip),%rax
jmp    1218 <main+0xc8>
mov    0x2dd8(%rip),%rax
mov    (%rax),%ebx
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xdf9(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
add    $0xa0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, 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
@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 [20 x i8]
%4 = alloca [30 x i8]
%5 = alloca [40 x i8]
%6 = alloca [3 x %struct.iovec]
store i32 0, i32* %1
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = load i32, i32* @IPPROTO_UDP
%10 = call i32 @socket(i32 %7, i32 %8, i32 %9)
store i32 %10, i32* %2
%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 = call i8* @strerror(i32 %14)
%16 = 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
store i32 %17, i32* %1
br label %46
18: ; preds = %0
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 0
%21 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i32 0, i32 0
store i8* %19, i8** %21
%22 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 0
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %22, i32 0, i32 1
store i32 20, i32* %23
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%25 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 1
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %25, i32 0, i32 0
store i8* %24, i8** %26
%27 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 1
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %27, i32 0, i32 1
store i32 30, i32* %28
%29 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%30 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 2
%31 = getelementptr inbounds %struct.iovec, %struct.iovec* %30, i32 0, i32 0
store i8* %29, i8** %31
%32 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 2
%33 = getelementptr inbounds %struct.iovec, %struct.iovec* %32, i32 0, i32 1
store i32 40, i32* %33
%34 = load i32, i32* %2
%35 = load i32, i32* @F_SETFL
%36 = load i32, i32* @O_NONBLOCK
%37 = call i32 @fcntl(i32 %34, i32 %35, i32 %36)
%38 = load i32, i32* %2
%39 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %6, i64 0, i64 0
%40 = call i32 @readv(i32 %38, %struct.iovec* %39, i32 3)
%41 = icmp ne i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %18
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %1
br label %46
44: ; preds = %18
%45 = load i32, i32* @EXIT_SUCCESS
store i32 %45, i32* %1
br label %46
46: ; preds = %44, %42, %12
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
%struct.iovec = type { i8*, 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
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [30 x i8]
%3 = alloca [40 x i8]
%4 = alloca [3 x %struct.iovec]
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = load i32, i32* @IPPROTO_UDP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
br label %36
16: ; preds = %0
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%20 = bitcast [3 x %struct.iovec]* %4 to i8*
%21 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 0
%22 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 0, i32 0
store i8* %17, i8** %22
%23 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 0, i32 1
store i32 20, i32* %23
%24 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 1, i32 0
store i8* %18, i8** %24
%25 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 1, i32 1
store i32 30, i32* %25
%26 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 2, i32 0
store i8* %19, i8** %26
%27 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 2, i32 1
store i32 40, i32* %27
%28 = load i32, i32* @F_SETFL
%29 = load i32, i32* @O_NONBLOCK
%30 = call i32 @fcntl(i32 %8, i32 %28, i32 %29)
%31 = call i32 @readv(i32 %8, %struct.iovec* %21, i32 3)
%32 = icmp eq i32 %31, -1
%33 = load i32, i32* @EXIT_SUCCESS
%34 = load i32, i32* @EXIT_FAILURE
%35 = select i1 %32, i32 %33, i32 %34
br label %36
36: ; preds = %16, %10
%37 = phi i32 [ %15, %10 ], [ %35, %16 ]
ret i32 %37
}