#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_un {
  int dummy;
};
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
scalar_t__ ENOTCONN;
scalar_t__ errno;
scalar_t__ getpeername(int, struct sockaddr *, int *);
int OS_IsFcgi(int sock) {
  union {
    struct sockaddr_in in;
    struct sockaddr_un un;
  } sa;
  int len = sizeof(sa);
  errno = 0;
  if (getpeername(sock, (struct sockaddr *)&sa, &len) != 0 &&
      errno == ENOTCONN) {
    return (1);
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<OS_IsFcgi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0x14(%rbp)
mov    0x2eaf(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <getpeername@plt>
cmp    $0x0,%rax
je     1170 <OS_IsFcgi+0x60>
mov    0x2e87(%rip),%rax
mov    (%rax),%rax
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%rax
jne    1170 <OS_IsFcgi+0x60>
movl   $0x1,-0x4(%rbp)
jmp    1177 <OS_IsFcgi+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OS_IsFcgi>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0x4(%rsp)
mov    0x2eb4(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1030 <getpeername@plt>
test   %rax,%rax
je     1153 <OS_IsFcgi+0x43>
mov    (%rbx),%rcx
mov    0x2e9f(%rip),%rdx
mov    $0x1,%eax
cmp    (%rdx),%rcx
je     1155 <OS_IsFcgi+0x45>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%union.anon = type { %struct.sockaddr_in }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@ENOTCONN = global i64 0
define i32 @OS_IsFcgi(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %union.anon
%5 = alloca i32
store i32 %0, i32* %3
store i32 4, i32* %5
store i64 0, i64* @errno
%6 = load i32, i32* %3
%7 = bitcast %union.anon* %4 to %struct.sockaddr*
%8 = call i64 @getpeername(i32 %6, %struct.sockaddr* %7, i32* %5)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOTCONN
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 1, i32* %2
br label %16
15: ; preds = %10, %1
store i32 0, i32* %2
br label %16
16: ; preds = %15, %14
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
%union.anon = type { %struct.sockaddr_in }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@ENOTCONN = global i64 0
define i32 @OS_IsFcgi(i32 %0) {
%2 = alloca %union.anon
%3 = alloca i32
%4 = bitcast %union.anon* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
store i64 0, i64* @errno
%6 = bitcast %union.anon* %2 to %struct.sockaddr*
%7 = call i64 @getpeername(i32 %0, %struct.sockaddr* %6, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOTCONN
%12 = icmp eq i64 %10, %11
br i1 %12, label %14, label %13
13: ; preds = %9, %1
br label %14
14: ; preds = %9, %13
%15 = phi i32 [ 0, %13 ], [ 1, %9 ]
ret i32 %15
}