#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 */
int atoi(char *);
int bin(char *);
int dec(char *);
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, long);
int main(int argc, char **argv) {
  int i;
  int cidr;
  long int j;
  char *mode;
  char *nmask;
  i = 0;
  mode = argv[1];
  nmask = argv[2];
  if (mode[0] != '-')
    return -1;
  if (mode[1] == 'b') {
    i = 1;
  } else if (mode[1] == 'd') {
    i = 2;
  } else if (mode[1] == 'c') {
    i = 3;
  }
  switch (i) {
  case 0:
    cidr = -1;
    break;
  case 1:
    cidr = bin(nmask);
    break;
  case 2:
    cidr = dec(nmask);
    break;
  case 3:
    cidr = atoi(nmask);
    break;
  }
  if (cidr > -1) {
    printf("/%i\n", cidr);
  } else if (cidr < 0) {
    return -1;
  }
  j = (long int)pow(2, cidr);
  printf("\nNetworks: %li\n", j);
  j = (long int)pow(2, 32 - cidr);
  printf("Hosts:    %li\n", j);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11a1 <main+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e4 <main+0x194>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x62,%eax
jne    11be <main+0x6e>
movl   $0x1,-0x14(%rbp)
jmp    11fd <main+0xad>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    11db <main+0x8b>
movl   $0x2,-0x14(%rbp)
jmp    11f8 <main+0xa8>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x63,%eax
jne    11f3 <main+0xa3>
movl   $0x3,-0x14(%rbp)
jmp    11f8 <main+0xa8>
jmp    11fd <main+0xad>
mov    -0x14(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x3,%rax
ja     125c <main+0x10c>
mov    -0x38(%rbp),%rax
lea    0xde7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xffffffff,-0x18(%rbp)
jmp    125c <main+0x10c>
mov    -0x30(%rbp),%rdi
call   1040 <bin@plt>
mov    %eax,-0x18(%rbp)
jmp    125c <main+0x10c>
mov    -0x30(%rbp),%rdi
call   1030 <dec@plt>
mov    %eax,-0x18(%rbp)
jmp    125c <main+0x10c>
mov    -0x30(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jle    127b <main+0x12b>
movslq -0x18(%rbp),%rsi
lea    0xd9f(%rip),%rdi
call   1050 <printf@plt>
jmp    1296 <main+0x146>
cmpl   $0x0,-0x18(%rbp)
jge    1291 <main+0x141>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e4 <main+0x194>
jmp    1296 <main+0x146>
mov    -0x18(%rbp),%esi
mov    $0x2,%edi
call   1060 <pow@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xd63(%rip),%rdi
call   1050 <printf@plt>
mov    $0x20,%esi
sub    -0x18(%rbp),%esi
mov    $0x2,%edi
call   1060 <pow@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xd4d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x8(%rsi),%rax
mov    $0xffffffff,%ebx
cmpb   $0x2d,(%rax)
jne    11d8 <main+0x88>
mov    0x10(%rsi),%rdi
mov    0x1(%rax),%al
cmp    $0x64,%al
je     117b <main+0x2b>
cmp    $0x63,%al
je     1182 <main+0x32>
cmp    $0x62,%al
jne    11d8 <main+0x88>
call   1040 <bin@plt>
jmp    1187 <main+0x37>
call   1030 <dec@plt>
jmp    1187 <main+0x37>
call   1070 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11d8 <main+0x88>
mov    %ebp,%esi
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%edi
mov    %ebp,%esi
call   1060 <pow@plt>
lea    0xe57(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    $0x20,%esi
sub    %ebp,%esi
mov    $0x2,%edi
call   1060 <pow@plt>
lea    0xe47(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/%i\0A\00"
@.str.1 = [16 x i8] c"\0ANetworks: %li\0A\00"
@.str.2 = [15 x i8] c"Hosts: %li\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 i64
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %9
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
store i8* %16, i8** %10
%17 = load i8*, i8** %9
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 45
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 -1, i32* %3
br label %80
23: ; preds = %2
%24 = load i8*, i8** %9
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 98
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %6
br label %46
30: ; preds = %23
%31 = load i8*, i8** %9
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 100
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 2, i32* %6
br label %45
37: ; preds = %30
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 99
br i1 %42, label %43, label %44
43: ; preds = %37
store i32 3, i32* %6
br label %44
44: ; preds = %43, %37
br label %45
45: ; preds = %44, %36
br label %46
46: ; preds = %45, %29
%47 = load i32, i32* %6
switch i32 %47, label %58 [
i32 0, label %48
i32 1, label %49
i32 2, label %52
i32 3, label %55
]
48: ; preds = %46
store i32 -1, i32* %7
br label %58
49: ; preds = %46
%50 = load i8*, i8** %10
%51 = call i32 @bin(i8* %50)
store i32 %51, i32* %7
br label %58
52: ; preds = %46
%53 = load i8*, i8** %10
%54 = call i32 @dec(i8* %53)
store i32 %54, i32* %7
br label %58
55: ; preds = %46
%56 = load i8*, i8** %10
%57 = call i32 @atoi(i8* %56)
store i32 %57, i32* %7
br label %58
58: ; preds = %46, %55, %52, %49, %48
%59 = load i32, i32* %7
%60 = icmp sgt i32 %59, -1
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %63)
br label %70
65: ; preds = %58
%66 = load i32, i32* %7
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %65
store i32 -1, i32* %3
br label %80
69: ; preds = %65
br label %70
70: ; preds = %69, %61
%71 = load i32, i32* %7
%72 = call i64 @pow(i32 2, i32 %71)
store i64 %72, i64* %8
%73 = load i64, i64* %8
%74 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %73)
%75 = load i32, i32* %7
%76 = sub nsw i32 32, %75
%77 = call i64 @pow(i32 2, i32 %76)
store i64 %77, i64* %8
%78 = load i64, i64* %8
%79 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %78)
store i32 0, i32* %3
br label %80
80: ; preds = %70, %68, %22
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str = [5 x i8] c"/%i\0A\00"
@.str.1 = [16 x i8] c"\0ANetworks: %li\0A\00"
@.str.2 = [15 x i8] c"Hosts: %li\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 45
br i1 %8, label %9, label %29
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %4, i64 1
%11 = load i8, i8* %10
switch i8 %11, label %29 [
i8 98, label %12
i8 100, label %14
i8 99, label %16
]
12: ; preds = %9
%13 = tail call i32 @bin(i8* %6)
br label %18
14: ; preds = %9
%15 = tail call i32 @dec(i8* %6)
br label %18
16: ; preds = %9
%17 = tail call i32 @atoi(i8* %6)
br label %18
18: ; preds = %16, %14, %12
%19 = phi i32 [ %17, %16 ], [ %15, %14 ], [ %13, %12 ]
%20 = icmp sgt i32 %19, -1
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = zext i32 %19 to i64
%23 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %22)
%24 = tail call i64 @pow(i32 2, i32 %19)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %24)
%26 = sub nsw i32 32, %19
%27 = tail call i64 @pow(i32 2, i32 %26)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %27)
br label %29
29: ; preds = %9, %18, %2, %21
%30 = phi i32 [ 0, %21 ], [ -1, %2 ], [ -1, %18 ], [ -1, %9 ]
ret i32 %30
}