#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*/ err;

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ _debug(char *, int, int /*<<< orphan*/, char *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *strrchr(char *, char);
int is_socket_valid(int sockfd) {
  int err = 0;
  int errlen = sizeof(err);
  if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) {
    _debug((strrchr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/"
                    "heads/master/src/util.c",
                    '/')
                ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                          "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                          "LeonKendy/Wifi/refs/heads/master/src/util.c",
                          '/') +
                      1
                : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/heads/"
                  "master/src/util.c"),
           241, LOG_INFO, "getsockopt(SO_ERROR): %s", strerror(errno));
    return 0;
  }
  if (err) {
    _debug((strrchr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/"
                    "heads/master/src/util.c",
                    '/')
                ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                          "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                          "LeonKendy/Wifi/refs/heads/master/src/util.c",
                          '/') +
                      1
                : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/heads/"
                  "master/src/util.c"),
           246, LOG_INFO, "getsockopt(SO_ERROR): %s", strerror(errno));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_socket_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x4,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1040 <getsockopt@plt>
cmp    $0xffffffff,%eax
jne    1216 <is_socket_valid+0xd6>
lea    0xe75(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
cmp    $0x0,%rax
je     11bd <is_socket_valid+0x7d>
lea    0xe5a(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11cd <is_socket_valid+0x8d>
lea    0xe3c(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11cd <is_socket_valid+0x8d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    %eax,%r8d
mov    $0xf1,%esi
lea    0xe81(%rip),%rcx
call   1050 <_debug@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b9 <is_socket_valid+0x179>
cmpl   $0x0,-0xc(%rbp)
je     12b2 <is_socket_valid+0x172>
lea    0xdd9(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
cmp    $0x0,%rax
je     1259 <is_socket_valid+0x119>
lea    0xdbe(%rip),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1269 <is_socket_valid+0x129>
lea    0xda0(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1269 <is_socket_valid+0x129>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    %eax,%r8d
mov    $0xf6,%esi
lea    0xde5(%rip),%rcx
call   1050 <_debug@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b9 <is_socket_valid+0x179>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_socket_valid>:
push   %rbp
push   %rbx
push   %rax
movl   $0x0,(%rsp)
movl   $0x4,0x4(%rsp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
lea    0x4(%rsp),%r8
call   1030 <getsockopt@plt>
cmp    $0xffffffff,%eax
je     1178 <is_socket_valid+0x48>
mov    $0xf6,%ebx
cmpl   $0x0,(%rsp)
jne    117d <is_socket_valid+0x4d>
mov    $0x1,%eax
jmp    11b0 <is_socket_valid+0x80>
mov    $0xf1,%ebx
mov    0x2e44(%rip),%rax
mov    (%rax),%ebp
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xee4(%rip),%rdi
lea    0xee4(%rip),%rcx
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%r8d
call   1040 <_debug@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/heads/master/src/util.c\00"
@LOG_INFO = global i32 0
@.str.1 = [25 x i8] c"getsockopt(SO_ERROR): %s\00"
@errno = global i32 0
define i32 @is_socket_valid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 4, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_ERROR
%9 = call i32 @getsockopt(i32 %6, i32 %7, i32 %8, i32* %4, i32* %5)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %24
11: ; preds = %1
%12 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%16 = getelementptr inbounds i8, i8* %15, i64 1
br label %18
17: ; preds = %11
br label %18
18: ; preds = %17, %14
%19 = phi i8* [ %16, %14 ], [ getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), %17 ]
%20 = load i32, i32* @LOG_INFO
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @_debug(i8* %19, i32 241, i32 %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 0, i32* %2
br label %41
24: ; preds = %1
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %24
%28 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i8 signext 47)
%32 = getelementptr inbounds i8, i8* %31, i64 1
br label %34
33: ; preds = %27
br label %34
34: ; preds = %33, %30
%35 = phi i8* [ %32, %30 ], [ getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), %33 ]
%36 = load i32, i32* @LOG_INFO
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 @_debug(i8* %35, i32 246, i32 %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %38)
store i32 0, i32* %2
br label %41
40: ; preds = %24
store i32 1, i32* %2
br label %41
41: ; preds = %40, %34, %18
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/heads/master/src/util.c\00"
@LOG_INFO = global i32 0
@.str.1 = [25 x i8] c"getsockopt(SO_ERROR): %s\00"
@errno = global i32 0
define i32 @is_socket_valid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_ERROR
%8 = call i32 @getsockopt(i32 %0, i32 %6, i32 %7, i32* %2, i32* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10, %1
%14 = phi i32 [ 241, %1 ], [ 246, %10 ]
%15 = load i32, i32* @LOG_INFO
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @_debug(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 127), i32 %14, i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %13, %10
%20 = phi i32 [ 1, %10 ], [ 0, %13 ]
ret i32 %20
}