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

/* Variables and functions */
int /*<<< orphan*/ INADDR_ANY;
scalar_t__ IN_CLASSA(int /*<<< orphan*/);
int /*<<< orphan*/ IN_CLASSA_NET;
scalar_t__ IN_CLASSB(int /*<<< orphan*/);
int /*<<< orphan*/ IN_CLASSB_NET;
scalar_t__ IN_CLASSC(int /*<<< orphan*/);
int /*<<< orphan*/ IN_CLASSC_NET;
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
uint32_t inet_class_netmask(uint32_t ip) {
  ip = ntohl(ip);
  if (IN_CLASSA(ip))
    return htonl(IN_CLASSA_NET);
  if (IN_CLASSB(ip))
    return htonl(IN_CLASSB_NET);
  if (IN_CLASSC(ip))
    return htonl(IN_CLASSC_NET);
  return INADDR_ANY;
}


x86 assembly (clang, -O0):
<inet_class_netmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <ntohl@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <IN_CLASSA@plt>
cmp    $0x0,%rax
je     118e <inet_class_netmask+0x3e>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
jmp    11ea <inet_class_netmask+0x9a>
mov    -0x8(%rbp),%edi
call   1040 <IN_CLASSB@plt>
cmp    $0x0,%rax
je     11b6 <inet_class_netmask+0x66>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
jmp    11ea <inet_class_netmask+0x9a>
mov    -0x8(%rbp),%edi
call   1050 <IN_CLASSC@plt>
cmp    $0x0,%rax
je     11de <inet_class_netmask+0x8e>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
jmp    11ea <inet_class_netmask+0x9a>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_class_netmask>:
push   %rbx
call   1060 <ntohl@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <IN_CLASSA@plt>
test   %rax,%rax
je     116d <inet_class_netmask+0x1d>
mov    0x2e7d(%rip),%rax
jmp    1195 <inet_class_netmask+0x45>
mov    %ebx,%edi
call   1040 <IN_CLASSB@plt>
test   %rax,%rax
je     1182 <inet_class_netmask+0x32>
mov    0x2e58(%rip),%rax
jmp    1195 <inet_class_netmask+0x45>
mov    %ebx,%edi
call   1050 <IN_CLASSC@plt>
test   %rax,%rax
je     119d <inet_class_netmask+0x4d>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1030 <htonl@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@IN_CLASSA_NET = global i32 0
@IN_CLASSB_NET = global i32 0
@IN_CLASSC_NET = global i32 0
@INADDR_ANY = global i32 0
define i32 @inet_class_netmask(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i32 @ntohl(i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = call i64 @IN_CLASSA(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @IN_CLASSA_NET
%11 = call i32 @htonl(i32 %10)
store i32 %11, i32* %2
br label %28
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i64 @IN_CLASSB(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* @IN_CLASSB_NET
%18 = call i32 @htonl(i32 %17)
store i32 %18, i32* %2
br label %28
19: ; preds = %12
%20 = load i32, i32* %3
%21 = call i64 @IN_CLASSC(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @IN_CLASSC_NET
%25 = call i32 @htonl(i32 %24)
store i32 %25, i32* %2
br label %28
26: ; preds = %19
%27 = load i32, i32* @INADDR_ANY
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %23, %16, %9
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@IN_CLASSA_NET = global i32 0
@IN_CLASSB_NET = global i32 0
@IN_CLASSC_NET = global i32 0
@INADDR_ANY = global i32 0
define i32 @inet_class_netmask(i32 %0) {
%2 = tail call i32 @ntohl(i32 %0)
%3 = tail call i64 @IN_CLASSA(i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* @IN_CLASSA_NET
%7 = tail call i32 @htonl(i32 %6)
br label %22
8: ; preds = %1
%9 = tail call i64 @IN_CLASSB(i32 %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @IN_CLASSB_NET
%13 = tail call i32 @htonl(i32 %12)
br label %22
14: ; preds = %8
%15 = tail call i64 @IN_CLASSC(i32 %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* @IN_CLASSC_NET
%19 = tail call i32 @htonl(i32 %18)
br label %22
20: ; preds = %14
%21 = load i32, i32* @INADDR_ANY
br label %22
22: ; preds = %20, %17, %11, %5
%23 = phi i32 [ %7, %5 ], [ %13, %11 ], [ %19, %17 ], [ %21, %20 ]
ret i32 %23
}