#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ EPOLLHUP;
int /*<<< orphan*/ EPOLL_CTL_MOD;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SHUT_WR;
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int, char *, int);
int /*<<< orphan*/ memset(struct epoll_event *, int /*<<< orphan*/, int);
int shutdown(int, int /*<<< orphan*/);
int shut(int connfd, int efd) {
  struct epoll_event ev;
  memset(&ev, 0, sizeof(struct epoll_event));
  ev.events = EPOLLHUP;
  ev.data.fd = connfd;
  if (epoll_ctl(efd, EPOLL_CTL_MOD, connfd, &ev) == -1) {
    error(EXIT_FAILURE, errno, "Error %d changing epoll descriptor", errno);
  }
  if (shutdown(connfd, SHUT_WR) == -1) {
    error(0, errno, "Error %d on connection shutdown", errno);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<shut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rcx
call   1050 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    11b8 <shut+0x78>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%ecx
lea    0xe4d(%rip),%rdx
call   1060 <error@plt>
mov    -0x8(%rbp),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
cmp    $0xffffffff,%eax
jne    11fe <shut+0xbe>
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    0x2dee(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
lea    0xe36(%rip),%rdx
call   1060 <error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <shut+0xc5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shut>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rsp,%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %ebp,(%rsp)
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %r15,%rcx
call   1050 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    11aa <shut+0x6a>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%ecx
lea    0xe5d(%rip),%rdx
mov    %ecx,%esi
call   1060 <error@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <shutdown@plt>
cmp    $0xffffffff,%eax
jne    11de <shut+0x9e>
mov    0x2e0a(%rip),%rax
mov    (%rax),%ecx
lea    0xe54(%rip),%rdx
xor    %edi,%edi
mov    %ecx,%esi
call   1060 <error@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@EPOLLHUP = global i32 0
@EPOLL_CTL_MOD = global i32 0
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [35 x i8] c"Error %d changing epoll descriptor\00"
@SHUT_WR = global i32 0
@.str.1 = [32 x i8] c"Error %d on connection shutdown\00"
define i32 @shut(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.epoll_event
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = call i32 @memset(%struct.epoll_event* %6, i32 0, i32 8)
%8 = load i32, i32* @EPOLLHUP
%9 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* %4
%11 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load i32, i32* %5
%14 = load i32, i32* @EPOLL_CTL_MOD
%15 = load i32, i32* %4
%16 = call i32 @epoll_ctl(i32 %13, i32 %14, i32 %15, %struct.epoll_event* %6)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* @EXIT_FAILURE
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i32 @error(i32 %19, i32 %20, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %18, %2
%24 = load i32, i32* %4
%25 = load i32, i32* @SHUT_WR
%26 = call i32 @shutdown(i32 %24, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32, i32* @errno
%30 = load i32, i32* @errno
%31 = call i32 @error(i32 0, i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 -1, i32* %3
br label %33
32: ; preds = %23
store i32 0, i32* %3
br label %33
33: ; preds = %32, %28
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@EPOLLHUP = global i32 0
@EPOLL_CTL_MOD = global i32 0
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str = [35 x i8] c"Error %d changing epoll descriptor\00"
@SHUT_WR = global i32 0
@.str.1 = [32 x i8] c"Error %d on connection shutdown\00"
define i32 @shut(i32 %0, i32 %1) {
%3 = alloca %struct.epoll_event
%4 = bitcast %struct.epoll_event* %3 to i8*
%5 = call i32 @memset(%struct.epoll_event* %3, i32 0, i32 8)
%6 = load i32, i32* @EPOLLHUP
%7 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 0, i32 0
store i32 %0, i32* %8
%9 = load i32, i32* @EPOLL_CTL_MOD
%10 = call i32 @epoll_ctl(i32 %1, i32 %9, i32 %0, %struct.epoll_event* %3)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = load i32, i32* @errno
%15 = call i32 @error(i32 %13, i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %12, %2
%17 = load i32, i32* @SHUT_WR
%18 = call i32 @shutdown(i32 %0, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @errno
%22 = call i32 @error(i32 0, i32 %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %16, %20
%24 = phi i32 [ -1, %20 ], [ 0, %16 ]
ret i32 %24
}