#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 u_long;

/* Variables and functions */
int htonl(int);
int inet_addr(char *);
u_long getNaturalMask(u_long inaddr) {
  if ((!(inaddr & htonl(0x80000000)))) {
    return inet_addr("255.0.0.0");
  }
  if (((inaddr & htonl(0xc0000000)) == htonl(0x80000000))) {
    return inet_addr("255.255.0.0");
  }
  if (((inaddr & htonl(0xe0000000)) == htonl(0xc0000000))) {
    return inet_addr("255.255.255.0");
  }
  return htonl(0);
}


x86 assembly (clang, -O0):
<getNaturalMask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x80000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
and    %ecx,%eax
cmp    $0x0,%eax
jne    115f <getNaturalMask+0x3f>
lea    0xeae(%rip),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x4(%rbp)
jmp    11f3 <getNaturalMask+0xd3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0xc0000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    $0x80000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jne    11a4 <getNaturalMask+0x84>
lea    0xe73(%rip),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x4(%rbp)
jmp    11f3 <getNaturalMask+0xd3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xe0000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    $0xc0000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jne    11e9 <getNaturalMask+0xc9>
lea    0xe3a(%rip),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x4(%rbp)
jmp    11f3 <getNaturalMask+0xd3>
xor    %edi,%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNaturalMask>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x80000000,%edi
call   1030 <htonl@plt>
test   %ebx,%eax
je     1152 <getNaturalMask+0x32>
mov    %eax,%ebp
mov    $0xc0000000,%edi
call   1030 <htonl@plt>
mov    %eax,%r14d
and    %ebx,%eax
cmp    %ebp,%eax
jne    115b <getNaturalMask+0x3b>
lea    0xeba(%rip),%rdi
jmp    1173 <getNaturalMask+0x53>
lea    0xea7(%rip),%rdi
jmp    1173 <getNaturalMask+0x53>
mov    $0xe0000000,%edi
call   1030 <htonl@plt>
and    %ebx,%eax
cmp    %r14d,%eax
jne    117c <getNaturalMask+0x5c>
lea    0xea3(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <inet_addr@plt>
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <htonl@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"255.0.0.0\00"
@.str.1 = [12 x i8] c"255.255.0.0\00"
@.str.2 = [14 x i8] c"255.255.255.0\00"
define i32 @getNaturalMask(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i32 @htonl(i32 -2147483648)
%6 = and i32 %4, %5
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %9, i32* %2
br label %28
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i32 @htonl(i32 -1073741824)
%13 = and i32 %11, %12
%14 = call i32 @htonl(i32 -2147483648)
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 %17, i32* %2
br label %28
18: ; preds = %10
%19 = load i32, i32* %3
%20 = call i32 @htonl(i32 -536870912)
%21 = and i32 %19, %20
%22 = call i32 @htonl(i32 -1073741824)
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 %25, i32* %2
br label %28
26: ; preds = %18
%27 = call i32 @htonl(i32 0)
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %24, %16, %8
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [10 x i8] c"255.0.0.0\00"
@.str.1 = [12 x i8] c"255.255.0.0\00"
@.str.2 = [14 x i8] c"255.255.255.0\00"
define i32 @getNaturalMask(i32 %0) {
%2 = tail call i32 @htonl(i32 -2147483648)
%3 = and i32 %2, %0
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %21
7: ; preds = %1
%8 = tail call i32 @htonl(i32 -1073741824)
%9 = and i32 %8, %0
%10 = icmp eq i32 %9, %2
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %21
13: ; preds = %7
%14 = tail call i32 @htonl(i32 -536870912)
%15 = and i32 %14, %0
%16 = icmp eq i32 %15, %8
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %21
19: ; preds = %13
%20 = tail call i32 @htonl(i32 0)
br label %21
21: ; preds = %19, %17, %11, %5
%22 = phi i32 [ %12, %11 ], [ %18, %17 ], [ %20, %19 ], [ %6, %5 ]
ret i32 %22
}