#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;
typedef void *caddr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ exit(int);
int ioctl(int, int, ...);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd = 0;
  struct ifreq ifr;
  int err = 0;
  unsigned long go = 696969;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (fd == -1) {
    perror("socket");
    exit(1);
  }
  memset(&ifr, 0, sizeof(ifr));
  strncpy(ifr.ifr_name, "test0", IFNAMSIZ);
  ioctl(fd, (0x89F0));
  err = ioctl(fd, (0x89F1), &ifr);
  if (err == -1) {
    perror("ioctl");
    exit(1);
  }
  ioctl(fd, (0x89F2), &ifr);
  ioctl(fd, (0x89F2), &ifr);
  ifr.ifr_data = (caddr_t)&go;
  err = ioctl(fd, (0x89F3), &ifr);
  if (err == -1) {
    perror("ioctl");
    exit(1);
  }
  go = 31337;
  ifr.ifr_data = (caddr_t)&go;
  err = ioctl(fd, (0x89F4), &ifr);
  if (err == -1) {
    perror("ioctl");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0xaa289,-0x38(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c8 <main+0x68>
lea    0xe47(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
lea    0xe1c(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
mov    $0x89f0,%esi
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x89f1,%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1235 <main+0xd5>
lea    0xde7(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x89f2,%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    $0x89f2,%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
lea    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x89f3,%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1299 <main+0x139>
lea    0xd83(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movq   $0x7a69,-0x38(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x89f4,%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12df <main+0x17f>
lea    0xd3d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movq   $0xaa289,0x8(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
cmp    $0xffffffff,%eax
je     1269 <main+0x109>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x18(%rsp),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
lea    0xe49(%rip),%rsi
call   1030 <strncpy@plt>
mov    %ebx,%edi
mov    $0x89f0,%esi
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %ebx,%edi
mov    $0x89f1,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0x100>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    $0x89f2,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <ioctl@plt>
mov    %ebx,%edi
mov    $0x89f2,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <ioctl@plt>
lea    0x8(%rsp),%r15
mov    %r15,0x10(%rsp)
mov    %ebx,%edi
mov    $0x89f3,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0x100>
movq   $0x7a69,0x8(%rsp)
mov    %r15,0x10(%rsp)
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    $0x89f4,%esi
xor    %eax,%eax
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0x100>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xda6(%rip),%rdi
jmp    1270 <main+0x110>
lea    0xd90(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i8*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [6 x i8] c"test0\00"
@IFNAMSIZ = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.ifreq
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %8
store i64 696969, i64* %9
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i32 @memset(%struct.ifreq* %7, i32 0, i32 16)
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load i32, i32* @IFNAMSIZ
%23 = call i32 @strncpy(i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %6
%25 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 35312)
%26 = load i32, i32* %6
%27 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 35313, %struct.ifreq* %7)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %18
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18
%34 = load i32, i32* %6
%35 = call i32 (i32, i32, ...) @ioctl(i32 %34, i32 35314, %struct.ifreq* %7)
%36 = load i32, i32* %6
%37 = call i32 (i32, i32, ...) @ioctl(i32 %36, i32 35314, %struct.ifreq* %7)
%38 = bitcast i64* %9 to i8*
%39 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
store i8* %38, i8** %39
%40 = load i32, i32* %6
%41 = call i32 (i32, i32, ...) @ioctl(i32 %40, i32 35315, %struct.ifreq* %7)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %33
%45 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %33
store i64 31337, i64* %9
%48 = bitcast i64* %9 to i8*
%49 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
store i8* %48, i8** %49
%50 = load i32, i32* %6
%51 = call i32 (i32, i32, ...) @ioctl(i32 %50, i32 35316, %struct.ifreq* %7)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %47
%55 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
%struct.ifreq = type { i8*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [6 x i8] c"test0\00"
@IFNAMSIZ = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.ifreq
%4 = alloca i64
%5 = bitcast %struct.ifreq* %3 to i8*
%6 = bitcast i64* %4 to i8*
store i64 696969, i64* %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 16)
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%17 = load i32, i32* %16
%18 = load i32, i32* @IFNAMSIZ
%19 = call i32 @strncpy(i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 35312)
%21 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 35313, %struct.ifreq* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %14
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %14
%27 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 35314, %struct.ifreq* %3)
%28 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 35314, %struct.ifreq* %3)
%29 = bitcast %struct.ifreq* %3 to i64**
store i64* %4, i64** %29
%30 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 35315, %struct.ifreq* %3)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %26
store i64 31337, i64* %4
store i64* %4, i64** %29
%36 = call i32 (i32, i32, ...) @ioctl(i32 %9, i32 35316, %struct.ifreq* %3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %35
ret i32 0
}