char *ipv4_prefix_to_hosts(char *hosts, unsigned hosts_size, unsigned prefix) {
  unsigned tmp;
  if (prefix >= 31) {
    snprintf(hosts, hosts_size, "%s", p2_table(32 - prefix));
  } else {
    tmp = (1 << (32 - prefix)) - 2;
    snprintf(hosts, hosts_size, "%u", tmp);
  }
  return hosts;
}


x86 assembly (clang, -O0):
<ipv4_prefix_to_hosts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x1f,-0x10(%rbp)
jb     1177 <ipv4_prefix_to_hosts+0x57>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x20(%rbp)
mov    $0x20,%edi
sub    -0x10(%rbp),%edi
mov    $0x0,%al
call   1040 <p2_table@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%ecx
lea    0xe95(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11a6 <ipv4_prefix_to_hosts+0x86>
mov    $0x20,%ecx
sub    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    %eax,%esi
mov    -0x14(%rbp),%ecx
lea    0xe64(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_prefix_to_hosts>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0x1f,%edx
jb     114c <ipv4_prefix_to_hosts+0x2c>
mov    %esi,%r14d
mov    $0x20,%edi
sub    %edx,%edi
xor    %eax,%eax
call   1040 <p2_table@plt>
lea    0xebc(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
jmp    1166 <ipv4_prefix_to_hosts+0x46>
neg    %dl
mov    $0x1,%eax
mov    %edx,%ecx
shl    %cl,%eax
add    $0xfffffffe,%eax
mov    %esi,%esi
lea    0xea0(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%u\00"
define i8* @ipv4_prefix_to_hosts(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp uge i32 %8, 31
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = zext i32 %12 to i64
%14 = load i32, i32* %6
%15 = sub i32 32, %14
%16 = call i32 (i32, ...) bitcast (i32 (...)* @p2_table to i32 (i32, ...)*)(i32 %15)
%17 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %11, i64 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %28
18: ; preds = %3
%19 = load i32, i32* %6
%20 = sub i32 32, %19
%21 = shl i32 1, %20
%22 = sub nsw i32 %21, 2
store i32 %22, i32* %7
%23 = load i8*, i8** %4
%24 = load i32, i32* %5
%25 = zext i32 %24 to i64
%26 = load i32, i32* %7
%27 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %23, i64 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %18, %10
%29 = load i8*, i8** %4
ret i8* %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%u\00"
define i8* @ipv4_prefix_to_hosts(i8* returned writeonly %0, i32 %1, i32 %2) {
%4 = icmp ugt i32 %2, 30
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = zext i32 %1 to i64
%7 = sub i32 32, %2
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @p2_table to i32 (i32, ...)*)(i32 %7)
%9 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %16
10: ; preds = %3
%11 = sub nuw nsw i32 32, %2
%12 = shl nuw i32 1, %11
%13 = add nsw i32 %12, -2
%14 = zext i32 %1 to i64
%15 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %16
16: ; preds = %10, %5
ret i8* %0
}