#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 ifreq {
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlcpy(int /*<<< orphan*/, char *, int);
int ppp_available() {
  int s, ok;
  struct ifreq ifr;
  extern char *no_ppp_msg;
  if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    return 1;
  strlcpy(ifr.ifr_name, "ppp0", sizeof(ifr.ifr_name));
  ok = ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) >= 0;
  close(s);
  no_ppp_msg = "This system lacks kernel support for PPP.  To include PPP "
               "support\nin the kernel, please follow the steps detailed in "
               "the README.ultrix\nfile in the ppp-2.2 distribution.\n";
  return ok;
}


x86 assembly (clang, -O0):
<ppp_available>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1179 <ppp_available+0x39>
movl   $0x1,-0x4(%rbp)
jmp    11d2 <ppp_available+0x92>
mov    -0x10(%rbp),%edi
lea    0xe7d(%rip),%rsi
mov    $0x4,%edx
call   1050 <strlcpy@plt>
mov    -0x8(%rbp),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rax
mov    %eax,%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    0x2e06(%rip),%rax
lea    0xe3c(%rip),%rcx
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppp_available>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11aa <ppp_available+0x6a>
mov    %eax,%ebp
lea    0xe97(%rip),%rsi
mov    $0x4,%edx
call   1050 <strlcpy@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1030 <ioctl@plt>
mov    %rax,%rbx
shr    $0x3f,%rbx
xor    $0x1,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
lea    0xe67(%rip),%rax
mov    0x2e23(%rip),%rcx
mov    %rax,(%rcx)
jmp    11af <ppp_available+0x6f>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [5 x i8] c"ppp0\00"
@SIOCGIFFLAGS = global i32 0
@.str.1 = [170 x i8] c"This system lacks kernel support for PPP. To include PPP support\0Ain the kernel, please follow the steps detailed in the README.ultrix\0Afile in the ppp-2.2 distribution.\0A\00"
@no_ppp_msg = external global i8*
define i32 @ppp_available() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.ifreq
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 1, i32* %1
br label %23
10: ; preds = %0
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @strlcpy(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = load i32, i32* %2
%15 = load i32, i32* @SIOCGIFFLAGS
%16 = ptrtoint %struct.ifreq* %4 to i32
%17 = call i64 @ioctl(i32 %14, i32 %15, i32 %16)
%18 = icmp sge i64 %17, 0
%19 = zext i1 %18 to i32
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
store i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i8** @no_ppp_msg
%22 = load i32, i32* %3
store i32 %22, i32* %1
br label %23
23: ; preds = %10, %9
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [5 x i8] c"ppp0\00"
@SIOCGIFFLAGS = global i32 0
@.str.1 = [170 x i8] c"This system lacks kernel support for PPP. To include PPP support\0Ain the kernel, please follow the steps detailed in the README.ultrix\0Afile in the ppp-2.2 distribution.\0A\00"
@no_ppp_msg = external global i8*
define i32 @ppp_available() {
%1 = alloca %struct.ifreq
%2 = bitcast %struct.ifreq* %1 to i8*
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %0
%8 = tail call i32 @strlcpy(i32 undef, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = load i32, i32* @SIOCGIFFLAGS
%10 = ptrtoint %struct.ifreq* %1 to i64
%11 = trunc i64 %10 to i32
%12 = call i64 @ioctl(i32 %5, i32 %9, i32 %11)
%13 = lshr i64 %12, 63
%14 = trunc i64 %13 to i32
%15 = xor i32 %14, 1
%16 = call i32 @close(i32 %5)
store i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i8** @no_ppp_msg
br label %17
17: ; preds = %0, %7
%18 = phi i32 [ %15, %7 ], [ 1, %0 ]
ret i32 %18
}