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

/* Variables and functions */
scalar_t__ IFNAMSIZ;
int /*<<< orphan*/ fatal_error(char *);
scalar_t__ ioctl(int, int, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, char, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, scalar_t__);
void get_ifinfo(struct ifreq *ans, int sock_fd, const char *ifname, int query) {
  memset(ans, '\0', sizeof(struct ifreq));
  strncpy(ans->ifr_name, ifname, (IFNAMSIZ - 1));
  if (ioctl(sock_fd, query, ans) < 0)
    fatal_error("ioctl()");
}


x86 assembly (clang, -O0):
<get_ifinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    0x2e69(%rip),%rax
mov    (%rax),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11a8 <get_ifinfo+0x68>
lea    0xe5d(%rip),%rdi
call   1060 <fatal_error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ifinfo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%rbp
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x0(%rbp),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%rdx
add    $0xffffffffffffffff,%rdx
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %rbp,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
js     1196 <get_ifinfo+0x56>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe63(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fatal_error@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@IFNAMSIZ = global i64 0
@.str = [8 x i8] c"ioctl()\00"
define void @get_ifinfo(%struct.ifreq* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.ifreq*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store %struct.ifreq* %0, %struct.ifreq** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load %struct.ifreq*, %struct.ifreq** %5
%10 = call i32 @memset(%struct.ifreq* %9, i8 signext 0, i32 4)
%11 = load %struct.ifreq*, %struct.ifreq** %5
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i8*, i8** %7
%15 = load i64, i64* @IFNAMSIZ
%16 = sub nsw i64 %15, 1
%17 = call i32 @strncpy(i32 %13, i8* %14, i64 %16)
%18 = load i32, i32* %6
%19 = load i32, i32* %8
%20 = load %struct.ifreq*, %struct.ifreq** %5
%21 = call i64 @ioctl(i32 %18, i32 %19, %struct.ifreq* %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %4
%24 = call i32 @fatal_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %4
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@IFNAMSIZ = global i64 0
@.str = [8 x i8] c"ioctl()\00"
define void @get_ifinfo(%struct.ifreq* %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 @memset(%struct.ifreq* %0, i8 signext 0, i32 4)
%6 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = load i64, i64* @IFNAMSIZ
%9 = add nsw i64 %8, -1
%10 = tail call i32 @strncpy(i32 %7, i8* %2, i64 %9)
%11 = tail call i64 @ioctl(i32 %1, i32 %3, %struct.ifreq* %0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = tail call i32 @fatal_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %4
ret void
}