#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 */
struct linger {
  int l_onoff;
  scalar_t__ l_linger;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_LINGER;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ gettext(char *);
int /*<<< orphan*/ set_error(int /*<<< orphan*/, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct linger *,
               int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void failure_close(int fd) {
  struct linger sl;
  sl.l_onoff = 1;
  sl.l_linger = 0;
  if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &sl, sizeof sl) == -1)
    set_error(gettext("could not set TCP_NODELAY on socket (%s)"),
              strerror(errno));
  close(fd);
}


x86 assembly (clang, -O0):
<failure_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11be <failure_close+0x6e>
lea    0xe62(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1050 <set_error@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<failure_close>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x1,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11b5 <failure_close+0x65>
lea    0xe69(%rip),%rdi
call   1040 <gettext@plt>
mov    %eax,%ebp
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <set_error@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.linger = type { i32, i64 }
@SOL_SOCKET = global i32 0
@SO_LINGER = global i32 0
@.str = [41 x i8] c"could not set TCP_NODELAY on socket (%s)\00"
@errno = global i32 0
define void @failure_close(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.linger
store i32 %0, i32* %2
%4 = getelementptr inbounds %struct.linger, %struct.linger* %3, i32 0, i32 0
store i32 1, i32* %4
%5 = getelementptr inbounds %struct.linger, %struct.linger* %3, i32 0, i32 1
store i64 0, i64* %5
%6 = load i32, i32* %2
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_LINGER
%9 = call i32 @setsockopt(i32 %6, i32 %7, i32 %8, %struct.linger* %3, i32 16)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = call i32 @gettext(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @set_error(i32 %12, i32 %14)
br label %16
16: ; preds = %11, %1
%17 = load i32, i32* %2
%18 = call i32 @close(i32 %17)
ret void
}

LLVM IR (-O2):
%struct.linger = type { i32, i64 }
@SOL_SOCKET = global i32 0
@SO_LINGER = global i32 0
@.str = [41 x i8] c"could not set TCP_NODELAY on socket (%s)\00"
@errno = global i32 0
define void @failure_close(i32 %0) {
%2 = alloca %struct.linger
%3 = bitcast %struct.linger* %2 to i8*
%4 = getelementptr inbounds %struct.linger, %struct.linger* %2, i64 0, i32 0
store i32 1, i32* %4
%5 = getelementptr inbounds %struct.linger, %struct.linger* %2, i64 0, i32 1
store i64 0, i64* %5
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_LINGER
%8 = call i32 @setsockopt(i32 %0, i32 %6, i32 %7, %struct.linger* %2, i32 16)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = call i32 @gettext(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @set_error(i32 %11, i32 %13)
br label %15
15: ; preds = %10, %1
%16 = call i32 @close(i32 %0)
ret void
}