#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*/);
const char *ipv4_net_to_class(struct in_addr net) {
  unsigned byte1 = (ntohl(net.s_addr) >> 24) & 0xff;
  if (byte1 < 128) {
    return "Class A";
  }
  if (byte1 >= 128 && byte1 < 192) {
    return "Class B";
  }
  if (byte1 >= 192 && byte1 < 224) {
    return "Class C";
  }
  if (byte1 >= 224 && byte1 < 239) {
    return "Class D";
  }
  return "Class E";
}


x86 assembly (clang, -O0):
<ipv4_net_to_class>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <ntohl@plt>
sar    $0x18,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jae    114b <ipv4_net_to_class+0x3b>
lea    0xebe(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <ipv4_net_to_class+0xc4>
cmpl   $0x80,-0x14(%rbp)
jb     1175 <ipv4_net_to_class+0x65>
cmpl   $0xc0,-0x14(%rbp)
jae    1175 <ipv4_net_to_class+0x65>
lea    0xe9c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <ipv4_net_to_class+0xc4>
cmpl   $0xc0,-0x14(%rbp)
jb     119f <ipv4_net_to_class+0x8f>
cmpl   $0xe0,-0x14(%rbp)
jae    119f <ipv4_net_to_class+0x8f>
lea    0xe7a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <ipv4_net_to_class+0xc4>
cmpl   $0xe0,-0x14(%rbp)
jb     11c9 <ipv4_net_to_class+0xb9>
cmpl   $0xef,-0x14(%rbp)
jae    11c9 <ipv4_net_to_class+0xb9>
lea    0xe58(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d4 <ipv4_net_to_class+0xc4>
lea    0xe50(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_net_to_class>:
push   %rax
call   1030 <ntohl@plt>
test   %eax,%eax
js     1123 <ipv4_net_to_class+0x13>
lea    0xedf(%rip),%rax
pop    %rcx
ret
cmp    $0xc0000000,%eax
jae    1133 <ipv4_net_to_class+0x23>
lea    0xed7(%rip),%rax
pop    %rcx
ret
cmp    $0xe0000000,%eax
jae    1143 <ipv4_net_to_class+0x33>
lea    0xecf(%rip),%rax
pop    %rcx
ret
cmp    $0xef000000,%eax
lea    0xec9(%rip),%rcx
lea    0xeca(%rip),%rax
cmovb  %rcx,%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [8 x i8] c"Class A\00"
@.str.1 = [8 x i8] c"Class B\00"
@.str.2 = [8 x i8] c"Class C\00"
@.str.3 = [8 x i8] c"Class D\00"
@.str.4 = [8 x i8] c"Class E\00"
define i8* @ipv4_net_to_class(i32 %0) {
%2 = alloca i8*
%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 i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
br label %36
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 i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %36
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 i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %36
28: ; preds = %24, %21
%29 = load i32, i32* %4
%30 = icmp uge i32 %29, 224
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %4
%33 = icmp ult i32 %32, 239
br i1 %33, label %34, label %35
34: ; preds = %31
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %36
35: ; preds = %31, %28
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %36
36: ; preds = %35, %34, %27, %20, %13
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@.str = [8 x i8] c"Class A\00"
@.str.1 = [8 x i8] c"Class B\00"
@.str.2 = [8 x i8] c"Class C\00"
@.str.3 = [8 x i8] c"Class D\00"
@.str.4 = [8 x i8] c"Class E\00"
define i8* @ipv4_net_to_class(i32 %0) {
%2 = tail call i32 @ntohl(i32 %0)
%3 = icmp sgt i32 %2, -1
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = icmp ult i32 %2, -1073741824
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = icmp ult i32 %2, -536870912
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = icmp ult i32 %2, -285212672
%10 = select i1 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0)
br label %11
11: ; preds = %8, %6, %4, %1
%12 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %6 ], [ %10, %8 ]
ret i8* %12
}