#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__ EBADF;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ assert(int);
scalar_t__ close(int);
scalar_t__ errno;
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ socket_del_fd(int);
void disconnect(int fd) {
  do {
  } while (0);
  socket_del_fd(fd);
  shutdown(fd, SHUT_RDWR);
  while (close(fd) != 0) {
    assert(errno != EBADF);
  }
}


x86 assembly (clang, -O0):
<disconnect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
jmp    1150 <disconnect+0x10>
mov    -0x4(%rbp),%edi
call   1050 <socket_del_fd@plt>
mov    -0x4(%rbp),%edi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     11a1 <disconnect+0x61>
mov    0x2e56(%rip),%rax
mov    (%rax),%rax
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    1169 <disconnect+0x29>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disconnect>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
call   1050 <socket_del_fd@plt>
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <shutdown@plt>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
je     119d <disconnect+0x5d>
mov    0x2e69(%rip),%r14
mov    0x2e5a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%rax
xor    %edi,%edi
cmp    (%r15),%rax
setne  %dil
call   1060 <assert@plt>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
jne    1180 <disconnect+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SHUT_RDWR = global i32 0
@errno = global i64 0
@EBADF = global i64 0
define void @disconnect(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
br label %3
3: ; preds = %1
br label %4
4: ; preds = %3
%5 = load i32, i32* %2
%6 = call i32 @socket_del_fd(i32 %5)
%7 = load i32, i32* %2
%8 = load i32, i32* @SHUT_RDWR
%9 = call i32 @shutdown(i32 %7, i32 %8)
br label %10
10: ; preds = %14, %4
%11 = load i32, i32* %2
%12 = call i64 @close(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i64, i64* @errno
%16 = load i64, i64* @EBADF
%17 = icmp ne i64 %15, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
br label %10
20: ; preds = %10
ret void
}

LLVM IR (-O2):
@SHUT_RDWR = global i32 0
@errno = global i64 0
@EBADF = global i64 0
define void @disconnect(i32 %0) {
%2 = tail call i32 @socket_del_fd(i32 %0)
%3 = load i32, i32* @SHUT_RDWR
%4 = tail call i32 @shutdown(i32 %0, i32 %3)
%5 = tail call i64 @close(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1, %7
%8 = load i64, i64* @errno
%9 = load i64, i64* @EBADF
%10 = icmp ne i64 %8, %9
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i64 @close(i32 %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %1
ret void
}