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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int errno;
scalar_t__ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *,
                      int *);
int /*<<< orphan*/ log_message(char *, char *, char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strerror(int);
int check_connect_status(int f) {
  socklen_t len;
  int err;
  len = sizeof(err);
  if (getsockopt(f, SOL_SOCKET, SO_ERROR, &err, &len) != 0) {
    log_message("%s: %s: %s (errno %d)", "check_connect_status", "getsockopt",
                strerror(errno), errno);
    return -1;
  }
  if (err != 0) {
    log_message("%s: %s: %s (errno %d)", "check_connect_status", "connect",
                strerror(err), err);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_connect_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1030 <getsockopt@plt>
cmp    $0x0,%rax
je     11ae <check_connect_status+0x7e>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%ecx
mov    0x2e53(%rip),%rax
mov    (%rax),%r8d
lea    0xe71(%rip),%rdi
lea    0xe80(%rip),%rsi
lea    0xe8e(%rip),%rdx
call   1040 <log_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <check_connect_status+0xc3>
cmpl   $0x0,-0x10(%rbp)
je     11ec <check_connect_status+0xbc>
mov    -0x10(%rbp),%edi
call   1050 <strerror@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%r8d
lea    0xe33(%rip),%rdi
lea    0xe42(%rip),%rsi
lea    0xe5b(%rip),%rdx
call   1040 <log_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <check_connect_status+0xc3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_connect_status>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0xc(%rsp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1030 <getsockopt@plt>
test   %rax,%rax
je     118b <check_connect_status+0x5b>
mov    0x2e6e(%rip),%rbx
mov    (%rbx),%edi
call   1050 <strerror@plt>
mov    (%rbx),%r8d
lea    0xe85(%rip),%rdi
lea    0xe94(%rip),%rsi
lea    0xea2(%rip),%rdx
jmp    11b2 <check_connect_status+0x82>
mov    0x8(%rsp),%edi
test   %edi,%edi
je     11c4 <check_connect_status+0x94>
call   1050 <strerror@plt>
mov    0x8(%rsp),%r8d
lea    0xe5c(%rip),%rdi
lea    0xe6b(%rip),%rsi
lea    0xe84(%rip),%rdx
mov    %eax,%ecx
call   1040 <log_message@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
jmp    11be <check_connect_status+0x8e>

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str = [22 x i8] c"%s: %s: %s (errno %d)\00"
@.str.1 = [21 x i8] c"check_connect_status\00"
@.str.2 = [11 x i8] c"getsockopt\00"
@errno = global i32 0
@.str.3 = [8 x i8] c"connect\00"
define i32 @check_connect_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 4, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_ERROR
%9 = call i64 @getsockopt(i32 %6, i32 %7, i32 %8, i32* %5, i32* %4)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = load i32, i32* @errno
%15 = call i32 @log_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
store i32 -1, i32* %2
br label %25
16: ; preds = %1
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* %5
%21 = call i32 @strerror(i32 %20)
%22 = load i32, i32* %5
%23 = call i32 @log_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %22)
store i32 -1, i32* %2
br label %25
24: ; preds = %16
store i32 0, i32* %2
br label %25
25: ; preds = %24, %19, %11
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str = [22 x i8] c"%s: %s: %s (errno %d)\00"
@.str.1 = [21 x i8] c"check_connect_status\00"
@.str.2 = [11 x i8] c"getsockopt\00"
@errno = global i32 0
@.str.3 = [8 x i8] c"connect\00"
define i32 @check_connect_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %2
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_ERROR
%8 = call i64 @getsockopt(i32 %0, i32 %6, i32 %7, i32* %3, i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = load i32, i32* @errno
%14 = call i32 @log_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %13)
br label %22
15: ; preds = %1
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = call i32 @strerror(i32 %16)
%20 = load i32, i32* %3
%21 = call i32 @log_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %20)
br label %22
22: ; preds = %15, %18, %10
%23 = phi i32 [ -1, %10 ], [ -1, %18 ], [ 0, %15 ]
ret i32 %23
}