#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 {
  short ifr_flags;
};

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ free(struct ifreq *);
scalar_t__ if_IOCTL(struct ifreq *, int /*<<< orphan*/, char *);
struct ifreq *malloc(int);
int get_IFACE_flags(short *FLAGS, char *name) {
  int ret;
  struct ifreq *if_req;
  if_req = malloc(sizeof(struct ifreq));
  if (if_IOCTL(if_req, SIOCGIFFLAGS, name)) {
    return ret;
  }
  *FLAGS = if_req->ifr_flags;
  free(if_req);
  return 0;
}


x86 assembly (clang, -O0):
<get_IFACE_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1050 <if_IOCTL@plt>
cmp    $0x0,%rax
je     1179 <get_IFACE_flags+0x49>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1197 <get_IFACE_flags+0x67>
mov    -0x28(%rbp),%rax
mov    (%rax),%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_IFACE_flags>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1050 <if_IOCTL@plt>
test   %rax,%rax
jne    1170 <get_IFACE_flags+0x40>
movzwl (%rbx),%eax
mov    %ax,(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ifreq = type { i16 }
@SIOCGIFFLAGS = global i32 0
define i32 @get_IFACE_flags(i16* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i16*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.ifreq*
store i16* %0, i16** %4
store i8* %1, i8** %5
%8 = call %struct.ifreq* @malloc(i32 2)
store %struct.ifreq* %8, %struct.ifreq** %7
%9 = load %struct.ifreq*, %struct.ifreq** %7
%10 = load i32, i32* @SIOCGIFFLAGS
%11 = load i8*, i8** %5
%12 = call i64 @if_IOCTL(%struct.ifreq* %9, i32 %10, i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %3
br label %23
16: ; preds = %2
%17 = load %struct.ifreq*, %struct.ifreq** %7
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %17, i32 0, i32 0
%19 = load i16, i16* %18
%20 = load i16*, i16** %4
store i16 %19, i16* %20
%21 = load %struct.ifreq*, %struct.ifreq** %7
%22 = call i32 @free(%struct.ifreq* %21)
store i32 0, i32* %3
br label %23
23: ; preds = %16, %14
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.ifreq = type { i16 }
@SIOCGIFFLAGS = global i32 0
define i32 @get_IFACE_flags(i16* nocapture writeonly %0, i8* %1) {
%3 = tail call %struct.ifreq* @malloc(i32 2)
%4 = load i32, i32* @SIOCGIFFLAGS
%5 = tail call i64 @if_IOCTL(%struct.ifreq* %3, i32 %4, i8* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%9 = load i16, i16* %8
store i16 %9, i16* %0
%10 = tail call i32 @free(%struct.ifreq* %3)
br label %11
11: ; preds = %2, %7
ret i32 0
}