#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_storage {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addrfrom;
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 recvfrom(int, char **, int, int /*<<< orphan*/, struct sockaddr *, 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);
  }
  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);
  }
  fcntl(sock, F_SETFL, O_NONBLOCK);
  char buf[42];
  struct sockaddr_storage addrfrom;
  socklen_t fromlen = sizeof(addrfrom);
  if (recvfrom(sock, &buf, sizeof(buf), 0, (struct sockaddr *)&addrfrom,
               &fromlen) != -1) {
    fprintf(stderr, "recvfrom() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11f8 <main+0x78>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xe1e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1307 <main+0x187>
mov    0x2de9(%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    0xdfa(%rip),%rdi
call   1060 <inet_aton@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
cmp    $0x0,%rax
jge    1279 <main+0xf9>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xdbd(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1307 <main+0x187>
mov    -0x8(%rbp),%edi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
mov    0x2d54(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
movl   $0x4,-0x5c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%r8
mov    $0x2a,%edx
xor    %ecx,%ecx
lea    -0x5c(%rbp),%r9
call   1070 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     12fb <main+0x17b>
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xd52(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1307 <main+0x187>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x2e5a(%rip),%r14
mov    (%r14),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1256 <main+0xd6>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe48(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1060 <inet_aton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
test   %rax,%rax
js     1276 <main+0xf6>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
movl   $0x4,0x4(%rsp)
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %ebx,%edi
mov    $0x2a,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     12af <main+0x12f>
mov    0x2d8b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xde3(%rip),%rsi
jmp    1294 <main+0x114>
mov    0x2d6b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd8c(%rip),%rsi
jmp    1294 <main+0x114>
mov    0x2d4b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd8c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cf2(%rip),%rax
jmp    12a5 <main+0x125>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%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
@.str.3 = [24 x i8] c"recvfrom() failed: %s\0A.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [42 x i8]
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
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 %53
18: ; preds = %0
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 8000)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%24 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %23)
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i64 @connect(i32 %25, %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
store i32 %34, i32* %1
br label %53
35: ; preds = %18
%36 = load i32, i32* %2
%37 = load i32, i32* @F_SETFL
%38 = load i32, i32* @O_NONBLOCK
%39 = call i32 @fcntl(i32 %36, i32 %37, i32 %38)
store i32 4, i32* %6
%40 = load i32, i32* %2
%41 = bitcast [42 x i8]* %4 to i8**
%42 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
%43 = call i32 @recvfrom(i32 %40, i8** %41, i32 42, i32 0, %struct.sockaddr* %42, i32* %6)
%44 = icmp ne i32 %43, -1
br i1 %44, label %45, label %51
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
store i32 %50, i32* %1
br label %53
51: ; preds = %35
%52 = load i32, i32* @EXIT_SUCCESS
store i32 %52, i32* %1
br label %53
53: ; preds = %51, %45, %29, %12
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%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
@.str.3 = [24 x i8] c"recvfrom() failed: %s\0A.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [42 x i8]
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%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 %54
16: ; preds = %0
%17 = bitcast %struct.sockaddr_in* %1 to i8*
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 8000)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%23 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%25 = call i64 @connect(i32 %8, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
br label %52
33: ; preds = %16
%34 = load i32, i32* @F_SETFL
%35 = load i32, i32* @O_NONBLOCK
%36 = call i32 @fcntl(i32 %8, i32 %34, i32 %35)
%37 = getelementptr inbounds [42 x i8], [42 x i8]* %2, i64 0, i64 0
%38 = bitcast %struct.sockaddr_storage* %3 to i8*
%39 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%40 = bitcast [42 x i8]* %2 to i8**
%41 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%42 = call i32 @recvfrom(i32 %8, i8** %40, i32 42, i32 0, %struct.sockaddr* %41, i32* %4)
%43 = icmp eq i32 %42, -1
br i1 %43, label %49, label %44
44: ; preds = %33
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %33, %44
%50 = phi i32* [ @EXIT_FAILURE, %44 ], [ @EXIT_SUCCESS, %33 ]
%51 = load i32, i32* %50
br label %52
52: ; preds = %49, %27
%53 = phi i32 [ %32, %27 ], [ %51, %49 ]
br label %54
54: ; preds = %52, %10
%55 = phi i32 [ %15, %10 ], [ %53, %52 ]
ret i32 %55
}