#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*/ timeo;
struct timeval {
  int member_0;
  int /*<<< orphan*/ member_1;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_SNDTIMEO;
scalar_t__ connect(int, struct sockaddr const *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              struct timeval *, int);
int conn_nonb(int sockfd, const struct sockaddr *saptr, int salen) {
  struct timeval timeo = {5, 0};
  setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo));
  if (connect(sockfd, saptr, salen)) {
    perror("connect");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<conn_nonb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <connect@plt>
cmp    $0x0,%rax
je     11a2 <conn_nonb+0x72>
lea    0xe77(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <conn_nonb+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conn_nonb>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x5,0x8(%rsp)
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <connect@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    118b <conn_nonb+0x5b>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6e(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    1182 <conn_nonb+0x52>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.conn_nonb.timeo = %struct.timeval { i32 5, i32 0 }
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@.str = [8 x i8] c"connect\00"
define i32 @conn_nonb(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr*
%7 = alloca i32
%8 = alloca %struct.timeval
store i32 %0, i32* %5
store %struct.sockaddr* %1, %struct.sockaddr** %6
store i32 %2, i32* %7
%9 = bitcast %struct.timeval* %8 to i8*
%10 = load i32, i32* %5
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_SNDTIMEO
%13 = call i32 @setsockopt(i32 %10, i32 %11, i32 %12, %struct.timeval* %8, i32 8)
%14 = load i32, i32* %5
%15 = load %struct.sockaddr*, %struct.sockaddr** %6
%16 = load i32, i32* %7
%17 = call i64 @connect(i32 %14, %struct.sockaddr* %15, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %22
21: ; preds = %3
store i32 0, i32* %4
br label %22
22: ; preds = %21, %19
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.timeval = type { i32, i32 }
@SOL_SOCKET = global i32 0
@SO_SNDTIMEO = global i32 0
@.str = [8 x i8] c"connect\00"
define i32 @conn_nonb(i32 %0, %struct.sockaddr* %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.timeval*
%6 = bitcast i64* %4 to i8*
store i64 5, i64* %4
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_SNDTIMEO
%9 = call i32 @setsockopt(i32 %0, i32 %7, i32 %8, %struct.timeval* %5, i32 8)
%10 = call i64 @connect(i32 %0, %struct.sockaddr* %1, i32 %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %3, %12
%15 = phi i32 [ -1, %12 ], [ 0, %3 ]
ret i32 %15
}