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

/* Variables and functions */
int /*<<< orphan*/ ETH_P_ALL;
int /*<<< orphan*/ IFF_PROMISC;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_PACKET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
void set_promiscuous_mode(char *interface) {
  int sock;
  struct ifreq flags;
  sock = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
  strcpy(flags.ifr_name, interface);
  ioctl(sock, SIOCGIFFLAGS, &flags);
  flags.ifr_flags |= IFF_PROMISC;
  ioctl(sock, SIOCSIFFLAGS, &flags);
  close(sock);
}


x86 assembly (clang, -O0):
<set_promiscuous_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <ioctl@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <ioctl@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_promiscuous_mode>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e5e(%rip),%rax
mov    (%rax),%ebp
mov    0x2e75(%rip),%rax
mov    (%rax),%ebx
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1040 <htons@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rdx
call   1050 <ioctl@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
or     %eax,0x8(%rsp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1050 <ioctl@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@PF_INET = global i32 0
@SOCK_PACKET = global i32 0
@ETH_P_ALL = global i32 0
@SIOCGIFFLAGS = global i32 0
@IFF_PROMISC = global i32 0
@SIOCSIFFLAGS = global i32 0
define void @set_promiscuous_mode(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.ifreq
store i8* %0, i8** %2
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_PACKET
%7 = load i32, i32* @ETH_P_ALL
%8 = call i32 @htons(i32 %7)
%9 = call i32 @socket(i32 %5, i32 %6, i32 %8)
store i32 %9, i32* %3
%10 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load i8*, i8** %2
%13 = call i32 @strcpy(i32 %11, i8* %12)
%14 = load i32, i32* %3
%15 = load i32, i32* @SIOCGIFFLAGS
%16 = call i32 @ioctl(i32 %14, i32 %15, %struct.ifreq* %4)
%17 = load i32, i32* @IFF_PROMISC
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%19 = load i32, i32* %18
%20 = or i32 %19, %17
store i32 %20, i32* %18
%21 = load i32, i32* %3
%22 = load i32, i32* @SIOCSIFFLAGS
%23 = call i32 @ioctl(i32 %21, i32 %22, %struct.ifreq* %4)
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@PF_INET = global i32 0
@SOCK_PACKET = global i32 0
@ETH_P_ALL = global i32 0
@SIOCGIFFLAGS = global i32 0
@IFF_PROMISC = global i32 0
@SIOCSIFFLAGS = global i32 0
define void @set_promiscuous_mode(i8* %0) {
%2 = alloca %struct.ifreq
%3 = bitcast %struct.ifreq* %2 to i8*
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_PACKET
%6 = load i32, i32* @ETH_P_ALL
%7 = tail call i32 @htons(i32 %6)
%8 = tail call i32 @socket(i32 %4, i32 %5, i32 %7)
%9 = tail call i32 @strcpy(i32 undef, i8* %0)
%10 = load i32, i32* @SIOCGIFFLAGS
%11 = call i32 @ioctl(i32 %8, i32 %10, %struct.ifreq* %2)
%12 = load i32, i32* @IFF_PROMISC
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %14, %12
store i32 %15, i32* %13
%16 = load i32, i32* @SIOCSIFFLAGS
%17 = call i32 @ioctl(i32 %8, i32 %16, %struct.ifreq* %2)
%18 = call i32 @close(i32 %8)
ret void
}