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

/* Variables and functions */
scalar_t__ ENOTSOCK;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_DEBUG;
scalar_t__ errno;
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int *);
int is_not_socket(int fd) {
  int opt;
  socklen_t len = sizeof(opt);
  if (-1 == getsockopt(fd, SOL_SOCKET, SO_DEBUG, &opt, &len) &&
      errno == ENOTSOCK) {
    errno = 0;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_not_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ebc(%rip),%rax
mov    (%rax),%esi
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1030 <getsockopt@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1187 <is_not_socket+0x77>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
jne    1187 <is_not_socket+0x77>
mov    0x2e54(%rip),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    118e <is_not_socket+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_not_socket>:
push   %rax
movl   $0x4,(%rsp)
mov    0x2ec9(%rip),%rax
mov    (%rax),%esi
mov    0x2eb8(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
call   1030 <getsockopt@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1142 <is_not_socket+0x32>
pop    %rcx
ret
mov    0x2e7f(%rip),%rcx
mov    (%rcx),%rdx
mov    0x2e7d(%rip),%rsi
cmp    (%rsi),%rdx
jne    1140 <is_not_socket+0x30>
movq   $0x0,(%rcx)
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_DEBUG = global i32 0
@errno = global i64 0
@ENOTSOCK = global i64 0
define i32 @is_not_socket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 4, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_DEBUG
%9 = call i32 @getsockopt(i32 %6, i32 %7, i32 %8, i32* %4, i32* %5)
%10 = icmp eq i32 -1, %9
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOTSOCK
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i64 0, i64* @errno
store i32 1, i32* %2
br label %17
16: ; preds = %11, %1
store i32 0, i32* %2
br label %17
17: ; preds = %16, %15
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_DEBUG = global i32 0
@errno = global i64 0
@ENOTSOCK = global i64 0
define i32 @is_not_socket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_DEBUG
%8 = call i32 @getsockopt(i32 %0, i32 %6, i32 %7, i32* %2, i32* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOTSOCK
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store i64 0, i64* @errno
br label %15
15: ; preds = %1, %10, %14
%16 = phi i32 [ 1, %14 ], [ 0, %10 ], [ 0, %1 ]
ret i32 %16
}