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

/* Variables and functions */
int htonl(int);
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
unsigned long cidr_get_mask(unsigned int maskbits) {
  struct in_addr mask;
  if (maskbits == 0)
    return 0;
  inet_aton("255.255.255.255", &mask);
  mask.s_addr = htonl(mask.s_addr << (32 - maskbits));
  return mask.s_addr;
}


x86 assembly (clang, -O0):
<cidr_get_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1142 <cidr_get_mask+0x22>
movq   $0x0,-0x8(%rbp)
jmp    116f <cidr_get_mask+0x4f>
lea    0xeb7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <inet_aton@plt>
mov    -0x10(%rbp),%edi
mov    $0x20,%ecx
sub    -0xc(%rbp),%ecx
shl    %cl,%edi
call   1030 <htonl@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cidr_get_mask>:
test   %edi,%edi
je     1153 <cidr_get_mask+0x33>
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xece(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <inet_aton@plt>
mov    0x8(%rsp),%edi
neg    %bl
mov    %ebx,%ecx
shl    %cl,%edi
call   1030 <htonl@plt>
cltq
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [16 x i8] c"255.255.255.255\00"
define i64 @cidr_get_mask(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca %struct.in_addr
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i64 0, i64* %2
br label %20
8: ; preds = %1
%9 = call i32 @inet_aton(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %4)
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* %3
%13 = sub i32 32, %12
%14 = shl i32 %11, %13
%15 = call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%18 = load i32, i32* %17
%19 = sext i32 %18 to i64
store i64 %19, i64* %2
br label %20
20: ; preds = %8, %7
%21 = load i64, i64* %2
ret i64 %21
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [16 x i8] c"255.255.255.255\00"
define i64 @cidr_get_mask(i32 %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = icmp eq i32 %0, 0
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = call i32 @inet_aton(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.in_addr* %2)
%7 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = sub i32 32, %0
%10 = shl i32 %8, %9
%11 = call i32 @htonl(i32 %10)
%12 = sext i32 %11 to i64
br label %13
13: ; preds = %1, %5
%14 = phi i64 [ %12, %5 ], [ 0, %1 ]
ret i64 %14
}