#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 */
int ntohl(int /*<<< orphan*/);
unsigned default_ipv4_prefix(struct in_addr net) {
  unsigned byte1 = (ntohl(net.s_addr) >> 24) & 0xff;
  if (byte1 < 128) {
    return 8;
  }
  if (byte1 >= 128 && byte1 < 192) {
    return 16;
  }
  if (byte1 >= 192 && byte1 < 224) {
    return 24;
  }
  return 24;
}


x86 assembly (clang, -O0):
<default_ipv4_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <ntohl@plt>
sar    $0x18,%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x80,-0xc(%rbp)
jae    1147 <default_ipv4_prefix+0x37>
movl   $0x8,-0x4(%rbp)
jmp    119a <default_ipv4_prefix+0x8a>
cmpl   $0x80,-0xc(%rbp)
jb     116d <default_ipv4_prefix+0x5d>
cmpl   $0xc0,-0xc(%rbp)
jae    116d <default_ipv4_prefix+0x5d>
movl   $0x10,-0x4(%rbp)
jmp    119a <default_ipv4_prefix+0x8a>
cmpl   $0xc0,-0xc(%rbp)
jb     1193 <default_ipv4_prefix+0x83>
cmpl   $0xe0,-0xc(%rbp)
jae    1193 <default_ipv4_prefix+0x83>
movl   $0x18,-0x4(%rbp)
jmp    119a <default_ipv4_prefix+0x8a>
movl   $0x18,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<default_ipv4_prefix>:
push   %rax
call   1030 <ntohl@plt>
xor    %ecx,%ecx
cmp    $0xc0000000,%eax
setae  %cl
test   %eax,%eax
lea    0x10(,%rcx,8),%ecx
mov    $0x8,%eax
cmovs  %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
define i32 @default_ipv4_prefix(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)
%9 = ashr i32 %8, 24
%10 = and i32 %9, 255
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp ult i32 %11, 128
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 8, i32* %2
br label %29
14: ; preds = %1
%15 = load i32, i32* %4
%16 = icmp uge i32 %15, 128
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp ult i32 %18, 192
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 16, i32* %2
br label %29
21: ; preds = %17, %14
%22 = load i32, i32* %4
%23 = icmp uge i32 %22, 192
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp ult i32 %25, 224
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 24, i32* %2
br label %29
28: ; preds = %24, %21
store i32 24, i32* %2
br label %29
29: ; preds = %28, %27, %20, %13
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @default_ipv4_prefix(i32 %0) {
%2 = tail call i32 @ntohl(i32 %0)
%3 = icmp sgt i32 %2, -1
%4 = icmp ult i32 %2, -1073741824
%5 = select i1 %4, i32 16, i32 24
%6 = select i1 %3, i32 8, i32 %5
ret i32 %6
}