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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EX_OSERR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int errno;
int ioctl(int, unsigned long, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, int);
int do_req(const char *iface, unsigned long req, void *data) {
  int s;
  struct ifreq ifr;
  int error, serrno;
  if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
    err(EX_OSERR, "Can't create socket");
  memset(&ifr, 0, sizeof(ifr));
  strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
  ifr.ifr_data = data;
  error = ioctl(s, req, &ifr);
  serrno = errno;
  (void)close(s);
  errno = serrno;
  return error;
}


x86 assembly (clang, -O0):
<do_req>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11ae <do_req+0x4e>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1070 <err@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x34(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x38(%rbp),%ecx
mov    0x2dc8(%rip),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_req>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    11ad <do_req+0x4d>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1070 <err@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x10(%rsp),%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %r15,0x8(%rsp)
mov    %r13d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <ioctl@plt>
mov    %eax,%ebx
mov    0x2de2(%rip),%r14
mov    (%r14),%ebp
mov    %r13d,%edi
call   1060 <close@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i8*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@EX_OSERR = global i32 0
@.str = [20 x i8] c"Can't create socket\00"
@errno = global i32 0
define i32 @do_req(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.ifreq
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @EX_OSERR
%17 = call i32 @err(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %3
%19 = call i32 @memset(%struct.ifreq* %8, i32 0, i32 16)
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load i8*, i8** %4
%23 = call i32 @strncpy(i32 %21, i8* %22, i32 4)
%24 = load i8*, i8** %6
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
store i8* %24, i8** %25
%26 = load i32, i32* %7
%27 = load i64, i64* %5
%28 = call i32 @ioctl(i32 %26, i64 %27, %struct.ifreq* %8)
store i32 %28, i32* %9
%29 = load i32, i32* @errno
store i32 %29, i32* %10
%30 = load i32, i32* %7
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %10
store i32 %32, i32* @errno
%33 = load i32, i32* %9
ret i32 %33
}

LLVM IR (-O2):
%struct.ifreq = type { i8*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@EX_OSERR = global i32 0
@.str = [20 x i8] c"Can't create socket\00"
@errno = global i32 0
define i32 @do_req(i8* %0, i64 %1, i8* %2) {
%4 = alloca %struct.ifreq
%5 = bitcast %struct.ifreq* %4 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 eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* @EX_OSERR
%12 = tail call i32 @err(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %3
%14 = call i32 @memset(%struct.ifreq* %4, i32 0, i32 16)
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 1
%16 = load i32, i32* %15
%17 = call i32 @strncpy(i32 %16, i8* %0, i32 4)
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0
store i8* %2, i8** %18
%19 = call i32 @ioctl(i32 %8, i64 %1, %struct.ifreq* %4)
%20 = load i32, i32* @errno
%21 = call i32 @close(i32 %8)
store i32 %20, i32* @errno
ret i32 %19
}