#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);
u_long getNaturalBcast(u_long inaddr) {
  if ((!(inaddr & htonl(0x80000000)))) {
    return (inaddr & htonl(0xff000000)) | htonl(0x00ffffff);
  }
  if (((inaddr & htonl(0xc0000000)) == htonl(0x80000000))) {
    return (inaddr & htonl(0xffff0000)) | htonl(0x0000ffff);
  }
  if (((inaddr & htonl(0xe0000000)) == htonl(0xc0000000))) {
    return (inaddr & htonl(0xffffff00)) | htonl(0x000000ff);
  }
  return htonl(0);
}


x86 assembly (clang, -O0):
<getNaturalBcast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    116e <getNaturalBcast+0x5e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0xff000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    $0xffffff,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <getNaturalBcast+0x130>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xc0000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    $0x80000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jne    11d2 <getNaturalBcast+0xc2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0xffff0000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    $0xffff,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <getNaturalBcast+0x130>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0xe0000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    $0xc0000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jne    1236 <getNaturalBcast+0x126>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0xffffff00,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    $0xff,%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <getNaturalBcast+0x130>
xor    %edi,%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNaturalBcast>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x80000000,%edi
call   1030 <htonl@plt>
test   %ebx,%eax
je     114e <getNaturalBcast+0x3e>
mov    %eax,%ebp
mov    $0xc0000000,%edi
call   1030 <htonl@plt>
mov    %eax,%r14d
and    %ebx,%eax
cmp    %ebp,%eax
jne    1163 <getNaturalBcast+0x53>
mov    $0xffff0000,%edi
call   1030 <htonl@plt>
mov    %eax,%ebp
and    %ebx,%ebp
mov    $0xffff,%edi
jmp    1187 <getNaturalBcast+0x77>
mov    $0xff000000,%edi
call   1030 <htonl@plt>
mov    %eax,%ebp
and    %ebx,%ebp
mov    $0xffffff,%edi
jmp    1187 <getNaturalBcast+0x77>
mov    $0xe0000000,%edi
call   1030 <htonl@plt>
and    %ebx,%eax
cmp    %r14d,%eax
jne    1193 <getNaturalBcast+0x83>
mov    $0xffffff00,%edi
call   1030 <htonl@plt>
mov    %eax,%ebp
and    %ebx,%ebp
mov    $0xff,%edi
call   1030 <htonl@plt>
or     %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <htonl@plt>

LLVM IR (-O0):
define i32 @getNaturalBcast(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 %14, label %8
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i32 @htonl(i32 -16777216)
%11 = and i32 %9, %10
%12 = call i32 @htonl(i32 16777215)
%13 = or i32 %11, %12
store i32 %13, i32* %2
br label %40
14: ; preds = %1
%15 = load i32, i32* %3
%16 = call i32 @htonl(i32 -1073741824)
%17 = and i32 %15, %16
%18 = call i32 @htonl(i32 -2147483648)
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load i32, i32* %3
%22 = call i32 @htonl(i32 -65536)
%23 = and i32 %21, %22
%24 = call i32 @htonl(i32 65535)
%25 = or i32 %23, %24
store i32 %25, i32* %2
br label %40
26: ; preds = %14
%27 = load i32, i32* %3
%28 = call i32 @htonl(i32 -536870912)
%29 = and i32 %27, %28
%30 = call i32 @htonl(i32 -1073741824)
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load i32, i32* %3
%34 = call i32 @htonl(i32 -256)
%35 = and i32 %33, %34
%36 = call i32 @htonl(i32 255)
%37 = or i32 %35, %36
store i32 %37, i32* %2
br label %40
38: ; preds = %26
%39 = call i32 @htonl(i32 0)
store i32 %39, i32* %2
br label %40
40: ; preds = %38, %32, %20, %8
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @getNaturalBcast(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 %10
5: ; preds = %1
%6 = tail call i32 @htonl(i32 -16777216)
%7 = and i32 %6, %0
%8 = tail call i32 @htonl(i32 16777215)
%9 = or i32 %7, %8
br label %30
10: ; preds = %1
%11 = tail call i32 @htonl(i32 -1073741824)
%12 = and i32 %11, %0
%13 = icmp eq i32 %12, %2
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = tail call i32 @htonl(i32 -65536)
%16 = and i32 %15, %0
%17 = tail call i32 @htonl(i32 65535)
%18 = or i32 %16, %17
br label %30
19: ; preds = %10
%20 = tail call i32 @htonl(i32 -536870912)
%21 = and i32 %20, %0
%22 = icmp eq i32 %21, %11
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = tail call i32 @htonl(i32 -256)
%25 = and i32 %24, %0
%26 = tail call i32 @htonl(i32 255)
%27 = or i32 %25, %26
br label %30
28: ; preds = %19
%29 = tail call i32 @htonl(i32 0)
br label %30
30: ; preds = %28, %23, %14, %5
%31 = phi i32 [ %18, %14 ], [ %27, %23 ], [ %29, %28 ], [ %9, %5 ]
ret i32 %31
}