#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 */

/* Variables and functions */
scalar_t__ pow(int, int);
short int ipv4_get_num_hosts(unsigned short int pfxlen, unsigned int *num) {
  int hosts = 0;
  switch (pfxlen) {
  case 0:
    hosts = 0xFFFFFFFC;
    break;
  case 31:
    hosts = 2;
    break;
  case 32:
    hosts = 1;
    break;
  default:
    hosts = (unsigned int)pow(2, 32 - pfxlen) - 2;
    break;
  }
  *num = hosts;
  return 0;
}


x86 assembly (clang, -O0):
<ipv4_get_num_hosts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movzwl -0x2(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     1160 <ipv4_get_num_hosts+0x50>
jmp    113e <ipv4_get_num_hosts+0x2e>
mov    -0x18(%rbp),%eax
sub    $0x1f,%eax
je     116c <ipv4_get_num_hosts+0x5c>
jmp    114f <ipv4_get_num_hosts+0x3f>
mov    -0x18(%rbp),%eax
sub    $0x20,%eax
je     1178 <ipv4_get_num_hosts+0x68>
jmp    1184 <ipv4_get_num_hosts+0x74>
movl   $0xfffffffc,-0x14(%rbp)
jmp    119f <ipv4_get_num_hosts+0x8f>
movl   $0x2,-0x14(%rbp)
jmp    119f <ipv4_get_num_hosts+0x8f>
movl   $0x1,-0x14(%rbp)
jmp    119f <ipv4_get_num_hosts+0x8f>
movzwl -0x2(%rbp),%eax
mov    $0x20,%esi
sub    %eax,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
cwtl
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_get_num_hosts>:
push   %rbx
mov    %rsi,%rbx
test   %edi,%edi
je     112b <ipv4_get_num_hosts+0x1b>
cmp    $0x20,%di
je     1132 <ipv4_get_num_hosts+0x22>
cmp    $0x1f,%di
jne    1139 <ipv4_get_num_hosts+0x29>
mov    $0x2,%eax
jmp    1150 <ipv4_get_num_hosts+0x40>
mov    $0xfffffffc,%eax
jmp    1150 <ipv4_get_num_hosts+0x40>
mov    $0x1,%eax
jmp    1150 <ipv4_get_num_hosts+0x40>
movzwl %di,%eax
mov    $0x20,%esi
sub    %eax,%esi
mov    $0x2,%edi
call   1030 <pow@plt>
add    $0xfffffffe,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define signext i16 @ipv4_get_num_hosts(i16 zeroext %0, i32* %1) {
%3 = alloca i16
%4 = alloca i32*
%5 = alloca i32
store i16 %0, i16* %3
store i32* %1, i32** %4
store i32 0, i32* %5
%6 = load i16, i16* %3
%7 = zext i16 %6 to i32
switch i32 %7, label %11 [
i32 0, label %8
i32 31, label %9
i32 32, label %10
]
8: ; preds = %2
store i32 -4, i32* %5
br label %18
9: ; preds = %2
store i32 2, i32* %5
br label %18
10: ; preds = %2
store i32 1, i32* %5
br label %18
11: ; preds = %2
%12 = load i16, i16* %3
%13 = zext i16 %12 to i32
%14 = sub nsw i32 32, %13
%15 = call i64 @pow(i32 2, i32 %14)
%16 = trunc i64 %15 to i32
%17 = sub i32 %16, 2
store i32 %17, i32* %5
br label %18
18: ; preds = %11, %10, %9, %8
%19 = load i32, i32* %5
%20 = load i32*, i32** %4
store i32 %19, i32* %20
ret i16 0
}

LLVM IR (-O2):
define signext i16 @ipv4_get_num_hosts(i16 zeroext %0, i32* nocapture writeonly %1) {
switch i16 %0, label %5 [
i16 0, label %11
i16 31, label %3
i16 32, label %4
]
3: ; preds = %2
br label %11
4: ; preds = %2
br label %11
5: ; preds = %2
%6 = zext i16 %0 to i32
%7 = sub nsw i32 32, %6
%8 = tail call i64 @pow(i32 2, i32 %7)
%9 = trunc i64 %8 to i32
%10 = add i32 %9, -2
br label %11
11: ; preds = %2, %5, %4, %3
%12 = phi i32 [ %10, %5 ], [ 1, %4 ], [ 2, %3 ], [ -4, %2 ]
store i32 %12, i32* %1
ret i16 0
}