#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*/ type;
struct sockaddr_in {
  scalar_t__ sin_family;
};
typedef int socklen_t;

/* Variables and functions */
scalar_t__ AF_INET;
int SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_TYPE;
scalar_t__ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *,
                      int *);
int is_redirectable(int sockfd, struct sockaddr_in *sin) {
  int result, type;
  socklen_t type_length = sizeof(type);
  if (AF_INET != sin->sin_family) {
    goto out0;
  }
  if (getsockopt(sockfd, SOL_SOCKET, SO_TYPE, &type, &type_length)) {
    goto out0;
  }
  if (SOCK_STREAM != type) {
    goto out0;
  }
  result = 1;
out:
  return result;
out0:
  result = 0;
  goto out;
}


x86 assembly (clang, -O0):
<is_redirectable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    0x2eb3(%rip),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
je     1142 <is_redirectable+0x32>
jmp    119a <is_redirectable+0x8a>
mov    -0x4(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1030 <getsockopt@plt>
cmp    $0x0,%rax
je     1173 <is_redirectable+0x63>
jmp    119a <is_redirectable+0x8a>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
cmp    -0x18(%rbp),%eax
je     118a <is_redirectable+0x7a>
jmp    119a <is_redirectable+0x8a>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
movl   $0x0,-0x14(%rbp)
jmp    1191 <is_redirectable+0x81>

x86 assembly (clang, -O2):
<is_redirectable>:
push   %rax
movl   $0x4,(%rsp)
mov    0x2ec1(%rip),%rax
mov    (%rax),%rax
cmp    (%rsi),%rax
jne    115f <is_redirectable+0x4f>
mov    0x2eba(%rip),%rax
mov    (%rax),%esi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
call   1030 <getsockopt@plt>
test   %rax,%rax
jne    115f <is_redirectable+0x4f>
mov    0x2e76(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%eax
cmp    0x4(%rsp),%ecx
je     1161 <is_redirectable+0x51>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i64 }
@AF_INET = global i64 0
@SOL_SOCKET = global i32 0
@SO_TYPE = global i32 0
@SOCK_STREAM = global i32 0
define i32 @is_redirectable(i32 %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %4
store i32 4, i32* %7
%8 = load i64, i64* @AF_INET
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = icmp ne i64 %8, %11
br i1 %12, label %13, label %14
13: ; preds = %2
br label %29
14: ; preds = %2
%15 = load i32, i32* %3
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_TYPE
%18 = call i64 @getsockopt(i32 %15, i32 %16, i32 %17, i32* %6, i32* %7)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
br label %29
21: ; preds = %14
%22 = load i32, i32* @SOCK_STREAM
%23 = load i32, i32* %6
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
br label %29
26: ; preds = %21
store i32 1, i32* %5
br label %27
27: ; preds = %29, %26
%28 = load i32, i32* %5
ret i32 %28
29: ; preds = %25, %20, %13
store i32 0, i32* %5
br label %27
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i64 }
@AF_INET = global i64 0
@SOL_SOCKET = global i32 0
@SO_TYPE = global i32 0
@SOCK_STREAM = global i32 0
define i32 @is_redirectable(i32 %0, %struct.sockaddr_in* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%7 = load i64, i64* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%9 = load i64, i64* %8
%10 = icmp eq i64 %7, %9
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_TYPE
%14 = call i64 @getsockopt(i32 %0, i32 %12, i32 %13, i32* %3, i32* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32, i32* @SOCK_STREAM
%18 = load i32, i32* %3
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16, %22
%21 = phi i32 [ 0, %22 ], [ 1, %16 ]
ret i32 %21
22: ; preds = %16, %11, %2
br label %20
}