#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 dummy;
};

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ SIOCDEVPRIVATE;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
scalar_t__ ioctl(int, scalar_t__, struct ifreq *);
int get_info_SPEC(int sock, struct ifreq *ifr) {
  if (ioctl(sock, (SIOCDEVPRIVATE + 14), ifr) < 0 && errno != EAGAIN) {
    close(sock);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_info_SPEC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%rsi
add    $0xe,%rsi
mov    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1181 <get_info_SPEC+0x61>
mov    0x2e86(%rip),%rax
mov    (%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
je     1181 <get_info_SPEC+0x61>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <get_info_SPEC+0x68>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_info_SPEC>:
push   %rbx
mov    %rsi,%rdx
mov    %edi,%ebx
mov    0x2e9b(%rip),%rax
mov    (%rax),%rsi
add    $0xe,%rsi
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1145 <get_info_SPEC+0x25>
pop    %rbx
ret
mov    0x2e94(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e7a(%rip),%rdx
cmp    (%rdx),%rcx
je     1143 <get_info_SPEC+0x23>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@SIOCDEVPRIVATE = global i64 0
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @get_info_SPEC(i32 %0, %struct.ifreq* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.ifreq*
store i32 %0, i32* %4
store %struct.ifreq* %1, %struct.ifreq** %5
%6 = load i32, i32* %4
%7 = load i64, i64* @SIOCDEVPRIVATE
%8 = add nsw i64 %7, 14
%9 = load %struct.ifreq*, %struct.ifreq** %5
%10 = call i64 @ioctl(i32 %6, i64 %8, %struct.ifreq* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i64, i64* @errno
%14 = load i64, i64* @EAGAIN
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
store i32 -1, i32* %3
br label %20
19: ; preds = %12, %2
store i32 0, i32* %3
br label %20
20: ; preds = %19, %16
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@SIOCDEVPRIVATE = global i64 0
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @get_info_SPEC(i32 %0, %struct.ifreq* %1) {
%3 = load i64, i64* @SIOCDEVPRIVATE
%4 = add nsw i64 %3, 14
%5 = tail call i64 @ioctl(i32 %0, i64 %4, %struct.ifreq* %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i64, i64* @errno
%9 = load i64, i64* @EAGAIN
%10 = icmp eq i64 %8, %9
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @close(i32 %0)
br label %13
13: ; preds = %2, %7, %11
%14 = phi i32 [ -1, %11 ], [ 0, %7 ], [ 0, %2 ]
ret i32 %14
}