#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct sockaddr_ll {
  int /*<<< orphan*/ sll_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct ifaddrs {
  void *ifa_netmask;
  void *ifa_addr;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ htonl(int);
int /*<<< orphan*/ inet_addr(char *);
void *malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
void init_target(struct ifaddrs *if_sender, char *target) {
  char *slash = strstr(target, "/");
  if_sender->ifa_addr = malloc(sizeof(struct sockaddr));
  if_sender->ifa_netmask = malloc(sizeof(struct sockaddr));
  struct sockaddr_in *ip_sender = (struct sockaddr_in *)if_sender->ifa_addr;
  struct sockaddr_in *mask_sender =
      (struct sockaddr_in *)if_sender->ifa_netmask;
  *slash = '\0';
  ip_sender->sin_addr.s_addr = inet_addr(target);
  memset(((struct sockaddr_ll *)(ip_sender))->sll_addr, 0xff, 6);
  *slash = '/';
  if (slash) {
    int maskbits = atoi(slash + 1);
    if (maskbits < 1 || maskbits > 30) {
      fprintf(stderr, "Invalid net mask bits (1-30): %d\n", maskbits);
      exit(1);
    }
    int mask = 0, i;
    for (i = 0; i < maskbits; i++)
      mask |= 1 << (31 - i);
    mask_sender->sin_addr.s_addr = htonl(mask);
  }
}


x86 assembly (clang, -O0):
<init_target>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0xff,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     12b6 <init_target+0x136>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jl     1247 <init_target+0xc7>
cmpl   $0x1e,-0x2c(%rbp)
jle    1269 <init_target+0xe9>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xda8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12a6 <init_target+0x126>
mov    $0x1f,%ecx
sub    -0x34(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1277 <init_target+0xf7>
mov    -0x30(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_target>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %rax,0x8(%r12)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,(%r12)
movb   $0x0,(%rbx)
mov    %r15,%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x0(%r13)
mov    %eax,%edi
mov    $0xff,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1090 <atoi@plt>
lea    -0x1f(%rax),%ecx
cmp    $0xffffffe2,%ecx
jb     1287 <init_target+0x107>
xor    %ecx,%ecx
mov    $0x0,%edi
cmp    $0x4,%eax
jb     12a8 <init_target+0x128>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%edx
rol    $0x1e,%edx
cmp    $0x5,%edx
ja     123f <init_target+0xbf>
movdqa 0xddb(%rip),%xmm0
lea    0xe44(%rip),%rsi
movslq (%rsi,%rdx,4),%rdx
add    %rsi,%rdx
jmp    *%rdx
movdqa 0xe13(%rip),%xmm0
jmp    126f <init_target+0xef>
movdqa 0xe19(%rip),%xmm0
jmp    126f <init_target+0xef>
movdqa 0xdef(%rip),%xmm0
jmp    126f <init_target+0xef>
movdqa 0xdd5(%rip),%xmm0
jmp    126f <init_target+0xef>
movdqa 0xdbb(%rip),%xmm0
jmp    126f <init_target+0xef>
movdqa 0xda1(%rip),%xmm0
pshufd $0xee,%xmm0,%xmm1
por    %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
por    %xmm1,%xmm0
movd   %xmm0,%edi
jmp    12b4 <init_target+0x134>
mov    0x2d52(%rip),%rcx
mov    (%rcx),%edi
lea    0xdf1(%rip),%rsi
mov    %eax,%edx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x80000000,%edx
shr    %cl,%edx
or     %edx,%edi
add    $0x1,%ecx
cmp    %ecx,%eax
jne    12a8 <init_target+0x128>
call   1040 <htonl@plt>
mov    %eax,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ifaddrs = type { i8*, i8* }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_ll = type { i32 }
@.str = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Invalid net mask bits (1-30): %d\0A\00"
define void @init_target(%struct.ifaddrs* %0, i8* %1) {
%3 = alloca %struct.ifaddrs*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.sockaddr_in*
%7 = alloca %struct.sockaddr_in*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.ifaddrs* %0, %struct.ifaddrs** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = call i8* @strstr(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %5
%13 = call i8* @malloc(i32 4)
%14 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%15 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %14, i32 0, i32 1
store i8* %13, i8** %15
%16 = call i8* @malloc(i32 4)
%17 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%18 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %17, i32 0, i32 0
store i8* %16, i8** %18
%19 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%20 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %19, i32 0, i32 1
%21 = load i8*, i8** %20
%22 = bitcast i8* %21 to %struct.sockaddr_in*
store %struct.sockaddr_in* %22, %struct.sockaddr_in** %6
%23 = load %struct.ifaddrs*, %struct.ifaddrs** %3
%24 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = bitcast i8* %25 to %struct.sockaddr_in*
store %struct.sockaddr_in* %26, %struct.sockaddr_in** %7
%27 = load i8*, i8** %5
store i8 0, i8* %27
%28 = load i8*, i8** %4
%29 = call i32 @inet_addr(i8* %28)
%30 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %29, i32* %32
%33 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%34 = bitcast %struct.sockaddr_in* %33 to %struct.sockaddr_ll*
%35 = getelementptr inbounds %struct.sockaddr_ll, %struct.sockaddr_ll* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @memset(i32 %36, i32 255, i32 6)
%38 = load i8*, i8** %5
store i8 47, i8* %38
%39 = load i8*, i8** %5
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %75
41: ; preds = %2
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = icmp slt i32 %45, 1
br i1 %46, label %50, label %47
47: ; preds = %41
%48 = load i32, i32* %8
%49 = icmp sgt i32 %48, 30
br i1 %49, label %50, label %55
50: ; preds = %47, %41
%51 = load i32, i32* @stderr
%52 = load i32, i32* %8
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %47
store i32 0, i32* %9
store i32 0, i32* %10
br label %56
56: ; preds = %66, %55
%57 = load i32, i32* %10
%58 = load i32, i32* %8
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %69
60: ; preds = %56
%61 = load i32, i32* %10
%62 = sub nsw i32 31, %61
%63 = shl i32 1, %62
%64 = load i32, i32* %9
%65 = or i32 %64, %63
store i32 %65, i32* %9
br label %66
66: ; preds = %60
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
br label %56
69: ; preds = %56
%70 = load i32, i32* %9
%71 = call i32 @htonl(i32 %70)
%72 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %72, i32 0, i32 0
%74 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %73, i32 0, i32 0
store i32 %71, i32* %74
br label %75
75: ; preds = %69, %2
ret void
}

LLVM IR (-O2):
%struct.ifaddrs = type { i8*, i8* }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@stderr = global i32 0
@.str.1 = [34 x i8] c"Invalid net mask bits (1-30): %d\0A\00"
define void @init_target(%struct.ifaddrs* nocapture writeonly %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %1, i32 47)
%4 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%5 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %0, i64 0, i32 1
store i8* %4, i8** %5
%6 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%7 = getelementptr inbounds %struct.ifaddrs, %struct.ifaddrs* %0, i64 0, i32 0
store i8* %6, i8** %7
%8 = bitcast i8* %4 to %struct.sockaddr_in*
store i8 0, i8* %3
%9 = tail call i32 @inet_addr(i8* %1)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0, i32 0
store i32 %9, i32* %10
%11 = tail call i32 @memset(i32 %9, i32 255, i32 6)
store i8 47, i8* %3
%12 = getelementptr inbounds i8, i8* %3, i64 1
%13 = tail call i32 @atoi(i8* %12)
%14 = add i32 %13, -31
%15 = icmp ult i32 %14, -30
br i1 %15, label %37, label %16
16: ; preds = %2
%17 = icmp ult i32 %13, 4
br i1 %17, label %34, label %18
18: ; preds = %16
%19 = and i32 %13, -4
%20 = sub i32 %19, 4
%21 = lshr i32 %20, 2
%22 = shl i32 %20, 30
%23 = or i32 %21, %22
switch i32 %23, label %24 [
i32 0, label %30
i32 1, label %25
i32 2, label %26
i32 3, label %27
i32 4, label %28
i32 5, label %29
]
24: ; preds = %18
br label %30
25: ; preds = %18
br label %30
26: ; preds = %18
br label %30
27: ; preds = %18
br label %30
28: ; preds = %18
br label %30
29: ; preds = %18
br label %30
30: ; preds = %18, %29, %28, %27, %26, %25, %24
%31 = phi <4 x i32> [ <i32 -2147483648, i32 1073741824, i32 536870912, i32 268435456>, %18 ], [ <i32 -2004318080, i32 1145324608, i32 572662304, i32 286331152>, %24 ], [ <i32 -2013265920, i32 1140850688, i32 570425344, i32 285212672>, %25 ], [ <i32 -2004877312, i32 1145044992, i32 572522496, i32 286261248>, %26 ], [ <i32 -2004353024, i32 1145307136, i32 572653568, i32 286326784>, %27 ], [ <i32 -2004320256, i32 1145323520, i32 572661760, i32 286330880>, %28 ], [ <i32 -2004318208, i32 1145324544, i32 572662272, i32 286331136>, %29 ]
%32 = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %31)
%33 = icmp eq i32 %13, %19
br i1 %33, label %48, label %34
34: ; preds = %16, %30
%35 = phi i32 [ 0, %16 ], [ %19, %30 ]
%36 = phi i32 [ 0, %16 ], [ %32, %30 ]
br label %41
37: ; preds = %2
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %34, %41
%42 = phi i32 [ %46, %41 ], [ %35, %34 ]
%43 = phi i32 [ %45, %41 ], [ %36, %34 ]
%44 = lshr i32 -2147483648, %42
%45 = or i32 %44, %43
%46 = add nuw nsw i32 %42, 1
%47 = icmp eq i32 %46, %13
br i1 %47, label %48, label %41
48: ; preds = %41, %30
%49 = phi i32 [ %32, %30 ], [ %45, %41 ]
%50 = bitcast i8* %6 to %struct.sockaddr_in*
%51 = tail call i32 @htonl(i32 %49)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %50, i64 0, i32 0, i32 0
store i32 %51, i32* %52
ret void
}