#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 /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int create_nonblocking_socket_tcp(void) {
  int sock;
  sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock < 0) {
    return sock;
  }
  if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
    fprintf(stderr, "[ERROR] "
                    "[CREATE_NONBLOCKING_SOCKET_TCP] Unable to set option "
                    "\"O_NONBLOCK\" on the socket"
                    "\n");
    return -1;
  }
  return sock;
}


x86 assembly (clang, -O0):
<create_nonblocking_socket_tcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1170 <create_nonblocking_socket_tcp+0x40>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bb <create_nonblocking_socket_tcp+0x8b>
mov    -0x8(%rbp),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11b5 <create_nonblocking_socket_tcp+0x85>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <create_nonblocking_socket_tcp+0x8b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_nonblocking_socket_tcp>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
call   1050 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     118f <create_nonblocking_socket_tcp+0x5f>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
test   %rax,%rax
jns    118f <create_nonblocking_socket_tcp+0x5f>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [89 x i8] c"[ERROR] [CREATE_NONBLOCKING_SOCKET_TCP] Unable to set option \22O_NONBLOCK\22 on the socket\0A\00"
define i32 @create_nonblocking_socket_tcp() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = load i32, i32* @IPPROTO_TCP
%6 = call i32 @socket(i32 %3, i32 %4, i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = load i32, i32* %2
store i32 %10, i32* %1
br label %22
11: ; preds = %0
%12 = load i32, i32* %2
%13 = load i32, i32* @F_SETFL
%14 = load i32, i32* @O_NONBLOCK
%15 = call i64 @fcntl(i32 %12, i32 %13, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %22
20: ; preds = %11
%21 = load i32, i32* %2
store i32 %21, i32* %1
br label %22
22: ; preds = %20, %17, %9
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [89 x i8] c"[ERROR] [CREATE_NONBLOCKING_SOCKET_TCP] Unable to set option \22O_NONBLOCK\22 on the socket\0A\00"
define i32 @create_nonblocking_socket_tcp() {
%1 = load i32, i32* @AF_INET
%2 = load i32, i32* @SOCK_STREAM
%3 = load i32, i32* @IPPROTO_TCP
%4 = tail call i32 @socket(i32 %1, i32 %2, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %14, 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 %14
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %6, %0, %11
%15 = phi i32 [ -1, %11 ], [ %4, %0 ], [ %4, %6 ]
ret i32 %15
}