#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 */
unsigned int createBitmask(char *);
unsigned int ip2ui(char *);
char *strtok(char *, char *);
int cidrToIpRange(char *cidr, unsigned int *startIp, unsigned int *endIp) {
  char *ip = strtok(cidr, "/");
  if (!ip)
    return 0;
  char *bitmask = strtok(NULL, "\0");
  if (!bitmask)
    return 0;
  unsigned int ipAsUInt = ip2ui(ip);
  unsigned int bitmaskAsUInt = createBitmask(bitmask);
  *startIp = (ipAsUInt & bitmaskAsUInt) + 1;
  *endIp = (ipAsUInt | ~bitmaskAsUInt) - 1;
  return 1;
}


x86 assembly (clang, -O0):
<cidrToIpRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116f <cidrToIpRange+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11dc <cidrToIpRange+0xac>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe88(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119a <cidrToIpRange+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    11dc <cidrToIpRange+0xac>
mov    -0x28(%rbp),%rdi
call   1030 <ip2ui@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <createBitmask@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%ecx
and    -0x38(%rbp),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%eax
xor    $0xffffffff,%eax
or     %eax,%ecx
sub    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cidrToIpRange>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xeba(%rip),%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1198 <cidrToIpRange+0x68>
mov    %rax,%r12
lea    0xea8(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <strtok@plt>
test   %rax,%rax
je     119a <cidrToIpRange+0x6a>
mov    %rax,%r13
mov    %r12,%rdi
call   1030 <ip2ui@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1040 <createBitmask@plt>
mov    %eax,%ecx
and    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,(%r15)
not    %eax
or     %ebx,%eax
add    $0xffffffff,%eax
mov    %eax,(%r14)
mov    $0x1,%ebx
jmp    119a <cidrToIpRange+0x6a>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] zeroinitializer
define i32 @cidrToIpRange(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%12 = load i8*, i8** %5
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %3
store i32 0, i32* %4
br label %38
17: ; preds = %3
%18 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %17
store i32 0, i32* %4
br label %38
22: ; preds = %17
%23 = load i8*, i8** %8
%24 = call i32 @ip2ui(i8* %23)
store i32 %24, i32* %10
%25 = load i8*, i8** %9
%26 = call i32 @createBitmask(i8* %25)
store i32 %26, i32* %11
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = and i32 %27, %28
%30 = add i32 %29, 1
%31 = load i32*, i32** %6
store i32 %30, i32* %31
%32 = load i32, i32* %10
%33 = load i32, i32* %11
%34 = xor i32 %33, -1
%35 = or i32 %32, %34
%36 = sub i32 %35, 1
%37 = load i32*, i32** %7
store i32 %36, i32* %37
store i32 1, i32* %4
br label %38
38: ; preds = %22, %21, %16
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] zeroinitializer
define i32 @cidrToIpRange(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = tail call i32 @ip2ui(i8* %4)
%11 = tail call i32 @createBitmask(i8* %7)
%12 = and i32 %11, %10
%13 = add i32 %12, 1
store i32 %13, i32* %1
%14 = xor i32 %11, -1
%15 = or i32 %10, %14
%16 = add i32 %15, -1
store i32 %16, i32* %2
br label %17
17: ; preds = %9, %6, %3
%18 = phi i32 [ 0, %3 ], [ 1, %9 ], [ 0, %6 ]
ret i32 %18
}