#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 FD_CLOEXEC;
int /*<<< orphan*/ F_GETFD;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, ...);
void usock_set_flags(int sock, unsigned int type) {
  if (!(type & 0x0200))
    fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC);
  if (type & 0x0400)
    fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK);
}


x86 assembly (clang, -O0):
<usock_set_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x200,%eax
cmp    $0x0,%eax
jne    116c <usock_set_flags+0x5c>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    %eax,%edx
mov    0x2e65(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    -0x8(%rbp),%eax
and    $0x400,%eax
cmp    $0x0,%eax
je     11ba <usock_set_flags+0xaa>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    %eax,%edx
mov    0x2e37(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usock_set_flags>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%ebx
test   $0x200,%esi
jne    1153 <usock_set_flags+0x43>
mov    0x2eb1(%rip),%rax
mov    (%rax),%r14d
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2e85(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   $0x400,%ebp
jne    1160 <usock_set_flags+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e69(%rip),%rax
mov    (%rax),%ebp
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2e66(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fcntl@plt>

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

LLVM IR (-O2):
@F_SETFD = global i32 0
@F_GETFD = global i32 0
@FD_CLOEXEC = global i32 0
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @usock_set_flags(i32 %0, i32 %1) {
%3 = and i32 %1, 512
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i32, i32* @F_SETFD
%7 = load i32, i32* @F_GETFD
%8 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %7)
%9 = load i32, i32* @FD_CLOEXEC
%10 = or i32 %9, %8
%11 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %6, i32 %10)
br label %12
12: ; preds = %5, %2
%13 = and i32 %1, 1024
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* @F_GETFL
%18 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %17)
%19 = load i32, i32* @O_NONBLOCK
%20 = or i32 %19, %18
%21 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %16, i32 %20)
br label %22
22: ; preds = %15, %12
ret void
}