#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 sockaddr {
  scalar_t__ sa_family;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ on;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_KEEPALIVE;
int connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              char *, int);
int ___sane_connect(int sock, struct sockaddr *sa, socklen_t len) {
  if (sa->sa_family == AF_INET) {
    int on = 1;
    (void)setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof(on));
  }
  return (connect(sock, sa, len));
}


x86 assembly (clang, -O0):
<___sane_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2ea0(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <___sane_connect+0x54>
movl   $0x1,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <connect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<___sane_connect>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rax
mov    0x2ea6(%rip),%rcx
cmp    (%rcx),%rax
jne    116b <___sane_connect+0x4b>
movl   $0x1,0xc(%rsp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <connect@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
define i32 @___sane_connect(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 %2, i32* %6
%8 = load %struct.sockaddr*, %struct.sockaddr** %5
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @AF_INET
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %19
13: ; preds = %3
store i32 1, i32* %7
%14 = load i32, i32* %4
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_KEEPALIVE
%17 = bitcast i32* %7 to i8*
%18 = call i32 @setsockopt(i32 %14, i32 %15, i32 %16, i8* %17, i32 4)
br label %19
19: ; preds = %13, %3
%20 = load i32, i32* %4
%21 = load %struct.sockaddr*, %struct.sockaddr** %5
%22 = load i32, i32* %6
%23 = call i32 @connect(i32 %20, %struct.sockaddr* %21, i32 %22)
ret i32 %23
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@AF_INET = global i64 0
@SOL_SOCKET = global i32 0
@SO_KEEPALIVE = global i32 0
define i32 @___sane_connect(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @AF_INET
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_KEEPALIVE
%13 = call i32 @setsockopt(i32 %0, i32 %11, i32 %12, i8* %10, i32 4)
br label %14
14: ; preds = %9, %3
%15 = call i32 @connect(i32 %0, %struct.sockaddr* %1, i32 %2)
ret i32 %15
}