#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int /*<<< orphan*/ assert(int);
int fcntl(int, int /*<<< orphan*/, int);
scalar_t__ unboxUnsigned(int /*<<< orphan*/ *);
uint32_t *socketSetNonBlocking(uint32_t context_len, uint32_t *hPtr) {
  int sd;
  int flags;
  sd = (int)unboxUnsigned(hPtr);
  flags = fcntl(sd, F_GETFL, 0);
  assert(flags >= 0);
  fcntl(sd, F_SETFL, flags | O_NONBLOCK);
  return (uint32_t *)NULL;
}


x86 assembly (clang, -O0):
<socketSetNonBlocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <unboxUnsigned@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
mov    0x2e60(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketSetNonBlocking>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rdi
call   1040 <unboxUnsigned@plt>
mov    %rax,%rbx
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
or     (%rax),%ebp
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <fcntl@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32* @socketSetNonBlocking(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = call i64 @unboxUnsigned(i32* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = load i32, i32* @F_GETFL
%12 = call i32 @fcntl(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %5
%18 = load i32, i32* @F_SETFL
%19 = load i32, i32* %6
%20 = load i32, i32* @O_NONBLOCK
%21 = or i32 %19, %20
%22 = call i32 @fcntl(i32 %17, i32 %18, i32 %21)
ret i32* null
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define noalias i32* @socketSetNonBlocking(i32 %0, i32* %1) {
%3 = tail call i64 @unboxUnsigned(i32* %1)
%4 = trunc i64 %3 to i32
%5 = load i32, i32* @F_GETFL
%6 = tail call i32 @fcntl(i32 %4, i32 %5, i32 0)
%7 = xor i32 %6, -1
%8 = lshr i32 %7, 31
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* @F_SETFL
%11 = load i32, i32* @O_NONBLOCK
%12 = or i32 %11, %6
%13 = tail call i32 @fcntl(i32 %4, i32 %10, i32 %12)
ret i32* null
}