#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_GETFD;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, int);
int serial_port_set_nonblock(int fd, int nonblock) {
  int flag = fcntl(fd, F_GETFD, 0);
  if (nonblock) {
    flag |= O_NONBLOCK;
  } else {
    flag &= ~O_NONBLOCK;
  }
  return fcntl(fd, F_SETFL, flag);
}


x86 assembly (clang, -O0):
<serial_port_set_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1152 <serial_port_set_nonblock+0x42>
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1164 <serial_port_set_nonblock+0x54>
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_port_set_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2eba(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
or     %eax,%ecx
not    %edx
and    %eax,%edx
test   %ebx,%ebx
cmovne %ecx,%edx
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fcntl@plt>

LLVM IR (-O0):
@F_GETFD = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @serial_port_set_nonblock(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* @F_GETFD
%8 = call i32 @fcntl(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @O_NONBLOCK
%13 = load i32, i32* %5
%14 = or i32 %13, %12
store i32 %14, i32* %5
br label %20
15: ; preds = %2
%16 = load i32, i32* @O_NONBLOCK
%17 = xor i32 %16, -1
%18 = load i32, i32* %5
%19 = and i32 %18, %17
store i32 %19, i32* %5
br label %20
20: ; preds = %15, %11
%21 = load i32, i32* %3
%22 = load i32, i32* @F_SETFL
%23 = load i32, i32* %5
%24 = call i32 @fcntl(i32 %21, i32 %22, i32 %23)
ret i32 %24
}

LLVM IR (-O2):
@F_GETFD = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @serial_port_set_nonblock(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GETFD
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = icmp eq i32 %1, 0
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %6, %4
%8 = xor i32 %6, -1
%9 = and i32 %4, %8
%10 = select i1 %5, i32 %9, i32 %7
%11 = load i32, i32* @F_SETFL
%12 = tail call i32 @fcntl(i32 %0, i32 %11, i32 %10)
ret i32 %12
}