#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 */

/* 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;
scalar_t__ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
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);
  }
  if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
    fprintf(stderr, "fcntl() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11b8 <main+0x78>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1225 <main+0xe5>
mov    -0x8(%rbp),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    1219 <main+0xd9>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe13(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1225 <main+0xe5>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
test   %eax,%eax
js     118e <main+0x4e>
mov    0x2e52(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e69(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%edi
call   1030 <fcntl@plt>
test   %rax,%rax
js     1197 <main+0x57>
mov    0x2e1c(%rip),%rax
jmp    11c9 <main+0x89>
lea    0xe6b(%rip),%rbx
jmp    119e <main+0x5e>
lea    0xe78(%rip),%rbx
mov    0x2e23(%rip),%rax
mov    (%rax),%ebp
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@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
@.str.1 = [21 x i8] c"fcntl() failed: %s\0A.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = load i32, i32* @IPPROTO_UDP
%6 = call i32 @socket(i32 %3, i32 %4, i32 %5)
store i32 %6, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %1
br label %28
14: ; preds = %0
%15 = load i32, i32* %2
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* @O_NONBLOCK
%18 = call i64 @fcntl(i32 %15, i32 %16, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %1
br label %28
26: ; preds = %14
%27 = load i32, i32* @EXIT_SUCCESS
store i32 %27, i32* %1
br label %28
28: ; preds = %26, %20, %8
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@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
@.str.1 = [21 x i8] c"fcntl() failed: %s\0A.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @AF_INET
%2 = load i32, i32* @SOCK_DGRAM
%3 = load i32, i32* @IPPROTO_UDP
%4 = tail call i32 @socket(i32 %1, i32 %2, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = load i32, i32* @F_SETFL
%8 = load i32, i32* @O_NONBLOCK
%9 = tail call i64 @fcntl(i32 %4, i32 %7, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6, %0
%12 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %6 ]
%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* %12, i8* %15)
br label %17
17: ; preds = %11, %6
%18 = phi i32* [ @EXIT_SUCCESS, %6 ], [ @EXIT_FAILURE, %11 ]
%19 = load i32, i32* %18
ret i32 %19
}