#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 {
  size_t ifr_flags;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ _eprintf_exit(int, int, int, char *, char *, ...);
int /*<<< orphan*/ bzero(struct ifreq *, int);
int /*<<< orphan*/ close(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_flags(const char *ifname, size_t flags) {
  int socket_fd;
  struct ifreq ifr;
  socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (socket_fd < 0) {
    _eprintf_exit(0x00, 0x0C, 42,
                  "/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));
  ifr.ifr_flags = flags & 0xffff;
  if (ioctl(socket_fd, SIOCSIFFLAGS, &ifr)) {
    _eprintf_exit(0x00, 0x0B, 51,
                  "/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 interface flags 0x%08x\n", flags);
  }
  close(socket_fd);
}


x86 assembly (clang, -O0):
<do_ioctl_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b7 <do_ioctl_flags+0x57>
xor    %edi,%edi
mov    $0xc,%esi
mov    $0x2a,%edx
lea    0xe57(%rip),%rcx
lea    0xef0(%rip),%r8
mov    $0x0,%al
call   1060 <_eprintf_exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
and    $0xffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     1228 <do_ioctl_flags+0xc8>
mov    -0x10(%rbp),%r9
xor    %edi,%edi
mov    $0xb,%esi
mov    $0x33,%edx
lea    0xde6(%rip),%rcx
lea    0xea5(%rip),%r8
mov    $0x0,%al
call   1060 <_eprintf_exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_ioctl_flags>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11b0 <do_ioctl_flags+0x50>
lea    0xe6a(%rip),%rcx
lea    0xf03(%rip),%r8
xor    %edi,%edi
mov    $0xc,%esi
mov    $0x2a,%edx
xor    %eax,%eax
call   1060 <_eprintf_exit@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    0x10(%rsp),%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movzwl %r14w,%eax
mov    %rax,0x8(%rsp)
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
je     1218 <do_ioctl_flags+0xb8>
lea    0xe05(%rip),%rcx
lea    0xec4(%rip),%r8
xor    %edi,%edi
mov    $0xb,%esi
mov    $0x33,%edx
mov    %r14,%r9
xor    %eax,%eax
call   1060 <_eprintf_exit@plt>
mov    %ebp,%edi
call   1050 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i64, i32 }
@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"
@SIOCSIFFLAGS = global i32 0
@.str.2 = [38 x i8] c"Could not set interface flags 0x%08x\0A\00"
define void @do_ioctl_flags(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.ifreq
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i32, i32, i32, i8*, i8*, ...) @_eprintf_exit(i32 0, i32 12, i32 42, 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 %14
14: ; preds = %12, %2
%15 = call i32 @bzero(%struct.ifreq* %6, i32 16)
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load i8*, i8** %3
%19 = call i32 @strncpy(i32 %17, i8* %18, i32 4)
%20 = load i64, i64* %4
%21 = and i64 %20, 65535
%22 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
store i64 %21, i64* %22
%23 = load i32, i32* %5
%24 = load i32, i32* @SIOCSIFFLAGS
%25 = call i64 @ioctl(i32 %23, i32 %24, %struct.ifreq* %6)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %14
%28 = load i64, i64* %4
%29 = call i32 (i32, i32, i32, i8*, i8*, ...) @_eprintf_exit(i32 0, i32 11, i32 51, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i64 %28)
br label %30
30: ; preds = %27, %14
%31 = load i32, i32* %5
%32 = call i32 @close(i32 %31)
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i64, i32 }
@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"
@SIOCSIFFLAGS = global i32 0
@.str.2 = [38 x i8] c"Could not set interface flags 0x%08x\0A\00"
define void @do_ioctl_flags(i8* %0, i64 %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 (i32, i32, i32, i8*, i8*, ...) @_eprintf_exit(i32 0, i32 12, i32 42, 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 %11
11: ; preds = %9, %2
%12 = call i32 @bzero(%struct.ifreq* %3, i32 16)
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%14 = load i32, i32* %13
%15 = tail call i32 @strncpy(i32 %14, i8* %0, i32 4)
%16 = and i64 %1, 65535
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i64 %16, i64* %17
%18 = load i32, i32* @SIOCSIFFLAGS
%19 = call i64 @ioctl(i32 %7, i32 %18, %struct.ifreq* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %11
%22 = call i32 (i32, i32, i32, i8*, i8*, ...) @_eprintf_exit(i32 0, i32 11, i32 51, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i64 %1)
br label %23
23: ; preds = %21, %11
%24 = call i32 @close(i32 %7)
ret void
}