#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);
scalar_t__ isClassA(int);
scalar_t__ isClassB(int);
scalar_t__ isClassC(int);
u_long getNaturalBcast(u_long inaddr) {
  if (isClassA(inaddr)) {
    return (inaddr & htonl(0xff000000)) | htonl(0x00ffffff);
  }
  if (isClassB(inaddr)) {
    return (inaddr & htonl(0xffff0000)) | htonl(0x0000ffff);
  }
  if (isClassC(inaddr)) {
    return (inaddr & htonl(0xffffff00)) | htonl(0x000000ff);
  }
  return htonl(0);
}


x86 assembly (clang, -O0):
<getNaturalBcast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <isClassA@plt>
cmp    $0x0,%rax
je     1190 <getNaturalBcast+0x50>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0xff000000,%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    $0xffffff,%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <getNaturalBcast+0xe4>
mov    -0x8(%rbp),%edi
call   1060 <isClassB@plt>
cmp    $0x0,%rax
je     11d5 <getNaturalBcast+0x95>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0xffff0000,%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    $0xffff,%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <getNaturalBcast+0xe4>
mov    -0x8(%rbp),%edi
call   1030 <isClassC@plt>
cmp    $0x0,%rax
je     121a <getNaturalBcast+0xda>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0xffffff00,%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    $0xff,%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1224 <getNaturalBcast+0xe4>
xor    %edi,%edi
call   1050 <htonl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNaturalBcast>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1040 <isClassA@plt>
test   %rax,%rax
je     1164 <getNaturalBcast+0x24>
mov    $0xff000000,%edi
call   1050 <htonl@plt>
mov    %eax,%ebp
and    %ebx,%ebp
mov    $0xffffff,%edi
jmp    11a4 <getNaturalBcast+0x64>
mov    %ebx,%edi
call   1060 <isClassB@plt>
test   %rax,%rax
je     1185 <getNaturalBcast+0x45>
mov    $0xffff0000,%edi
call   1050 <htonl@plt>
mov    %eax,%ebp
and    %ebx,%ebp
mov    $0xffff,%edi
jmp    11a4 <getNaturalBcast+0x64>
mov    %ebx,%edi
call   1030 <isClassC@plt>
test   %rax,%rax
je     11b2 <getNaturalBcast+0x72>
mov    $0xffffff00,%edi
call   1050 <htonl@plt>
mov    %eax,%ebp
and    %ebx,%ebp
mov    $0xff,%edi
call   1050 <htonl@plt>
or     %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <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 i64 @isClassA(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i32 @htonl(i32 -16777216)
%10 = and i32 %8, %9
%11 = call i32 @htonl(i32 16777215)
%12 = or i32 %10, %11
store i32 %12, i32* %2
br label %35
13: ; preds = %1
%14 = load i32, i32* %3
%15 = call i64 @isClassB(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* %3
%19 = call i32 @htonl(i32 -65536)
%20 = and i32 %18, %19
%21 = call i32 @htonl(i32 65535)
%22 = or i32 %20, %21
store i32 %22, i32* %2
br label %35
23: ; preds = %13
%24 = load i32, i32* %3
%25 = call i64 @isClassC(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* %3
%29 = call i32 @htonl(i32 -256)
%30 = and i32 %28, %29
%31 = call i32 @htonl(i32 255)
%32 = or i32 %30, %31
store i32 %32, i32* %2
br label %35
33: ; preds = %23
%34 = call i32 @htonl(i32 0)
store i32 %34, i32* %2
br label %35
35: ; preds = %33, %27, %17, %7
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @getNaturalBcast(i32 %0) {
%2 = tail call i64 @isClassA(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i32 @htonl(i32 -16777216)
%6 = and i32 %5, %0
%7 = tail call i32 @htonl(i32 16777215)
%8 = or i32 %6, %7
br label %27
9: ; preds = %1
%10 = tail call i64 @isClassB(i32 %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i32 @htonl(i32 -65536)
%14 = and i32 %13, %0
%15 = tail call i32 @htonl(i32 65535)
%16 = or i32 %14, %15
br label %27
17: ; preds = %9
%18 = tail call i64 @isClassC(i32 %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %17
%21 = tail call i32 @htonl(i32 -256)
%22 = and i32 %21, %0
%23 = tail call i32 @htonl(i32 255)
%24 = or i32 %22, %23
br label %27
25: ; preds = %17
%26 = tail call i32 @htonl(i32 0)
br label %27
27: ; preds = %25, %20, %12, %4
%28 = phi i32 [ %8, %4 ], [ %16, %12 ], [ %24, %20 ], [ %26, %25 ]
ret i32 %28
}