#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 scalar_t__ uint32_t;

/* Variables and functions */
scalar_t__ IN_CLASSA(scalar_t__);
int /*<<< orphan*/ IN_CLASSA_NET;
scalar_t__ IN_CLASSB(scalar_t__);
int /*<<< orphan*/ IN_CLASSB_NET;
scalar_t__ IN_CLASSC(scalar_t__);
int /*<<< orphan*/ IN_CLASSC_NET;
scalar_t__ htonl(scalar_t__);
scalar_t__ ntohl(int /*<<< orphan*/);
uint32_t ipv4_getnetmask(uint32_t addr) {
  uint32_t dst;
  if (addr == 0)
    return 0;
  dst = htonl(addr);
  if (IN_CLASSA(dst))
    return ntohl(IN_CLASSA_NET);
  if (IN_CLASSB(dst))
    return ntohl(IN_CLASSB_NET);
  if (IN_CLASSC(dst))
    return ntohl(IN_CLASSC_NET);
  return 0;
}


x86 assembly (clang, -O0):
<ipv4_getnetmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <ipv4_getnetmask+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1207 <ipv4_getnetmask+0xb7>
mov    -0x10(%rbp),%rdi
call   1030 <htonl@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <IN_CLASSA@plt>
cmp    $0x0,%rax
je     11ab <ipv4_getnetmask+0x5b>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1060 <ntohl@plt>
mov    %rax,-0x8(%rbp)
jmp    1207 <ipv4_getnetmask+0xb7>
mov    -0x18(%rbp),%rdi
call   1040 <IN_CLASSB@plt>
cmp    $0x0,%rax
je     11d5 <ipv4_getnetmask+0x85>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1060 <ntohl@plt>
mov    %rax,-0x8(%rbp)
jmp    1207 <ipv4_getnetmask+0xb7>
mov    -0x18(%rbp),%rdi
call   1050 <IN_CLASSC@plt>
cmp    $0x0,%rax
je     11ff <ipv4_getnetmask+0xaf>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1060 <ntohl@plt>
mov    %rax,-0x8(%rbp)
jmp    1207 <ipv4_getnetmask+0xb7>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_getnetmask>:
push   %rbx
test   %rdi,%rdi
je     11a6 <ipv4_getnetmask+0x56>
call   1030 <htonl@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <IN_CLASSA@plt>
test   %rax,%rax
je     1174 <ipv4_getnetmask+0x24>
mov    0x2e76(%rip),%rax
jmp    119e <ipv4_getnetmask+0x4e>
mov    %rbx,%rdi
call   1040 <IN_CLASSB@plt>
test   %rax,%rax
je     118a <ipv4_getnetmask+0x3a>
mov    0x2e58(%rip),%rax
jmp    119e <ipv4_getnetmask+0x4e>
mov    %rbx,%rdi
call   1050 <IN_CLASSC@plt>
test   %rax,%rax
je     11a6 <ipv4_getnetmask+0x56>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1060 <ntohl@plt>
xor    %eax,%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
define i64 @ipv4_getnetmask(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i64 0, i64* %2
br label %32
8: ; preds = %1
%9 = load i64, i64* %3
%10 = call i64 @htonl(i64 %9)
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = call i64 @IN_CLASSA(i64 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* @IN_CLASSA_NET
%16 = call i64 @ntohl(i32 %15)
store i64 %16, i64* %2
br label %32
17: ; preds = %8
%18 = load i64, i64* %4
%19 = call i64 @IN_CLASSB(i64 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* @IN_CLASSB_NET
%23 = call i64 @ntohl(i32 %22)
store i64 %23, i64* %2
br label %32
24: ; preds = %17
%25 = load i64, i64* %4
%26 = call i64 @IN_CLASSC(i64 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @IN_CLASSC_NET
%30 = call i64 @ntohl(i32 %29)
store i64 %30, i64* %2
br label %32
31: ; preds = %24
store i64 0, i64* %2
br label %32
32: ; preds = %31, %28, %21, %14, %7
%33 = load i64, i64* %2
ret i64 %33
}

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