#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 {
  scalar_t__ ifr_data;
  int /*<<< orphan*/ ifr_name;
};
struct ethtool_value {
  int cmd;
  scalar_t__ data;
};
typedef int /*<<< orphan*/ ifr;
typedef scalar_t__ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCETHTOOL;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ _eprintf_exit(int, int, int, char *, char *);
int /*<<< orphan*/ bzero(struct ifreq *, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
void do_ioctl_ethtool(const char *ifname, int subcmd) {
  int socket_fd;
  struct ifreq ifr;
  socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (socket_fd < 0) {
    _eprintf_exit(0x00, 0x0C, 67,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/mgrosvenor/camio1.0/refs/"
                  "heads/master/istreams/camio_istream_netmap.c",
                  "Could not open device control socket\n");
  }
  bzero(&ifr, sizeof(ifr));
  strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  struct ethtool_value eval;
  eval.cmd = subcmd;
  eval.data = 0;
  ifr.ifr_data = (caddr_t)&eval;
  if (ioctl(socket_fd, SIOCETHTOOL, &ifr)) {
    _eprintf_exit(0x00, 0x0B, 79,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/mgrosvenor/camio1.0/refs/"
                  "heads/master/istreams/camio_istream_netmap.c",
                  "Could not set ethtool value\n");
  }
}


x86 assembly (clang, -O0):
<do_ioctl_ethtool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11a4 <do_ioctl_ethtool+0x54>
xor    %edi,%edi
mov    $0xc,%esi
mov    $0x43,%edx
lea    0xe68(%rip),%rcx
lea    0xf01(%rip),%r8
call   1050 <_eprintf_exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
call   1060 <bzero@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     1217 <do_ioctl_ethtool+0xc7>
xor    %edi,%edi
mov    $0xb,%esi
mov    $0x4f,%edx
lea    0xdf5(%rip),%rcx
lea    0xeb4(%rip),%r8
call   1050 <_eprintf_exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_ioctl_ethtool>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    119e <do_ioctl_ethtool+0x4e>
lea    0xe7a(%rip),%rcx
lea    0xf13(%rip),%r8
xor    %edi,%edi
mov    $0xc,%esi
mov    $0x43,%edx
call   1050 <_eprintf_exit@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1060 <bzero@plt>
mov    0x20(%rsp),%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %r14d,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
je     1210 <do_ioctl_ethtool+0xc0>
lea    0xe08(%rip),%rcx
lea    0xec7(%rip),%r8
xor    %edi,%edi
mov    $0xb,%esi
mov    $0x4f,%edx
call   1050 <_eprintf_exit@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i64, i32 }
%struct.ethtool_value = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mgrosvenor/camio1.0/refs/heads/master/istreams/camio_istream_netmap.c\00"
@.str.1 = [38 x i8] c"Could not open device control socket\0A\00"
@SIOCETHTOOL = global i32 0
@.str.2 = [29 x i8] c"Could not set ethtool value\0A\00"
define void @do_ioctl_ethtool(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.ifreq
%7 = alloca %struct.ethtool_value
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @_eprintf_exit(i32 0, i32 12, i32 67, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = call i32 @bzero(%struct.ifreq* %6, i32 16)
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load i8*, i8** %3
%20 = call i32 @strncpy(i32 %18, i8* %19, i32 4)
%21 = load i32, i32* %4
%22 = getelementptr inbounds %struct.ethtool_value, %struct.ethtool_value* %7, i32 0, i32 0
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.ethtool_value, %struct.ethtool_value* %7, i32 0, i32 1
store i64 0, i64* %23
%24 = ptrtoint %struct.ethtool_value* %7 to i64
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
store i64 %24, i64* %25
%26 = load i32, i32* %5
%27 = load i32, i32* @SIOCETHTOOL
%28 = call i64 @ioctl(i32 %26, i32 %27, %struct.ifreq* %6)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %15
%31 = call i32 @_eprintf_exit(i32 0, i32 11, i32 79, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %15
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i64, i32 }
%struct.ethtool_value = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/mgrosvenor/camio1.0/refs/heads/master/istreams/camio_istream_netmap.c\00"
@.str.1 = [38 x i8] c"Could not open device control socket\0A\00"
@SIOCETHTOOL = global i32 0
@.str.2 = [29 x i8] c"Could not set ethtool value\0A\00"
define void @do_ioctl_ethtool(i8* %0, i32 %1) {
%3 = alloca %struct.ifreq
%4 = alloca %struct.ethtool_value
%5 = bitcast %struct.ifreq* %3 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @_eprintf_exit(i32 0, i32 12, i32 67, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = call i32 @bzero(%struct.ifreq* %3, i32 16)
%14 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%15 = load i32, i32* %14
%16 = tail call i32 @strncpy(i32 %15, i8* %0, i32 4)
%17 = bitcast %struct.ethtool_value* %4 to i8*
%18 = getelementptr inbounds %struct.ethtool_value, %struct.ethtool_value* %4, i64 0, i32 0
store i32 %1, i32* %18
%19 = getelementptr inbounds %struct.ethtool_value, %struct.ethtool_value* %4, i64 0, i32 1
store i64 0, i64* %19
%20 = ptrtoint %struct.ethtool_value* %4 to i64
%21 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i64 %20, i64* %21
%22 = load i32, i32* @SIOCETHTOOL
%23 = call i64 @ioctl(i32 %8, i32 %22, %struct.ifreq* %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %12
%26 = call i32 @_eprintf_exit(i32 0, i32 11, i32 79, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %12
ret void
}