#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 */
typedef int /*<<< orphan*/ mask_str;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, unsigned int,
                           unsigned int, unsigned int);
const char *get_mask_by_prefix_len(int len) {
  int i;
  static char mask_str[32] = {'\0'};
  unsigned int mask = 0;
  for (i = 0; i < len; i++) {
    mask |= (1 << (31 - i));
  }
  memset(mask_str, 0, sizeof(mask_str));
  sprintf(mask_str, "%u.%u.%u.%u", (mask & 0xFF000000) >> 24,
          (mask & 0x00FF0000) >> 16, (mask & 0x0000FF00) >> 8,
          (mask & 0x000000FF));
  return mask_str;
}


x86 assembly (clang, -O0):
<get_mask_by_prefix_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1168 <get_mask_by_prefix_len+0x48>
mov    $0x1f,%ecx
sub    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1139 <get_mask_by_prefix_len+0x19>
lea    0x2ed1(%rip),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%edx
and    $0xff000000,%edx
shr    $0x18,%edx
mov    -0xc(%rbp),%ecx
and    $0xff0000,%ecx
shr    $0x10,%ecx
mov    -0xc(%rbp),%r8d
and    $0xff00,%r8d
shr    $0x8,%r8d
mov    -0xc(%rbp),%r9d
and    $0xff,%r9d
lea    0x2e8c(%rip),%rdi
lea    0xe45(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2e79(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mask_by_prefix_len>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %edi,%edi
jle    13e0 <get_mask_by_prefix_len+0x2c0>
mov    $0x0,%ecx
cmp    $0x8,%edi
jb     13d0 <get_mask_by_prefix_len+0x2b0>
mov    %edi,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%edx
mov    %edx,%eax
shr    $0x3,%eax
add    $0x1,%eax
test   %edx,%edx
je     1427 <get_mask_by_prefix_len+0x307>
mov    %eax,%edx
and    $0xfffffffe,%edx
movdqa 0xe9f(%rip),%xmm6
xorps  %xmm0,%xmm0
movdqa 0xea3(%rip),%xmm8
movdqa 0xeaa(%rip),%xmm12
movdqa 0xeb1(%rip),%xmm9
movdqa 0xeb8(%rip),%xmm10
movdqa 0xebf(%rip),%xmm11
xorps  %xmm2,%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqa %xmm6,%xmm1
paddd  %xmm8,%xmm1
pshuflw $0xfe,%xmm6,%xmm3
movdqa %xmm12,%xmm5
psrld  %xmm3,%xmm5
pshuflw $0x54,%xmm6,%xmm3
movdqa %xmm12,%xmm4
psrld  %xmm3,%xmm4
punpcklqdq %xmm5,%xmm4
pshufd $0xee,%xmm6,%xmm3
pshuflw $0xfe,%xmm3,%xmm5
movdqa %xmm12,%xmm7
psrld  %xmm5,%xmm7
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm12,%xmm5
psrld  %xmm3,%xmm5
punpckhqdq %xmm7,%xmm5
shufps $0xcc,%xmm5,%xmm4
orps   %xmm0,%xmm4
pshuflw $0xfe,%xmm1,%xmm0
movdqa %xmm12,%xmm5
psrld  %xmm0,%xmm5
pshuflw $0x54,%xmm1,%xmm0
movdqa %xmm12,%xmm3
psrld  %xmm0,%xmm3
punpcklqdq %xmm5,%xmm3
pshufd $0xee,%xmm1,%xmm0
pshuflw $0xfe,%xmm0,%xmm1
movdqa %xmm12,%xmm5
psrld  %xmm1,%xmm5
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm12,%xmm1
psrld  %xmm0,%xmm1
punpckhqdq %xmm5,%xmm1
shufps $0xcc,%xmm1,%xmm3
orps   %xmm2,%xmm3
movdqa %xmm6,%xmm1
paddd  %xmm9,%xmm1
movdqa %xmm6,%xmm5
paddd  %xmm10,%xmm5
pshuflw $0xfe,%xmm1,%xmm0
movdqa %xmm12,%xmm2
psrld  %xmm0,%xmm2
pshuflw $0x54,%xmm1,%xmm7
movdqa %xmm12,%xmm0
psrld  %xmm7,%xmm0
punpcklqdq %xmm2,%xmm0
pshufd $0xee,%xmm1,%xmm1
pshuflw $0xfe,%xmm1,%xmm2
movdqa %xmm12,%xmm7
psrld  %xmm2,%xmm7
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm12,%xmm2
psrld  %xmm1,%xmm2
punpckhqdq %xmm7,%xmm2
shufps $0xcc,%xmm2,%xmm0
orps   %xmm4,%xmm0
pshuflw $0xfe,%xmm5,%xmm1
movdqa %xmm12,%xmm4
psrld  %xmm1,%xmm4
pshuflw $0x54,%xmm5,%xmm1
movdqa %xmm12,%xmm2
psrld  %xmm1,%xmm2
punpcklqdq %xmm4,%xmm2
pshufd $0xee,%xmm5,%xmm1
pshuflw $0xfe,%xmm1,%xmm4
movdqa %xmm12,%xmm5
psrld  %xmm4,%xmm5
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm12,%xmm4
psrld  %xmm1,%xmm4
punpckhqdq %xmm5,%xmm4
shufps $0xcc,%xmm4,%xmm2
orps   %xmm3,%xmm2
paddd  %xmm11,%xmm6
add    $0xfffffffe,%edx
jne    11a0 <get_mask_by_prefix_len+0x80>
test   $0x1,%al
je     13a5 <get_mask_by_prefix_len+0x285>
movdqa 0xd07(%rip),%xmm4
pshuflw $0xfe,%xmm6,%xmm1
movdqa 0xd0a(%rip),%xmm3
movdqa %xmm3,%xmm5
psrld  %xmm1,%xmm5
paddd  %xmm6,%xmm4
pshuflw $0x54,%xmm6,%xmm1
movdqa %xmm3,%xmm7
psrld  %xmm1,%xmm7
pshufd $0xee,%xmm6,%xmm1
pshuflw $0xfe,%xmm1,%xmm8
movdqa %xmm3,%xmm6
psrld  %xmm8,%xmm6
punpcklqdq %xmm5,%xmm7
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm3,%xmm5
psrld  %xmm1,%xmm5
punpckhqdq %xmm6,%xmm5
pshuflw $0xfe,%xmm4,%xmm1
movdqa %xmm3,%xmm6
psrld  %xmm1,%xmm6
shufps $0xcc,%xmm5,%xmm7
pshuflw $0x54,%xmm4,%xmm1
movdqa %xmm3,%xmm5
psrld  %xmm1,%xmm5
pshufd $0xee,%xmm4,%xmm1
pshuflw $0xfe,%xmm1,%xmm8
movdqa %xmm3,%xmm4
psrld  %xmm8,%xmm4
orps   %xmm7,%xmm0
pshuflw $0x54,%xmm1,%xmm1
psrld  %xmm1,%xmm3
punpcklqdq %xmm6,%xmm5
punpckhqdq %xmm4,%xmm3
shufps $0xcc,%xmm3,%xmm5
orps   %xmm5,%xmm2
orps   %xmm2,%xmm0
pshufd $0xee,%xmm0,%xmm1
por    %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
por    %xmm1,%xmm0
movd   %xmm0,%ebx
cmp    %edi,%ecx
je     13e0 <get_mask_by_prefix_len+0x2c0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x80000000,%eax
shr    %cl,%eax
or     %eax,%ebx
add    $0x1,%ecx
cmp    %ecx,%edi
jne    13d0 <get_mask_by_prefix_len+0x2b0>
lea    0x2c59(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    %ebx,%edx
shr    $0x18,%edx
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%ecx
movzbl %bh,%eax
movzbl %bl,%r9d
lea    0xc4f(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%r8d
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movdqa 0xbd1(%rip),%xmm6
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
test   $0x1,%al
jne    1301 <get_mask_by_prefix_len+0x1e1>
jmp    13a5 <get_mask_by_prefix_len+0x285>

LLVM IR (-O0):
@get_mask_by_prefix_len.mask_str = internal global [32 x i8] zeroinitializer
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i8* @get_mask_by_prefix_len(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %15, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = load i32, i32* %3
%11 = sub nsw i32 31, %10
%12 = shl i32 1, %11
%13 = load i32, i32* %4
%14 = or i32 %13, %12
store i32 %14, i32* %4
br label %15
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %5
18: ; preds = %5
%19 = call i32 @memset(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_mask_by_prefix_len.mask_str, i64 0, i64 0), i32 0, i32 32)
%20 = load i32, i32* %4
%21 = and i32 %20, -16777216
%22 = lshr i32 %21, 24
%23 = load i32, i32* %4
%24 = and i32 %23, 16711680
%25 = lshr i32 %24, 16
%26 = load i32, i32* %4
%27 = and i32 %26, 65280
%28 = lshr i32 %27, 8
%29 = load i32, i32* %4
%30 = and i32 %29, 255
%31 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_mask_by_prefix_len.mask_str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %25, i32 %28, i32 %30)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_mask_by_prefix_len.mask_str, i64 0, i64 0)
}

LLVM IR (-O2):
@get_mask_by_prefix_len.mask_str = internal global [32 x i8] zeroinitializer
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i8* @get_mask_by_prefix_len(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %62
3: ; preds = %1
%4 = icmp ult i32 %0, 8
br i1 %4, label %52, label %5
5: ; preds = %3
%6 = and i32 %0, -8
%7 = add i32 %6, -8
%8 = lshr exact i32 %7, 3
%9 = add nuw nsw i32 %8, 1
%10 = and i32 %9, 1
%11 = icmp eq i32 %7, 0
br i1 %11, label %33, label %12
12: ; preds = %5
%13 = and i32 %9, 1073741822
br label %14
14: ; preds = %14, %12
%15 = phi <4 x i32> [ zeroinitializer, %12 ], [ %28, %14 ]
%16 = phi <4 x i32> [ zeroinitializer, %12 ], [ %29, %14 ]
%17 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %12 ], [ %30, %14 ]
%18 = phi i32 [ 0, %12 ], [ %31, %14 ]
%19 = add <4 x i32> %17, <i32 4, i32 4, i32 4, i32 4>
%20 = lshr <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %17
%21 = lshr <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %19
%22 = or <4 x i32> %15, %20
%23 = or <4 x i32> %16, %21
%24 = add <4 x i32> %17, <i32 8, i32 8, i32 8, i32 8>
%25 = add <4 x i32> %17, <i32 12, i32 12, i32 12, i32 12>
%26 = lshr <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %24
%27 = lshr <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %25
%28 = or <4 x i32> %22, %26
%29 = or <4 x i32> %23, %27
%30 = add <4 x i32> %17, <i32 16, i32 16, i32 16, i32 16>
%31 = add i32 %18, 2
%32 = icmp eq i32 %31, %13
br i1 %32, label %33, label %14
33: ; preds = %14, %5
%34 = phi <4 x i32> [ undef, %5 ], [ %28, %14 ]
%35 = phi <4 x i32> [ undef, %5 ], [ %29, %14 ]
%36 = phi <4 x i32> [ zeroinitializer, %5 ], [ %28, %14 ]
%37 = phi <4 x i32> [ zeroinitializer, %5 ], [ %29, %14 ]
%38 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %5 ], [ %30, %14 ]
%39 = icmp eq i32 %10, 0
br i1 %39, label %46, label %40
40: ; preds = %33
%41 = add <4 x i32> %38, <i32 4, i32 4, i32 4, i32 4>
%42 = lshr <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %38
%43 = lshr <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %41
%44 = or <4 x i32> %36, %42
%45 = or <4 x i32> %37, %43
br label %46
46: ; preds = %33, %40
%47 = phi <4 x i32> [ %34, %33 ], [ %44, %40 ]
%48 = phi <4 x i32> [ %35, %33 ], [ %45, %40 ]
%49 = or <4 x i32> %48, %47
%50 = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %49)
%51 = icmp eq i32 %6, %0
br i1 %51, label %62, label %52
52: ; preds = %3, %46
%53 = phi i32 [ 0, %3 ], [ %50, %46 ]
%54 = phi i32 [ 0, %3 ], [ %6, %46 ]
br label %55
55: ; preds = %52, %55
%56 = phi i32 [ %59, %55 ], [ %53, %52 ]
%57 = phi i32 [ %60, %55 ], [ %54, %52 ]
%58 = lshr i32 -2147483648, %57
%59 = or i32 %56, %58
%60 = add nuw nsw i32 %57, 1
%61 = icmp eq i32 %60, %0
br i1 %61, label %62, label %55
62: ; preds = %55, %46, %1
%63 = phi i32 [ 0, %1 ], [ %50, %46 ], [ %59, %55 ]
%64 = tail call i32 @memset(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_mask_by_prefix_len.mask_str, i64 0, i64 0), i32 0, i32 32)
%65 = lshr i32 %63, 24
%66 = lshr i32 %63, 16
%67 = and i32 %66, 255
%68 = lshr i32 %63, 8
%69 = and i32 %68, 255
%70 = and i32 %63, 255
%71 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @get_mask_by_prefix_len.mask_str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %65, i32 %67, i32 %69, i32 %70)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @get_mask_by_prefix_len.mask_str, i64 0, i64 0)
}