#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 sockaddr_in {
  int dummy;
};
struct ifreq {
  int /*<<< orphan*/ ifr_netmask;
};

/* Variables and functions */
int /*<<< orphan*/ SIOCSIFNETMASK;
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ init_sockaddr_in(struct sockaddr_in *, char const *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
void setnetmask(int s, struct ifreq *ifr, const char *addr) {
  init_sockaddr_in((struct sockaddr_in *)&ifr->ifr_netmask, addr);
  if (ioctl(s, SIOCSIFNETMASK, ifr) < 0)
    die("SIOCSIFNETMASK");
}


x86 assembly (clang, -O0):
<setnetmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <init_sockaddr_in@plt>
mov    -0x4(%rbp),%edi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    117b <setnetmask+0x4b>
lea    0xe8a(%rip),%rdi
call   1050 <die@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnetmask>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <init_sockaddr_in@plt>
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     1162 <setnetmask+0x32>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe97(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <die@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32 }
%struct.sockaddr_in = type { i32 }
@SIOCSIFNETMASK = global i32 0
@.str = [15 x i8] c"SIOCSIFNETMASK\00"
define void @setnetmask(i32 %0, %struct.ifreq* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.ifreq*
%6 = alloca i8*
store i32 %0, i32* %4
store %struct.ifreq* %1, %struct.ifreq** %5
store i8* %2, i8** %6
%7 = load %struct.ifreq*, %struct.ifreq** %5
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %7, i32 0, i32 0
%9 = bitcast i32* %8 to %struct.sockaddr_in*
%10 = load i8*, i8** %6
%11 = call i32 @init_sockaddr_in(%struct.sockaddr_in* %9, i8* %10)
%12 = load i32, i32* %4
%13 = load i32, i32* @SIOCSIFNETMASK
%14 = load %struct.ifreq*, %struct.ifreq** %5
%15 = call i64 @ioctl(i32 %12, i32 %13, %struct.ifreq* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %3
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
%struct.sockaddr_in = type { i32 }
@SIOCSIFNETMASK = global i32 0
@.str = [15 x i8] c"SIOCSIFNETMASK\00"
define void @setnetmask(i32 %0, %struct.ifreq* %1, i8* %2) {
%4 = bitcast %struct.ifreq* %1 to %struct.sockaddr_in*
%5 = tail call i32 @init_sockaddr_in(%struct.sockaddr_in* %4, i8* %2)
%6 = load i32, i32* @SIOCSIFNETMASK
%7 = tail call i64 @ioctl(i32 %0, i32 %6, %struct.ifreq* %1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @die(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
ret void
}