#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*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
long O_NONBLOCK;
scalar_t__ fcntl(int, int /*<<< orphan*/, ...);
int native_pcm_nonblock(int fd, int nonblock) {
  long flags;
  if ((flags = fcntl(fd, F_GETFL)) < 0)
    return -1;
  if (nonblock)
    flags |= O_NONBLOCK;
  else
    flags &= ~O_NONBLOCK;
  if (fcntl(fd, F_SETFL, flags) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<native_pcm_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    114b <native_pcm_nonblock+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <native_pcm_nonblock+0xa6>
cmpl   $0x0,-0xc(%rbp)
je     116c <native_pcm_nonblock+0x5c>
mov    0x2e8c(%rip),%rax
mov    (%rax),%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1182 <native_pcm_nonblock+0x72>
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
xor    $0xffffffffffffffff,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11af <native_pcm_nonblock+0x9f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <native_pcm_nonblock+0xa6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<native_pcm_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %rax,%rax
js     1160 <native_pcm_nonblock+0x50>
mov    0x2eb5(%rip),%rcx
mov    (%rcx),%rdx
mov    %rdx,%rcx
or     %rax,%rcx
not    %rdx
and    %rax,%rdx
test   %ebp,%ebp
cmovne %rcx,%rdx
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
sar    $0x3f,%rax
jmp    1165 <native_pcm_nonblock+0x55>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i64 0
@F_SETFL = global i32 0
define i32 @native_pcm_nonblock(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = load i32, i32* @F_GETFL
%9 = call i64 (i32, i32, ...) @fcntl(i32 %7, i32 %8)
store i64 %9, i64* %6
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %32
12: ; preds = %2
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i64, i64* @O_NONBLOCK
%17 = load i64, i64* %6
%18 = or i64 %17, %16
store i64 %18, i64* %6
br label %24
19: ; preds = %12
%20 = load i64, i64* @O_NONBLOCK
%21 = xor i64 %20, -1
%22 = load i64, i64* %6
%23 = and i64 %22, %21
store i64 %23, i64* %6
br label %24
24: ; preds = %19, %15
%25 = load i32, i32* %4
%26 = load i32, i32* @F_SETFL
%27 = load i64, i64* %6
%28 = call i64 (i32, i32, ...) @fcntl(i32 %25, i32 %26, i64 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 -1, i32* %3
br label %32
31: ; preds = %24
store i32 0, i32* %3
br label %32
32: ; preds = %31, %30, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i64 0
@F_SETFL = global i32 0
define i32 @native_pcm_nonblock(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i64 (i32, i32, ...) @fcntl(i32 %0, i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = icmp eq i32 %1, 0
%8 = load i64, i64* @O_NONBLOCK
%9 = or i64 %8, %4
%10 = xor i64 %8, -1
%11 = and i64 %4, %10
%12 = select i1 %7, i64 %11, i64 %9
%13 = load i32, i32* @F_SETFL
%14 = tail call i64 (i32, i32, ...) @fcntl(i32 %0, i32 %13, i64 %12)
%15 = ashr i64 %14, 63
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %6, %2
%18 = phi i32 [ -1, %2 ], [ %16, %6 ]
ret i32 %18
}