#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 ifr_flags;
  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);
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int ppp_stat() {
  struct ifreq ifr;
  int s;
  strcpy(ifr.ifr_name, "ppp0");
  s = socket(AF_INET, SOCK_DGRAM, 0);
  if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
    perror("ioctl (SIOCGIFFLAGS)");
    exit(1);
  }
  close(s);
  return (ifr.ifr_flags);
}


x86 assembly (clang, -O0):
<ppp_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    -0x4(%rbp),%edi
lea    0xe8e(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rax
mov    %eax,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11ca <ppp_stat+0x6a>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ppp_stat>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     11b7 <ppp_stat+0x57>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe47(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@.str = [5 x i8] c"ppp0\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIFFLAGS = global i32 0
@.str.1 = [21 x i8] c"ioctl (SIOCGIFFLAGS)\00"
define i32 @ppp_stat() {
%1 = alloca %struct.ifreq
%2 = alloca i32
%3 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i32 0, i32 1
%4 = load i32, i32* %3
%5 = call i32 @strcpy(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = load i32, i32* @SIOCGIFFLAGS
%11 = ptrtoint %struct.ifreq* %1 to i32
%12 = call i64 @ioctl(i32 %9, i32 %10, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* %2
%19 = call i32 @close(i32 %18)
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i32 0, i32 0
%21 = load i32, i32* %20
ret i32 %21
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@.str = [5 x i8] c"ppp0\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCGIFFLAGS = global i32 0
@.str.1 = [21 x i8] c"ioctl (SIOCGIFFLAGS)\00"
define i32 @ppp_stat() {
%1 = alloca %struct.ifreq
%2 = bitcast %struct.ifreq* %1 to i8*
%3 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = load i32, i32* @SIOCGIFFLAGS
%8 = ptrtoint %struct.ifreq* %1 to i64
%9 = trunc i64 %8 to i32
%10 = call i64 @ioctl(i32 %6, i32 %7, i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @close(i32 %6)
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %1, i64 0, i32 0
%18 = load i32, i32* %17
ret i32 %18
}