#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 uint32_t;

/* Variables and functions */
int ntohl(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, ...);
char *mask_to_dotted(uint32_t mask) {
  int i;
  static char buf[20];
  uint32_t maskaddr, bits;
  maskaddr = ntohl(mask);
  if (mask == 0xFFFFFFFFL) {
    *buf = '\0';
    return buf;
  }
  i = 32;
  bits = 0xFFFFFFFEL;
  while (--i >= 0 && maskaddr != bits)
    bits <<= 1;
  if (i > 0)
    sprintf(buf, "/%d", i);
  else if (!i)
    *buf = '\0';
  else
    sprintf(buf, "/%d.%d.%d.%d", ((unsigned char *)&mask)[0],
            ((unsigned char *)&mask)[1], ((unsigned char *)&mask)[2],
            ((unsigned char *)&mask)[3]);
  return buf;
}


x86 assembly (clang, -O0):
<mask_to_dotted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <ntohl@plt>
mov    %eax,-0x14(%rbp)
movslq -0xc(%rbp),%rax
mov    $0xffffffff,%ecx
cmp    %rcx,%rax
jne    115f <mask_to_dotted+0x3f>
movb   $0x0,0x2ef1(%rip)
lea    0x2eea(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1227 <mask_to_dotted+0x107>
movl   $0x20,-0x10(%rbp)
movl   $0xfffffffe,-0x18(%rbp)
mov    -0x10(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jl     1190 <mask_to_dotted+0x70>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a0 <mask_to_dotted+0x80>
jmp    11ae <mask_to_dotted+0x8e>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <mask_to_dotted+0x4d>
cmpl   $0x0,-0x10(%rbp)
jle    11d8 <mask_to_dotted+0xb8>
mov    -0x10(%rbp),%eax
lea    0x2e7e(%rip),%rdi
lea    0xe37(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    121c <mask_to_dotted+0xfc>
cmpl   $0x0,-0x10(%rbp)
jne    11ee <mask_to_dotted+0xce>
movb   $0x0,0x2e57(%rip)
jmp    1217 <mask_to_dotted+0xf7>
mov    -0xc(%rbp),%al
movzbl -0xb(%rbp),%ecx
movzbl -0xa(%rbp),%r8d
movzbl -0x9(%rbp),%r9d
lea    0x2e3a(%rip),%rdi
lea    0xdf7(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    121c <mask_to_dotted+0xfc>
lea    0x2e1d(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mask_to_dotted>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    %edi,%eax
shr    $0x10,%eax
mov    %edi,%ecx
and    $0xff000000,%ecx
movzbl %al,%r14d
mov    %r14d,%eax
shl    $0x10,%eax
or     %ecx,%eax
movzbl %bh,%ebp
mov    %ebp,%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movzbl %bl,%edi
or     %ecx,%edi
call   1040 <ntohl@plt>
mov    $0xfffffffe,%edx
mov    $0x20,%ecx
nopl   (%rax)
add    $0xffffffff,%ecx
jae    116e <mask_to_dotted+0x4e>
lea    (%rdx,%rdx,1),%esi
cmp    %edx,%eax
mov    %esi,%edx
jne    1160 <mask_to_dotted+0x40>
lea    0x1(%rcx),%eax
cmp    $0x2,%eax
jb     1190 <mask_to_dotted+0x70>
movzbl %cl,%edx
lea    0x2ec0(%rip),%rdi
lea    0xe79(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11c2 <mask_to_dotted+0xa2>
test   %ecx,%ecx
je     11bb <mask_to_dotted+0x9b>
mov    %ebx,%eax
shr    $0x18,%eax
movzbl %bl,%edx
lea    0x2e9d(%rip),%rdi
lea    0xe5a(%rip),%rsi
mov    %eax,%r9d
mov    %ebp,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11c2 <mask_to_dotted+0xa2>
movb   $0x0,0x2e7e(%rip)
lea    0x2e77(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@mask_to_dotted.buf = internal global [20 x i8] zeroinitializer
@.str = [4 x i8] c"/%d\00"
@.str.1 = [13 x i8] c"/%d.%d.%d.%d\00"
define i8* @mask_to_dotted(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @ntohl(i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = icmp eq i64 %10, 4294967295
br i1 %11, label %12, label %13
12: ; preds = %1
store i8 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0)
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0), i8** %2
br label %57
13: ; preds = %1
store i32 32, i32* %4
store i32 -2, i32* %6
br label %14
14: ; preds = %24, %13
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = icmp ne i32 %19, %20
br label %22
22: ; preds = %18, %14
%23 = phi i1 [ false, %14 ], [ %21, %18 ]
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = load i32, i32* %6
%26 = shl i32 %25, 1
store i32 %26, i32* %6
br label %14
27: ; preds = %22
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %4
%32 = trunc i32 %31 to i8
%33 = call i32 (i8*, i8*, i8, ...) @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %32)
br label %56
34: ; preds = %27
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %34
store i8 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0)
br label %55
38: ; preds = %34
%39 = bitcast i32* %3 to i8*
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = bitcast i32* %3 to i8*
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = bitcast i32* %3 to i8*
%47 = getelementptr inbounds i8, i8* %46, i64 2
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = bitcast i32* %3 to i8*
%51 = getelementptr inbounds i8, i8* %50, i64 3
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = call i32 (i8*, i8*, i8, ...) @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %41, i32 %45, i32 %49, i32 %53)
br label %55
55: ; preds = %38, %37
br label %56
56: ; preds = %55, %30
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0), i8** %2
br label %57
57: ; preds = %56, %12
%58 = load i8*, i8** %2
ret i8* %58
}

LLVM IR (-O2):
@mask_to_dotted.buf = internal global [20 x i8] zeroinitializer
@.str = [4 x i8] c"/%d\00"
@.str.1 = [13 x i8] c"/%d.%d.%d.%d\00"
define i8* @mask_to_dotted(i32 %0) {
%2 = lshr i32 %0, 8
%3 = lshr i32 %0, 16
%4 = and i32 %0, -16777216
%5 = and i32 %3, 255
%6 = shl nuw nsw i32 %5, 16
%7 = or i32 %6, %4
%8 = and i32 %2, 255
%9 = shl nuw nsw i32 %8, 8
%10 = or i32 %7, %9
%11 = and i32 %0, 255
%12 = or i32 %10, %11
%13 = tail call i32 @ntohl(i32 %12)
br label %14
14: ; preds = %14, %1
%15 = phi i32 [ 32, %1 ], [ %17, %14 ]
%16 = phi i32 [ -2, %1 ], [ %21, %14 ]
%17 = add nsw i32 %15, -1
%18 = icmp ne i32 %15, 0
%19 = icmp ne i32 %13, %16
%20 = select i1 %18, i1 %19, i1 false
%21 = shl i32 %16, 1
br i1 %20, label %14, label %22
22: ; preds = %14
%23 = trunc i32 %0 to i8
%24 = lshr i32 %0, 24
%25 = icmp ugt i32 %15, 1
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = trunc i32 %17 to i8
%28 = tail call i32 (i8*, i8*, i8, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 zeroext %27)
br label %34
29: ; preds = %22
%30 = icmp eq i32 %17, 0
br i1 %30, label %31, label %32
31: ; preds = %29
store i8 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0)
br label %34
32: ; preds = %29
%33 = tail call i32 (i8*, i8*, i8, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %23, i32 %8, i32 %5, i32 %24)
br label %34
34: ; preds = %26, %32, %31
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @mask_to_dotted.buf, i64 0, i64 0)
}