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

/* Variables and functions */
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ SIOCSIFADDR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ splice(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/ *,
                          int, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int trigger(int *fildes) {
  int ret;
  struct ifreq ifr;
  memset(&ifr, 0, sizeof(ifr));
  strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
  ret = ioctl(fildes[2], SIOCSIFADDR, &ifr);
  if (ret < 0) {
    printf("[*] Failed to set Econet address.\n");
    return -1;
  }
  splice(fildes[3], NULL, fildes[1], NULL, 128, 0);
  splice(fildes[0], NULL, fildes[2], NULL, 128, 0);
  exit(0);
}


x86 assembly (clang, -O0):
<trigger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
lea    0xe71(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1070 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11d1 <trigger+0x71>
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x80,%r8d
xor    %r9d,%r9d
mov    %rcx,%rsi
call   1040 <splice@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x80,%r8d
xor    %r9d,%r9d
mov    %rcx,%rsi
call   1040 <splice@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<trigger>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    (%rsp),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
lea    0xe74(%rip),%rsi
call   1030 <strncpy@plt>
mov    0x8(%r14),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1070 <ioctl@plt>
test   %eax,%eax
jns    11c3 <trigger+0x63>
lea    0xe54(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x4(%r14),%edx
mov    0xc(%r14),%edi
xor    %esi,%esi
xor    %ecx,%ecx
mov    $0x80,%r8d
xor    %r9d,%r9d
call   1040 <splice@plt>
mov    (%r14),%edi
mov    0x8(%r14),%edx
xor    %esi,%esi
xor    %ecx,%ecx
mov    $0x80,%r8d
xor    %r9d,%r9d
call   1040 <splice@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@.str = [5 x i8] c"eth0\00"
@IFNAMSIZ = global i32 0
@SIOCSIFADDR = global i32 0
@.str.1 = [35 x i8] c"[*] Failed to set Econet address.\0A\00"
define i32 @trigger(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca %struct.ifreq
store i32* %0, i32** %2
%5 = call i32 @memset(%struct.ifreq* %4, i32 0, i32 4)
%6 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @IFNAMSIZ
%9 = call i32 @strncpy(i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i64 2
%12 = load i32, i32* %11
%13 = load i32, i32* @SIOCSIFADDR
%14 = call i32 @ioctl(i32 %12, i32 %13, %struct.ifreq* %4)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
19: ; preds = %1
%20 = load i32*, i32** %2
%21 = getelementptr inbounds i32, i32* %20, i64 3
%22 = load i32, i32* %21
%23 = load i32*, i32** %2
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = load i32, i32* %24
%26 = call i32 @splice(i32 %22, i32* null, i32 %25, i32* null, i32 128, i32 0)
%27 = load i32*, i32** %2
%28 = getelementptr inbounds i32, i32* %27, i64 0
%29 = load i32, i32* %28
%30 = load i32*, i32** %2
%31 = getelementptr inbounds i32, i32* %30, i64 2
%32 = load i32, i32* %31
%33 = call i32 @splice(i32 %29, i32* null, i32 %32, i32* null, i32 128, i32 0)
%34 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@.str = [5 x i8] c"eth0\00"
@IFNAMSIZ = global i32 0
@SIOCSIFADDR = global i32 0
@str = [34 x i8] c"[*] Failed to set Econet address.\00"
define i32 @trigger(i32* nocapture %0) {
%2 = alloca %struct.ifreq
%3 = bitcast %struct.ifreq* %2 to i8*
%4 = call i32 @memset(%struct.ifreq* %2, i32 0, i32 4)
%5 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0
%6 = load i32, i32* %5
%7 = load i32, i32* @IFNAMSIZ
%8 = call i32 @strncpy(i32 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds i32, i32* %0, i64 2
%10 = load i32, i32* %9
%11 = load i32, i32* @SIOCSIFADDR
%12 = call i32 @ioctl(i32 %10, i32 %11, %struct.ifreq* %2)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
ret i32 -1
16: ; preds = %1
%17 = getelementptr inbounds i32, i32* %0, i64 3
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @splice(i32 %18, i32* null, i32 %20, i32* null, i32 128, i32 0)
%22 = load i32, i32* %0
%23 = load i32, i32* %9
%24 = call i32 @splice(i32 %22, i32* null, i32 %23, i32* null, i32 128, i32 0)
%25 = call i32 @exit(i32 0)
unreachable
}