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

/* Variables and functions */
scalar_t__ IN_CLASSA(int);
int IN_CLASSA_NET;
int IN_CLASSA_NSHIFT;
scalar_t__ IN_CLASSB(int);
int IN_CLASSB_NET;
int IN_CLASSB_NSHIFT;
scalar_t__ IN_CLASSC(int);
int IN_CLASSC_NET;
int IN_CLASSC_NSHIFT;
scalar_t__ ntohl(int /*<<< orphan*/);
extern int inet_netof(struct in_addr in) {
  int a = (int)ntohl(in.s_addr);
  if (IN_CLASSA(a))
    return (a & IN_CLASSA_NET) >> IN_CLASSA_NSHIFT;
  if (IN_CLASSB(a))
    return (a & IN_CLASSB_NET) >> IN_CLASSB_NSHIFT;
  if (IN_CLASSC(a))
    return (a & IN_CLASSC_NET) >> IN_CLASSC_NSHIFT;
  return -1;
}


x86 assembly (clang, -O0):
<inet_netof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <IN_CLASSA@plt>
cmp    $0x0,%rax
je     1187 <inet_netof+0x47>
mov    -0xc(%rbp),%eax
mov    0x2e76(%rip),%rcx
and    (%rcx),%eax
mov    0x2e5d(%rip),%rcx
mov    (%rcx),%ecx
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
jmp    11f0 <inet_netof+0xb0>
mov    -0xc(%rbp),%edi
call   1030 <IN_CLASSB@plt>
cmp    $0x0,%rax
je     11b8 <inet_netof+0x78>
mov    -0xc(%rbp),%eax
mov    0x2e3d(%rip),%rcx
and    (%rcx),%eax
mov    0x2e14(%rip),%rcx
mov    (%rcx),%ecx
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
jmp    11f0 <inet_netof+0xb0>
mov    -0xc(%rbp),%edi
call   1040 <IN_CLASSC@plt>
cmp    $0x0,%rax
je     11e9 <inet_netof+0xa9>
mov    -0xc(%rbp),%eax
mov    0x2de4(%rip),%rcx
and    (%rcx),%eax
mov    0x2deb(%rip),%rcx
mov    (%rcx),%ecx
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
jmp    11f0 <inet_netof+0xb0>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_netof>:
push   %rbx
call   1050 <ntohl@plt>
mov    %rax,%rbx
mov    %ebx,%edi
call   1060 <IN_CLASSA@plt>
test   %rax,%rax
je     1167 <inet_netof+0x27>
mov    0x2e8c(%rip),%rax
and    (%rax),%ebx
mov    0x2e73(%rip),%rax
jmp    11a1 <inet_netof+0x61>
mov    %ebx,%edi
call   1030 <IN_CLASSB@plt>
test   %rax,%rax
je     1185 <inet_netof+0x45>
mov    0x2e66(%rip),%rax
and    (%rax),%ebx
mov    0x2e3d(%rip),%rax
jmp    11a1 <inet_netof+0x61>
mov    %ebx,%edi
call   1040 <IN_CLASSC@plt>
test   %rax,%rax
je     11a9 <inet_netof+0x69>
mov    0x2e20(%rip),%rax
and    (%rax),%ebx
mov    0x2e27(%rip),%rax
mov    (%rax),%cl
sar    %cl,%ebx
mov    %ebx,%eax
pop    %rbx
ret
mov    $0xffffffff,%ebx
jmp    11a5 <inet_netof+0x65>

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 i64 @ntohl(i32 %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = call i64 @IN_CLASSA(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %1
%14 = load i32, i32* %4
%15 = load i32, i32* @IN_CLASSA_NET
%16 = and i32 %14, %15
%17 = load i32, i32* @IN_CLASSA_NSHIFT
%18 = ashr i32 %16, %17
store i32 %18, i32* %2
br label %40
19: ; preds = %1
%20 = load i32, i32* %4
%21 = call i64 @IN_CLASSB(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* %4
%25 = load i32, i32* @IN_CLASSB_NET
%26 = and i32 %24, %25
%27 = load i32, i32* @IN_CLASSB_NSHIFT
%28 = ashr i32 %26, %27
store i32 %28, i32* %2
br label %40
29: ; preds = %19
%30 = load i32, i32* %4
%31 = call i64 @IN_CLASSC(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i32, i32* %4
%35 = load i32, i32* @IN_CLASSC_NET
%36 = and i32 %34, %35
%37 = load i32, i32* @IN_CLASSC_NSHIFT
%38 = ashr i32 %36, %37
store i32 %38, i32* %2
br label %40
39: ; preds = %29
store i32 -1, i32* %2
br label %40
40: ; preds = %39, %33, %23, %13
%41 = load i32, i32* %2
ret i32 %41
}

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 i64 @ntohl(i32 %0)
%3 = trunc i64 %2 to i32
%4 = tail call i64 @IN_CLASSA(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = load i32, i32* @IN_CLASSA_NET
%8 = and i32 %7, %3
%9 = load i32, i32* @IN_CLASSA_NSHIFT
%10 = ashr i32 %8, %9
br label %27
11: ; preds = %1
%12 = tail call i64 @IN_CLASSB(i32 %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = load i32, i32* @IN_CLASSB_NET
%16 = and i32 %15, %3
%17 = load i32, i32* @IN_CLASSB_NSHIFT
%18 = ashr i32 %16, %17
br label %27
19: ; preds = %11
%20 = tail call i64 @IN_CLASSC(i32 %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = load i32, i32* @IN_CLASSC_NET
%24 = and i32 %23, %3
%25 = load i32, i32* @IN_CLASSC_NSHIFT
%26 = ashr i32 %24, %25
br label %27
27: ; preds = %19, %22, %14, %6
%28 = phi i32 [ %10, %6 ], [ %18, %14 ], [ %26, %22 ], [ -1, %19 ]
ret i32 %28
}