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

/* Variables and functions */
int htonl(int);
int ntohl(int);
uint32_t get_natural_mask(uint32_t ip) {
  uint32_t iph = ntohl(ip);
  uint8_t msb = iph >> 24;
  if (((msb) >= (1) && (msb) <= (127))) {
    return htonl(0xFF000000);
  }
  if (((msb) >= (128) && (msb) <= (191))) {
    return htonl(0xFFFF0000);
  }
  if (((msb) >= (192) && (msb) <= (223))) {
    return htonl(0xFFFFFF00);
  }
  return 0xFFFFFFFF;
}


x86 assembly (clang, -O0):
<get_natural_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <ntohl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x18,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jl     1165 <get_natural_mask+0x45>
cmpl   $0x7f,-0x10(%rbp)
jg     1165 <get_natural_mask+0x45>
mov    $0xff000000,%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
jmp    11c4 <get_natural_mask+0xa4>
cmpl   $0x80,-0x10(%rbp)
jl     1191 <get_natural_mask+0x71>
cmpl   $0xbf,-0x10(%rbp)
jg     1191 <get_natural_mask+0x71>
mov    $0xffff0000,%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
jmp    11c4 <get_natural_mask+0xa4>
cmpl   $0xc0,-0x10(%rbp)
jl     11bd <get_natural_mask+0x9d>
cmpl   $0xdf,-0x10(%rbp)
jg     11bd <get_natural_mask+0x9d>
mov    $0xffffff00,%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
jmp    11c4 <get_natural_mask+0xa4>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_natural_mask>:
push   %rax
call   1040 <ntohl@plt>
cmp    $0x1000000,%eax
jl     1138 <get_natural_mask+0x18>
mov    $0xff000000,%edi
pop    %rax
jmp    1030 <htonl@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @get_natural_mask(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @ntohl(i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = ashr i32 %8, 24
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* %5
%14 = icmp sle i32 %13, 127
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @htonl(i32 -16777216)
store i32 %16, i32* %2
br label %34
17: ; preds = %12, %1
%18 = load i32, i32* %5
%19 = icmp sge i32 %18, 128
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* %5
%22 = icmp sle i32 %21, 191
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @htonl(i32 -65536)
store i32 %24, i32* %2
br label %34
25: ; preds = %20, %17
%26 = load i32, i32* %5
%27 = icmp sge i32 %26, 192
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* %5
%30 = icmp sle i32 %29, 223
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @htonl(i32 -256)
store i32 %32, i32* %2
br label %34
33: ; preds = %28, %25
store i32 -1, i32* %2
br label %34
34: ; preds = %33, %31, %23, %15
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
define i32 @get_natural_mask(i32 %0) {
%2 = tail call i32 @ntohl(i32 %0)
%3 = icmp sgt i32 %2, 16777215
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @htonl(i32 -16777216)
br label %6
6: ; preds = %1, %4
%7 = phi i32 [ %5, %4 ], [ -1, %1 ]
ret i32 %7
}