#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 */
typedef int /*<<< orphan*/ on;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_KEEPALIVE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ log_message(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int set_keepalive(int f, int on) {
  if (setsockopt(f, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) == -1) {
    log_message("set_keepalive: setsockopt: %s (errno %d).", strerror(errno),
                errno);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_keepalive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    119c <set_keepalive+0x6c>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
lea    0xe75(%rip),%rdi
call   1040 <log_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <set_keepalive+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_keepalive>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,0xc(%rsp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1187 <set_keepalive+0x57>
mov    0x2e6d(%rip),%rbx
mov    (%rbx),%edi
call   1050 <strerror@plt>
mov    (%rbx),%edx
lea    0xe85(%rip),%rdi
mov    %eax,%esi
call   1040 <log_message@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@.str = [42 x i8] c"set_keepalive: setsockopt: %s (errno %d).\00"
@errno = global i32 0
define i32 @set_keepalive(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_KEEPALIVE
%9 = call i32 @setsockopt(i32 %6, i32 %7, i32 %8, i32* %5, i32 4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = load i32, i32* @errno
%15 = call i32 @log_message(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
store i32 -1, i32* %3
br label %17
16: ; preds = %2
store i32 0, i32* %3
br label %17
17: ; preds = %16, %11
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
@.str = [42 x i8] c"set_keepalive: setsockopt: %s (errno %d).\00"
@errno = global i32 0
define i32 @set_keepalive(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = load i32, i32* @SOL_SOCKET
%5 = load i32, i32* @SO_KEEPALIVE
%6 = call i32 @setsockopt(i32 %0, i32 %4, i32 %5, i32* %3, i32 4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = load i32, i32* @errno
%12 = call i32 @log_message(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
br label %13
13: ; preds = %2, %8
%14 = phi i32 [ -1, %8 ], [ 0, %2 ]
ret i32 %14
}