#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 calc_broadcast(unsigned int, unsigned int);
unsigned int calc_network_address(unsigned int, unsigned int);
unsigned int cidr_to_mask(unsigned int);
unsigned int dotted_decimal_to_int(char *);
unsigned int get_cidr_value(char *);
int /*<<< orphan*/ help();
unsigned int mask_to_cidr(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printip(unsigned int);
int main(int argc, char **argv) {
  unsigned int netmask = 0;
  unsigned int cidrValue = 0;
  unsigned int network_addr = 0;
  unsigned int i_address = 0;
  unsigned int firstHost = 0;
  unsigned int lastHost = 0;
  unsigned int broadcast = 0;
  unsigned int hostCount = 0;
  if (argc < 3) {
    help();
    return 0;
  } else {
    i_address = dotted_decimal_to_int(argv[1]);
    if ((char)argv[2][0] == '/') {
      cidrValue = get_cidr_value(argv[2]);
      netmask = cidr_to_mask(cidrValue);
    } else {
      netmask = dotted_decimal_to_int(argv[2]);
      cidrValue = mask_to_cidr(netmask);
    }
    network_addr = calc_network_address(i_address, netmask);
    firstHost = network_addr + 1;
    broadcast = calc_broadcast(network_addr, netmask);
    lastHost = broadcast - 1;
    hostCount = broadcast - firstHost;
  }
  printf("ip address:\t\t");
  printip(i_address);
  printf("subnet:\t\t\t");
  printip(netmask);
  printf("cidr notation:\t\t/%u\n", cidrValue);
  if (cidrValue == 32) {
    printf("\n***/32 masks can only be used to describe a single host***\n\n");
  } else if (cidrValue == 31) {
    printf("first host:\t\t");
    printip(network_addr);
    printf("last host:\t\t");
    printip(broadcast);
    printf("\n***/31 masks should only be used on point-to-point links***\n\n");
  } else {
    printf("network address:\t");
    printip(network_addr);
    printf("first host:\t\t");
    printip(firstHost);
    printf("last host:\t\t");
    printip(lastHost);
    printf("broadcast:\t\t");
    printip(broadcast);
    printf("hostcount:\t\t%d\n", hostCount);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-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)
cmpl   $0x3,-0x8(%rbp)
jge    11fb <main+0x6b>
mov    $0x0,%al
call   10b0 <help@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a9 <main+0x219>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <dotted_decimal_to_int@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    123f <main+0xaf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <get_cidr_value@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <cidr_to_mask@plt>
mov    %eax,-0x14(%rbp)
jmp    125a <main+0xca>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <dotted_decimal_to_int@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <mask_to_cidr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <calc_network_address@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <calc_broadcast@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%edi
call   1060 <printip@plt>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <printip@plt>
mov    -0x18(%rbp),%esi
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x20,-0x18(%rbp)
jne    12eb <main+0x15b>
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13a2 <main+0x212>
cmpl   $0x1f,-0x18(%rbp)
jne    1334 <main+0x1a4>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <printip@plt>
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1060 <printip@plt>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    139d <main+0x20d>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1060 <printip@plt>
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
call   1060 <printip@plt>
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%edi
call   1060 <printip@plt>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1060 <printip@plt>
mov    -0x30(%rbp),%esi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13a2 <main+0x212>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jg     11b9 <main+0x19>
xor    %eax,%eax
call   10c0 <help@plt>
jmp    1315 <main+0x175>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10b0 <dotted_decimal_to_int@plt>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
cmpb   $0x2f,(%rdi)
jne    11e3 <main+0x43>
call   1090 <get_cidr_value@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <cidr_to_mask@plt>
mov    %eax,%ebp
jmp    11f3 <main+0x53>
call   10b0 <dotted_decimal_to_int@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   10a0 <mask_to_cidr@plt>
mov    %eax,%ebx
mov    %r12d,%edi
mov    %ebp,%esi
call   1030 <calc_network_address@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    %ebp,%esi
call   1060 <calc_broadcast@plt>
mov    %eax,%r14d
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%edi
call   1070 <printip@plt>
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <printip@plt>
lea    0xddb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x1f,%ebx
je     1262 <main+0xc2>
cmp    $0x20,%ebx
jne    129c <main+0xfc>
lea    0xe5e(%rip),%rdi
call   1040 <puts@plt>
jmp    1315 <main+0x175>
lea    0xdc5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
call   1070 <printip@plt>
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1070 <printip@plt>
lea    0xde3(%rip),%rdi
call   1040 <puts@plt>
jmp    1315 <main+0x175>
mov    %r15d,%ebx
add    $0x1,%ebx
mov    %r14d,%r12d
sub    %ebx,%r12d
mov    %r14d,%ebp
add    $0xffffffff,%ebp
lea    0xd94(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
call   1070 <printip@plt>
lea    0xd63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <printip@plt>
lea    0xd5c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <printip@plt>
lea    0xd66(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1070 <printip@plt>
lea    0xd5d(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"ip address:\09\09\00"
@.str.1 = [11 x i8] c"subnet:\09\09\09\00"
@.str.2 = [21 x i8] c"cidr notation:\09\09/%u\0A\00"
@.str.3 = [62 x i8] c"\0A***/32 masks can only be used to describe a single host***\0A\0A\00"
@.str.4 = [14 x i8] c"first host:\09\09\00"
@.str.5 = [13 x i8] c"last host:\09\09\00"
@.str.6 = [63 x i8] c"\0A***/31 masks should only be used on point-to-point links***\0A\0A\00"
@.str.7 = [18 x i8] c"network address:\09\00"
@.str.8 = [13 x i8] c"broadcast:\09\09\00"
@.str.9 = [16 x i8] c"hostcount:\09\09%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%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 i32 0, i32* %3
store i32 %0, i32* %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
store i32 0, i32* %13
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (...) @help()
store i32 0, i32* %3
br label %99
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @dotted_decimal_to_int(i8* %21)
store i32 %22, i32* %9
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 47
br i1 %29, label %30, label %37
30: ; preds = %18
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @get_cidr_value(i8* %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = call i32 @cidr_to_mask(i32 %35)
store i32 %36, i32* %6
br label %44
37: ; preds = %18
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @dotted_decimal_to_int(i8* %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = call i32 @mask_to_cidr(i32 %42)
store i32 %43, i32* %7
br label %44
44: ; preds = %37, %30
%45 = load i32, i32* %9
%46 = load i32, i32* %6
%47 = call i32 @calc_network_address(i32 %45, i32 %46)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = add i32 %48, 1
store i32 %49, i32* %10
%50 = load i32, i32* %8
%51 = load i32, i32* %6
%52 = call i32 @calc_broadcast(i32 %50, i32 %51)
store i32 %52, i32* %12
%53 = load i32, i32* %12
%54 = sub i32 %53, 1
store i32 %54, i32* %11
%55 = load i32, i32* %12
%56 = load i32, i32* %10
%57 = sub i32 %55, %56
store i32 %57, i32* %13
br label %58
58: ; preds = %44
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%60 = load i32, i32* %9
%61 = call i32 @printip(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%63 = load i32, i32* %6
%64 = call i32 @printip(i32 %63)
%65 = load i32, i32* %7
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %7
%68 = icmp eq i32 %67, 32
br i1 %68, label %69, label %71
69: ; preds = %58
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0))
br label %98
71: ; preds = %58
%72 = load i32, i32* %7
%73 = icmp eq i32 %72, 31
br i1 %73, label %74, label %82
74: ; preds = %71
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%76 = load i32, i32* %8
%77 = call i32 @printip(i32 %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%79 = load i32, i32* %12
%80 = call i32 @printip(i32 %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0))
br label %97
82: ; preds = %71
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%84 = load i32, i32* %8
%85 = call i32 @printip(i32 %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%87 = load i32, i32* %10
%88 = call i32 @printip(i32 %87)
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%90 = load i32, i32* %11
%91 = call i32 @printip(i32 %90)
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%93 = load i32, i32* %12
%94 = call i32 @printip(i32 %93)
%95 = load i32, i32* %13
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %82, %74
br label %98
98: ; preds = %97, %69
store i32 0, i32* %3
br label %99
99: ; preds = %98, %16
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@.str = [14 x i8] c"ip address:\09\09\00"
@.str.1 = [11 x i8] c"subnet:\09\09\09\00"
@.str.2 = [21 x i8] c"cidr notation:\09\09/%u\0A\00"
@.str.4 = [14 x i8] c"first host:\09\09\00"
@.str.5 = [13 x i8] c"last host:\09\09\00"
@.str.7 = [18 x i8] c"network address:\09\00"
@.str.8 = [13 x i8] c"broadcast:\09\09\00"
@.str.9 = [16 x i8] c"hostcount:\09\09%d\0A\00"
@str = [62 x i8] c"\0A***/31 masks should only be used on point-to-point links***\0A\00"
@str.10 = [61 x i8] c"\0A***/32 masks can only be used to describe a single host***\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @help()
br label %51
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @dotted_decimal_to_int(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = tail call i32 @get_cidr_value(i8* %11)
%16 = tail call i32 @cidr_to_mask(i32 %15)
br label %20
17: ; preds = %6
%18 = tail call i32 @dotted_decimal_to_int(i8* %11)
%19 = tail call i32 @mask_to_cidr(i32 %18)
br label %20
20: ; preds = %17, %14
%21 = phi i32 [ %16, %14 ], [ %18, %17 ]
%22 = phi i32 [ %15, %14 ], [ %19, %17 ]
%23 = tail call i32 @calc_network_address(i32 %9, i32 %21)
%24 = add i32 %23, 1
%25 = tail call i32 @calc_broadcast(i32 %23, i32 %21)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 @printip(i32 %9)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @printip(i32 %21)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %22)
switch i32 %22, label %39 [
i32 32, label %31
i32 31, label %33
]
31: ; preds = %20
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.10, i64 0, i64 0))
br label %51
33: ; preds = %20
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i32 @printip(i32 %23)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%37 = tail call i32 @printip(i32 %25)
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
br label %51
39: ; preds = %20
%40 = sub i32 %25, %24
%41 = add i32 %25, -1
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%43 = tail call i32 @printip(i32 %23)
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%45 = tail call i32 @printip(i32 %24)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%47 = tail call i32 @printip(i32 %41)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%49 = tail call i32 @printip(i32 %25)
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %40)
br label %51
51: ; preds = %31, %39, %33, %4
ret i32 0
}