#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int sa_family;
};
struct ifreq {
  TYPE_1__ ifr_hwaddr;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EX_OSERR;
int IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFHWADDR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int get_arphrd_type(char *ifname) {
  int s;
  struct ifreq ifr;
  s = socket(AF_INET, SOCK_DGRAM, 0);
  if (s < 0) {
    dprintf(STDERR_FILENO, "%s:%d: %s: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/jimdigriz/catnip/refs/heads/master/"
            "catnipd.c",
            57, "socket", strerror(errno));
    return -EX_OSERR;
  }
  memset(&ifr, 0, sizeof(ifr));
  strncpy(ifr.ifr_name, ifname, ((10) < (IFNAMSIZ) ? 10 : IFNAMSIZ));
  if (ioctl(s, SIOCGIFHWADDR, &ifr) == -1) {
    dprintf(STDERR_FILENO, "%s:%d: %s: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/jimdigriz/catnip/refs/heads/master/"
            "catnipd.c",
            65, "ioctl[SIOCGIFHWADDR]", strerror(errno));
    close(s);
    return -EX_OSERR;
  }
  close(s);
  return ifr.ifr_hwaddr.sa_family;
}


x86 assembly (clang, -O0):
<get_arphrd_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11f4 <get_arphrd_type+0x84>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%r9d
lea    0xe37(%rip),%rsi
lea    0xe3f(%rip),%rdx
mov    $0x39,%ecx
lea    0xeba(%rip),%r8
call   1070 <dprintf@plt>
xor    %eax,%eax
mov    0x2dc6(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12d4 <get_arphrd_type+0x164>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0xa,%eax
mov    0x2daa(%rip),%rcx
cmp    (%rcx),%eax
jge    1233 <get_arphrd_type+0xc3>
mov    $0xa,%eax
mov    %eax,-0x38(%rbp)
jmp    123f <get_arphrd_type+0xcf>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12c6 <get_arphrd_type+0x156>
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%r9d
lea    0xd6d(%rip),%rsi
lea    0xd75(%rip),%rdx
mov    $0x41,%ecx
lea    0xdf7(%rip),%r8
call   1070 <dprintf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
mov    0x2cf4(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12d4 <get_arphrd_type+0x164>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_arphrd_type>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     11f6 <get_arphrd_type+0x86>
mov    %eax,%ebp
mov    %rsp,%r15
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x4(%rsp),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
cmp    $0xa,%eax
mov    $0xa,%edx
cmovl  %eax,%edx
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1233 <get_arphrd_type+0xc3>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%rsp),%ebx
jmp    1280 <get_arphrd_type+0x110>
mov    0x2dbb(%rip),%rax
mov    (%rax),%ebp
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdec(%rip),%rsi
lea    0xdf4(%rip),%rdx
lea    0xe74(%rip),%r8
mov    %ebp,%edi
mov    $0x39,%ecx
mov    %eax,%r9d
call   1070 <dprintf@plt>
jmp    1277 <get_arphrd_type+0x107>
mov    0x2d7e(%rip),%rax
mov    (%rax),%r14d
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdae(%rip),%rsi
lea    0xdb6(%rip),%rdx
lea    0xe3d(%rip),%r8
mov    %r14d,%edi
mov    $0x41,%ecx
mov    %eax,%r9d
call   1070 <dprintf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2d32(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@STDERR_FILENO = global i32 0
@.str = [15 x i8] c"%s:%d: %s: %s\0A\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jimdigriz/catnip/refs/heads/master/catnipd.c\00"
@.str.2 = [7 x i8] c"socket\00"
@errno = global i32 0
@EX_OSERR = global i32 0
@IFNAMSIZ = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.3 = [21 x i8] c"ioctl[SIOCGIFHWADDR]\00"
define i32 @get_arphrd_type(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.ifreq
store i8* %0, i8** %3
%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* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i32, i32* @STDERR_FILENO
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @dprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @EX_OSERR
%17 = sub nsw i32 0, %16
store i32 %17, i32* %2
br label %50
18: ; preds = %1
%19 = call i32 @memset(%struct.ifreq* %5, i32 0, i32 8)
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load i8*, i8** %3
%23 = load i32, i32* @IFNAMSIZ
%24 = icmp slt i32 10, %23
br i1 %24, label %25, label %26
25: ; preds = %18
br label %28
26: ; preds = %18
%27 = load i32, i32* @IFNAMSIZ
br label %28
28: ; preds = %26, %25
%29 = phi i32 [ 10, %25 ], [ %27, %26 ]
%30 = call i32 @strncpy(i32 %21, i8* %22, i32 %29)
%31 = load i32, i32* %4
%32 = load i32, i32* @SIOCGIFHWADDR
%33 = call i32 @ioctl(i32 %31, i32 %32, %struct.ifreq* %5)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %44
35: ; preds = %28
%36 = load i32, i32* @STDERR_FILENO
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 @dprintf(i32 %36, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %4
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* @EX_OSERR
%43 = sub nsw i32 0, %42
store i32 %43, i32* %2
br label %50
44: ; preds = %28
%45 = load i32, i32* %4
%46 = call i32 @close(i32 %45)
%47 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
%49 = load i32, i32* %48
store i32 %49, i32* %2
br label %50
50: ; preds = %44, %35, %11
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
%struct.ifreq = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@STDERR_FILENO = global i32 0
@.str = [15 x i8] c"%s:%d: %s: %s\0A\00"
@.str.1 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jimdigriz/catnip/refs/heads/master/catnipd.c\00"
@.str.2 = [7 x i8] c"socket\00"
@errno = global i32 0
@EX_OSERR = global i32 0
@IFNAMSIZ = global i32 0
@SIOCGIFHWADDR = global i32 0
@.str.3 = [21 x i8] c"ioctl[SIOCGIFHWADDR]\00"
define i32 @get_arphrd_type(i8* %0) {
%2 = alloca %struct.ifreq
%3 = bitcast %struct.ifreq* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @STDERR_FILENO
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @dprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EX_OSERR
%14 = sub nsw i32 0, %13
br label %38
15: ; preds = %1
%16 = call i32 @memset(%struct.ifreq* %2, i32 0, i32 8)
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 1
%18 = load i32, i32* %17
%19 = load i32, i32* @IFNAMSIZ
%20 = icmp slt i32 %19, 10
%21 = select i1 %20, i32 %19, i32 10
%22 = call i32 @strncpy(i32 %18, i8* %0, i32 %21)
%23 = load i32, i32* @SIOCGIFHWADDR
%24 = call i32 @ioctl(i32 %6, i32 %23, %struct.ifreq* %2)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %34
26: ; preds = %15
%27 = load i32, i32* @STDERR_FILENO
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 @dprintf(i32 %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.1, i64 0, i64 0), i32 65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = call i32 @close(i32 %6)
%32 = load i32, i32* @EX_OSERR
%33 = sub nsw i32 0, %32
br label %38
34: ; preds = %15
%35 = call i32 @close(i32 %6)
%36 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0, i32 0
%37 = load i32, i32* %36
br label %38
38: ; preds = %34, %26, %8
%39 = phi i32 [ %14, %8 ], [ %33, %26 ], [ %37, %34 ]
ret i32 %39
}