#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 */
typedef int uint32_t;

/* Variables and functions */
int mask2bits(int);
char *in_netrange(uint32_t ip, uint32_t ifip, uint32_t ifmask) {
  if (mask2bits(ifmask) != 31) {
    if ((ip & ifmask) != (ifip & ifmask))
      return "Error: the IP address is not in the interface range\n";
    if ((ip & ifmask) == ip)
      return "Error: the IP address is a network address\n";
    else if ((ip | ~ifmask) == ip)
      return "Error: the IP address is a network address\n";
  } else {
    if (ip + 1 != ifip)
      return "Error: the IP address is not in the interface range\n";
  }
  return NULL;
}


x86 assembly (clang, -O0):
<in_netrange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <mask2bits@plt>
cmp    $0x1f,%eax
je     11a3 <in_netrange+0x93>
mov    -0xc(%rbp),%eax
and    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
and    -0x14(%rbp),%ecx
cmp    %ecx,%eax
je     1156 <in_netrange+0x46>
lea    0xeb3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <in_netrange+0xbf>
mov    -0xc(%rbp),%eax
and    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1175 <in_netrange+0x65>
lea    0xec9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <in_netrange+0xbf>
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
xor    $0xffffffff,%ecx
or     %ecx,%eax
cmp    -0xc(%rbp),%eax
jne    1199 <in_netrange+0x89>
lea    0xea5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <in_netrange+0xbf>
jmp    119e <in_netrange+0x8e>
jmp    11c7 <in_netrange+0xb7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cmp    -0x10(%rbp),%eax
je     11c2 <in_netrange+0xb2>
lea    0xe47(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <in_netrange+0xbf>
jmp    11c7 <in_netrange+0xb7>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_netrange>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    %edx,%edi
call   1030 <mask2bits@plt>
cmp    $0x1f,%eax
jne    1130 <in_netrange+0x20>
add    $0x1,%ebx
cmp    %ebp,%ebx
je     1151 <in_netrange+0x41>
jmp    1155 <in_netrange+0x45>
mov    %r14d,%ecx
and    %ebx,%ecx
and    %r14d,%ebp
cmp    %ebp,%ecx
jne    1155 <in_netrange+0x45>
lea    0xef2(%rip),%rax
cmp    %ebx,%ecx
je     115c <in_netrange+0x4c>
not    %r14d
not    %ebx
test   %r14d,%ebx
je     115c <in_netrange+0x4c>
xor    %eax,%eax
jmp    115c <in_netrange+0x4c>
lea    0xea4(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Error: the IP address is not in the interface range\0A\00"
@.str.1 = [44 x i8] c"Error: the IP address is a network address\0A\00"
define i8* @in_netrange(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = call i32 @mask2bits(i32 %8)
%10 = icmp ne i32 %9, 31
br i1 %10, label %11, label %37
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32, i32* %7
%14 = and i32 %12, %13
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = and i32 %15, %16
%18 = icmp ne i32 %14, %17
br i1 %18, label %19, label %20
19: ; preds = %11
store i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8** %4
br label %45
20: ; preds = %11
%21 = load i32, i32* %5
%22 = load i32, i32* %7
%23 = and i32 %21, %22
%24 = load i32, i32* %5
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %20
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %45
27: ; preds = %20
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = xor i32 %29, -1
%31 = or i32 %28, %30
%32 = load i32, i32* %5
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %27
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %45
35: ; preds = %27
br label %36
36: ; preds = %35
br label %44
37: ; preds = %3
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %6
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %37
store i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8** %4
br label %45
43: ; preds = %37
br label %44
44: ; preds = %43, %36
store i8* null, i8** %4
br label %45
45: ; preds = %44, %42, %34, %26, %19
%46 = load i8*, i8** %4
ret i8* %46
}

LLVM IR (-O2):
@.str = [53 x i8] c"Error: the IP address is not in the interface range\0A\00"
@.str.1 = [44 x i8] c"Error: the IP address is a network address\0A\00"
define i8* @in_netrange(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mask2bits(i32 %2)
%5 = icmp eq i32 %4, 31
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = and i32 %2, %0
%8 = and i32 %2, %1
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = icmp eq i32 %7, %0
br i1 %11, label %20, label %12
12: ; preds = %10
%13 = xor i32 %2, -1
%14 = or i32 %13, %0
%15 = icmp eq i32 %14, %0
br i1 %15, label %20, label %19
16: ; preds = %3
%17 = add nsw i32 %0, 1
%18 = icmp eq i32 %17, %1
br i1 %18, label %19, label %20
19: ; preds = %16, %12
br label %20
20: ; preds = %16, %12, %10, %6, %19
%21 = phi i8* [ null, %19 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), %10 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), %12 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), %16 ]
ret i8* %21
}