#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;
};

/* Variables and functions */
scalar_t__ IN_CLASSA(int /*<<< orphan*/);
int /*<<< orphan*/ IN_CLASSA_NET;
scalar_t__ IN_CLASSB(int /*<<< orphan*/);
int /*<<< orphan*/ IN_CLASSB_NET;
int /*<<< orphan*/ IN_CLASSC_NET;
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
u_int32_t net_mask(struct in_addr in) {
  register u_int32_t i = ntohl(in.s_addr);
  if (IN_CLASSA(i))
    return (htonl(IN_CLASSA_NET));
  else if (IN_CLASSB(i))
    return (htonl(IN_CLASSB_NET));
  return (htonl(IN_CLASSC_NET));
}


x86 assembly (clang, -O0):
<net_mask>:
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     117e <net_mask+0x3e>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
jmp    11bc <net_mask+0x7c>
mov    -0xc(%rbp),%edi
call   1040 <IN_CLASSB@plt>
cmp    $0x0,%rax
je     11a6 <net_mask+0x66>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
jmp    11bc <net_mask+0x7c>
jmp    11ab <net_mask+0x6b>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_mask>:
push   %rbx
call   1050 <ntohl@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <IN_CLASSA@plt>
test   %rax,%rax
je     115d <net_mask+0x1d>
mov    0x2e8d(%rip),%rax
jmp    1179 <net_mask+0x39>
mov    %ebx,%edi
call   1040 <IN_CLASSB@plt>
test   %rax,%rax
jne    1172 <net_mask+0x32>
mov    0x2e60(%rip),%rax
jmp    1179 <net_mask+0x39>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1030 <htonl@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@IN_CLASSA_NET = global i32 0
@IN_CLASSB_NET = global i32 0
@IN_CLASSC_NET = global i32 0
define i32 @net_mask(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 %15
12: ; preds = %1
%13 = load i32, i32* @IN_CLASSA_NET
%14 = call i32 @htonl(i32 %13)
store i32 %14, i32* %2
br label %26
15: ; preds = %1
%16 = load i32, i32* %4
%17 = call i64 @IN_CLASSB(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @IN_CLASSB_NET
%21 = call i32 @htonl(i32 %20)
store i32 %21, i32* %2
br label %26
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = load i32, i32* @IN_CLASSC_NET
%25 = call i32 @htonl(i32 %24)
store i32 %25, i32* %2
br label %26
26: ; preds = %23, %19, %12
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@IN_CLASSA_NET = global i32 0
@IN_CLASSB_NET = global i32 0
@IN_CLASSC_NET = global i32 0
define i32 @net_mask(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 %9
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
br label %9
9: ; preds = %5, %1
%10 = phi i32* [ @IN_CLASSA_NET, %1 ], [ %8, %5 ]
%11 = load i32, i32* %10
%12 = tail call i32 @htonl(i32 %11)
ret i32 %12
}