#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__ ENOTSOCK;
int /*<<< orphan*/ SHUT_WR;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int shutdown(int, int /*<<< orphan*/);
void socket_connected_receive(int fd) {
  int res = shutdown(fd, SHUT_WR);
  assert(res == 0 || (res == -1 && errno == ENOTSOCK));
}


x86 assembly (clang, -O0):
<socket_connected_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eb3(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
mov    %eax,-0x8(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x9(%rbp)
je     117d <socket_connected_receive+0x5d>
xor    %eax,%eax
cmpl   $0xffffffff,-0x8(%rbp)
mov    %al,-0xa(%rbp)
jne    1177 <socket_connected_receive+0x57>
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0xa(%rbp)
mov    -0xa(%rbp),%al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_connected_receive>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
test   %eax,%eax
je     115b <socket_connected_receive+0x3b>
cmp    $0xffffffff,%eax
sete   %al
mov    0x2e90(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e8e(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
pop    %rax
jmp    1040 <assert@plt>
mov    $0x1,%edi
pop    %rax
jmp    1040 <assert@plt>

LLVM IR (-O0):
@SHUT_WR = global i32 0
@errno = global i64 0
@ENOTSOCK = global i64 0
define void @socket_connected_receive(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @SHUT_WR
%6 = call i32 @shutdown(i32 %4, i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @ENOTSOCK
%15 = icmp eq i64 %13, %14
br label %16
16: ; preds = %12, %9
%17 = phi i1 [ false, %9 ], [ %15, %12 ]
br label %18
18: ; preds = %16, %1
%19 = phi i1 [ true, %1 ], [ %17, %16 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
ret void
}

LLVM IR (-O2):
@SHUT_WR = global i32 0
@errno = global i64 0
@ENOTSOCK = global i64 0
define void @socket_connected_receive(i32 %0) {
%2 = load i32, i32* @SHUT_WR
%3 = tail call i32 @shutdown(i32 %0, i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = icmp eq i32 %3, -1
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOTSOCK
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %5, %1
%13 = phi i32 [ 1, %1 ], [ %11, %5 ]
%14 = tail call i32 @assert(i32 %13)
ret void
}