#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 */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, unsigned int,
                           unsigned int, unsigned int);
int /*<<< orphan*/ uInCIDR4Format(char const *, unsigned int *, unsigned int *);
unsigned ExpandCIDR4(const char *cCIDR4, char *cIPs[]) {
  unsigned a = 0, b = 0, c = 0, d = 0;
  unsigned uCIDR4IP = 0;
  unsigned uCIDR4Mask = 0;
  unsigned uTmp = 0;
  register unsigned i;
  if (!uInCIDR4Format(cCIDR4, &uCIDR4IP, &uCIDR4Mask))
    return (0);
  for (i = 0; i < (~uCIDR4Mask) + 1; i++) {
    uTmp = uCIDR4IP & 0xff000000;
    a = uTmp >> 24;
    uTmp = uCIDR4IP & 0x00ff0000;
    b = uTmp >> 16;
    uTmp = uCIDR4IP & 0x0000ff00;
    c = uTmp >> 8;
    d = uCIDR4IP & 0x000000ff;
    cIPs[i] = malloc(16);
    sprintf(cIPs[i], "%u.%u.%u.%u", a, b, c, d);
    uCIDR4IP++;
  }
  return (i);
}


x86 assembly (clang, -O0):
<ExpandCIDR4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <uInCIDR4Format@plt>
cmp    $0x0,%eax
jne    1197 <ExpandCIDR4+0x67>
movl   $0x0,-0x4(%rbp)
jmp    1253 <ExpandCIDR4+0x123>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x30(%rbp),%ecx
xor    $0xffffffff,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jae    124d <ExpandCIDR4+0x11d>
mov    -0x2c(%rbp),%eax
and    $0xff000000,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
shr    $0x18,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff0000,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
shr    $0x10,%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff00,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
shr    $0x8,%eax
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x28(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
lea    0xdcf(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    119e <ExpandCIDR4+0x6e>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExpandCIDR4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
call   1030 <uInCIDR4Format@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     11ca <ExpandCIDR4+0x9a>
cmpl   $0x0,0x4(%rsp)
je     11ca <ExpandCIDR4+0x9a>
mov    (%rsp),%eax
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %eax,%r13d
shr    $0x18,%r13d
mov    %eax,%ecx
shr    $0x10,%ecx
movzbl %cl,%r12d
movzbl %ah,%ecx
mov    %ecx,%r15d
movzbl %al,%ebp
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
mov    %rax,%rdi
lea    0xe5f(%rip),%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %ebp,%r9d
call   1050 <sprintf@plt>
mov    (%rsp),%eax
add    $0x1,%eax
mov    %eax,(%rsp)
add    $0x1,%rbx
xor    %ecx,%ecx
sub    0x4(%rsp),%ecx
cmp    %rcx,%rbx
jb     1170 <ExpandCIDR4+0x40>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @ExpandCIDR4(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%14 = load i8*, i8** %4
%15 = call i32 @uInCIDR4Format(i8* %14, i32* %10, i32* %11)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %2
store i32 0, i32* %3
br label %62
18: ; preds = %2
store i32 0, i32* %13
br label %19
19: ; preds = %57, %18
%20 = load i32, i32* %13
%21 = load i32, i32* %11
%22 = xor i32 %21, -1
%23 = add i32 %22, 1
%24 = icmp ult i32 %20, %23
br i1 %24, label %25, label %60
25: ; preds = %19
%26 = load i32, i32* %10
%27 = and i32 %26, -16777216
store i32 %27, i32* %12
%28 = load i32, i32* %12
%29 = lshr i32 %28, 24
store i32 %29, i32* %6
%30 = load i32, i32* %10
%31 = and i32 %30, 16711680
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = lshr i32 %32, 16
store i32 %33, i32* %7
%34 = load i32, i32* %10
%35 = and i32 %34, 65280
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = lshr i32 %36, 8
store i32 %37, i32* %8
%38 = load i32, i32* %10
%39 = and i32 %38, 255
store i32 %39, i32* %9
%40 = call i8* @malloc(i32 16)
%41 = load i8**, i8*** %5
%42 = load i32, i32* %13
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
store i8* %40, i8** %44
%45 = load i8**, i8*** %5
%46 = load i32, i32* %13
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = load i32, i32* %8
%53 = load i32, i32* %9
%54 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %50, i32 %51, i32 %52, i32 %53)
%55 = load i32, i32* %10
%56 = add i32 %55, 1
store i32 %56, i32* %10
br label %57
57: ; preds = %25
%58 = load i32, i32* %13
%59 = add i32 %58, 1
store i32 %59, i32* %13
br label %19
60: ; preds = %19
%61 = load i32, i32* %13
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %17
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @ExpandCIDR4(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = call i32 @uInCIDR4Format(i8* %0, i32* %3, i32* %4)
%8 = icmp eq i32 %7, 0
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 0
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %35, label %12
12: ; preds = %2
%13 = load i32, i32* %3
br label %14
14: ; preds = %12, %14
%15 = phi i32 [ %13, %12 ], [ %27, %14 ]
%16 = phi i64 [ 0, %12 ], [ %28, %14 ]
%17 = lshr i32 %15, 24
%18 = lshr i32 %15, 16
%19 = and i32 %18, 255
%20 = lshr i32 %15, 8
%21 = and i32 %20, 255
%22 = and i32 %15, 255
%23 = call dereferenceable_or_null(16) i8* @malloc(i32 16)
%24 = getelementptr inbounds i8*, i8** %1, i64 %16
store i8* %23, i8** %24
%25 = call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19, i32 %21, i32 %22)
%26 = load i32, i32* %3
%27 = add i32 %26, 1
store i32 %27, i32* %3
%28 = add nuw nsw i64 %16, 1
%29 = load i32, i32* %4
%30 = sub i32 0, %29
%31 = zext i32 %30 to i64
%32 = icmp ult i64 %28, %31
br i1 %32, label %14, label %33
33: ; preds = %14
%34 = trunc i64 %28 to i32
br label %35
35: ; preds = %33, %2
%36 = phi i32 [ 0, %2 ], [ %34, %33 ]
ret i32 %36
}