#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*/ u_int32_t;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
typedef int in_addr_t;
typedef int i;

/* Variables and functions */
scalar_t__ IN_CLASSA(int /*<<< orphan*/);
int /*<<< orphan*/ IN_CLASSA_NET;
int IN_CLASSA_NSHIFT;
scalar_t__ IN_CLASSB(int /*<<< orphan*/);
int /*<<< orphan*/ IN_CLASSB_NET;
int IN_CLASSB_NSHIFT;
int /*<<< orphan*/ IN_CLASSC_NET;
int IN_CLASSC_NSHIFT;
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
in_addr_t inet_netof(struct in_addr in) {
  u_int32_t i = ntohl(in.s_addr);
  if (IN_CLASSA(i))
    return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
  else if (IN_CLASSB(i))
    return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
  else
    return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
}


x86 assembly (clang, -O0):
<inet_netof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <ntohl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <IN_CLASSA@plt>
cmp    $0x0,%rax
je     1177 <inet_netof+0x47>
mov    -0xc(%rbp),%eax
mov    0x2e86(%rip),%rcx
and    (%rcx),%eax
mov    0x2e6d(%rip),%rcx
mov    (%rcx),%ecx
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <inet_netof+0x92>
mov    -0xc(%rbp),%edi
call   1030 <IN_CLASSB@plt>
cmp    $0x0,%rax
je     11a8 <inet_netof+0x78>
mov    -0xc(%rbp),%eax
mov    0x2e4d(%rip),%rcx
and    (%rcx),%eax
mov    0x2e24(%rip),%rcx
mov    (%rcx),%ecx
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
jmp    11c2 <inet_netof+0x92>
mov    -0xc(%rbp),%eax
mov    0x2e06(%rip),%rcx
and    (%rcx),%eax
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%ecx
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_netof>:
push   %rbx
call   1040 <ntohl@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <IN_CLASSA@plt>
test   %rax,%rax
je     1154 <inet_netof+0x24>
mov    0x2e8d(%rip),%rcx
mov    0x2e96(%rip),%rax
jmp    117c <inet_netof+0x4c>
mov    %ebx,%edi
call   1030 <IN_CLASSB@plt>
test   %rax,%rax
mov    0x2e7b(%rip),%rax
cmove  0x2e4b(%rip),%rax
mov    0x2e4c(%rip),%rcx
cmove  0x2e4c(%rip),%rcx
mov    (%rax),%eax
and    %ebx,%eax
mov    (%rcx),%cl
sar    %cl,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@IN_CLASSA_NET = global i32 0
@IN_CLASSA_NSHIFT = global i32 0
@IN_CLASSB_NET = global i32 0
@IN_CLASSB_NSHIFT = global i32 0
@IN_CLASSC_NET = global i32 0
@IN_CLASSC_NSHIFT = global i32 0
define i32 @inet_netof(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.in_addr
%4 = alloca i32
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
store i32 %0, i32* %5
%6 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%7 = load i32, i32* %6
%8 = call i32 @ntohl(i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = call i64 @IN_CLASSA(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load i32, i32* %4
%14 = load i32, i32* @IN_CLASSA_NET
%15 = and i32 %13, %14
%16 = load i32, i32* @IN_CLASSA_NSHIFT
%17 = ashr i32 %15, %16
store i32 %17, i32* %2
br label %34
18: ; preds = %1
%19 = load i32, i32* %4
%20 = call i64 @IN_CLASSB(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load i32, i32* @IN_CLASSB_NET
%25 = and i32 %23, %24
%26 = load i32, i32* @IN_CLASSB_NSHIFT
%27 = ashr i32 %25, %26
store i32 %27, i32* %2
br label %34
28: ; preds = %18
%29 = load i32, i32* %4
%30 = load i32, i32* @IN_CLASSC_NET
%31 = and i32 %29, %30
%32 = load i32, i32* @IN_CLASSC_NSHIFT
%33 = ashr i32 %31, %32
store i32 %33, i32* %2
br label %34
34: ; preds = %28, %22, %12
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@IN_CLASSA_NET = global i32 0
@IN_CLASSA_NSHIFT = global i32 0
@IN_CLASSB_NET = global i32 0
@IN_CLASSB_NSHIFT = global i32 0
@IN_CLASSC_NET = global i32 0
@IN_CLASSC_NSHIFT = global i32 0
define i32 @inet_netof(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 %5, label %10
5: ; preds = %1
%6 = tail call i64 @IN_CLASSB(i32 %2)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i32* @IN_CLASSC_NET, i32* @IN_CLASSB_NET
%9 = select i1 %7, i32* @IN_CLASSC_NSHIFT, i32* @IN_CLASSB_NSHIFT
br label %10
10: ; preds = %5, %1
%11 = phi i32* [ @IN_CLASSA_NET, %1 ], [ %8, %5 ]
%12 = phi i32* [ @IN_CLASSA_NSHIFT, %1 ], [ %9, %5 ]
%13 = load i32, i32* %11
%14 = and i32 %13, %2
%15 = load i32, i32* %12
%16 = ashr i32 %14, %15
ret i32 %16
}