#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;
int fcntl(int, int /*<<< orphan*/, int);
int SK_clearsockflags(int socket, int flags) {
  int old_flags;
  if ((old_flags = fcntl(socket, F_GETFL, 0)) == -1) {
    return -1;
  }
  if (fcntl(socket, F_SETFL, old_flags & ~flags) == -1) {
    return -1;
  }
  return socket;
}


x86 assembly (clang, -O0):
<SK_clearsockflags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    1149 <SK_clearsockflags+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <SK_clearsockflags+0x70>
mov    -0x8(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    117a <SK_clearsockflags+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <SK_clearsockflags+0x70>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SK_clearsockflags>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eba(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     114a <SK_clearsockflags+0x3a>
mov    0x2ead(%rip),%rcx
mov    (%rcx),%esi
not    %ebp
and    %ebp,%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
jmp    114f <SK_clearsockflags+0x3f>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
define i32 @SK_clearsockflags(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = load i32, i32* @F_SETFL
%8 = xor i32 %1, -1
%9 = and i32 %4, %8
%10 = tail call i32 @fcntl(i32 %0, i32 %7, i32 %9)
%11 = icmp eq i32 %10, -1
%12 = select i1 %11, i32 -1, i32 %0
br label %13
13: ; preds = %6, %2
%14 = phi i32 [ -1, %2 ], [ %12, %6 ]
ret i32 %14
}