#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 */
scalar_t__ EAGAIN;
scalar_t__ ENOENT;
scalar_t__ errno;
int so_recvtest(int);
int so_closed(int fd) {
  int i;
  if (fd == -1)
    return 1;
  i = so_recvtest(fd);
  return (i == 0 || (i == -1 && errno != EAGAIN && errno != ENOENT));
}


x86 assembly (clang, -O0):
<so_closed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1131 <so_closed+0x21>
movl   $0x1,-0x4(%rbp)
jmp    11a4 <so_closed+0x94>
mov    -0x8(%rbp),%edi
call   1030 <so_recvtest@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
je     1199 <so_closed+0x89>
xor    %eax,%eax
cmpl   $0xffffffff,-0xc(%rbp)
mov    %al,-0xe(%rbp)
jne    1193 <so_closed+0x83>
mov    0x2e7f(%rip),%rax
mov    (%rax),%rcx
xor    %eax,%eax
mov    0x2e5b(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xe(%rbp)
je     1193 <so_closed+0x83>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<so_closed>:
push   %rbx
mov    $0x1,%ebx
cmp    $0xffffffff,%edi
je     1154 <so_closed+0x44>
call   1030 <so_recvtest@plt>
test   %eax,%eax
je     1154 <so_closed+0x44>
cmp    $0xffffffff,%eax
jne    1152 <so_closed+0x42>
mov    0x2eb0(%rip),%rax
mov    (%rax),%rax
mov    0x2e8e(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
je     1154 <so_closed+0x44>
mov    0x2e88(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
setne  %bl
jmp    1154 <so_closed+0x44>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
@ENOENT = global i64 0
define i32 @so_closed(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %29
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i32 @so_recvtest(i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %8
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EAGAIN
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i64, i64* @errno
%22 = load i64, i64* @ENOENT
%23 = icmp ne i64 %21, %22
br label %24
24: ; preds = %20, %16, %13
%25 = phi i1 [ false, %16 ], [ false, %13 ], [ %23, %20 ]
br label %26
26: ; preds = %24, %8
%27 = phi i1 [ true, %8 ], [ %25, %24 ]
%28 = zext i1 %27 to i32
store i32 %28, i32* %2
br label %29
29: ; preds = %26, %7
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
@ENOENT = global i64 0
define i32 @so_closed(i32 %0) {
%2 = icmp eq i32 %0, -1
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i32 @so_recvtest(i32 %0)
switch i32 %4, label %13 [
i32 0, label %14
i32 -1, label %5
]
5: ; preds = %3
%6 = load i64, i64* @errno
%7 = load i64, i64* @EAGAIN
%8 = icmp eq i64 %6, %7
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = load i64, i64* @ENOENT
%11 = icmp ne i64 %6, %10
%12 = zext i1 %11 to i32
br label %14
13: ; preds = %3
br label %14
14: ; preds = %9, %5, %13, %3, %1
%15 = phi i32 [ 1, %1 ], [ 1, %3 ], [ 0, %5 ], [ %12, %9 ], [ 0, %13 ]
ret i32 %15
}