#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 u_int32_t;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
scalar_t__ inet_aton(char *, struct in_addr *);
int ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ panic(char *, ...);
scalar_t__ strtou32(int *, char *);
u_int32_t mspectou32(char *mstr) {
  u_int32_t mask = 0, num;
  struct in_addr s;
  if (strtou32(&num, mstr))
    mask = num ? ~0 << (32 - num) : num;
  else if (inet_aton(mstr, &s)) {
    mask = ntohl(s.s_addr);
    for (num = ~mask; num & 1; num >>= 1)
      ;
    if (num) {
      for (num = mask; num & 1; num >>= 1)
        ;
      if (num)
        panic("invalid mask 0x%08x from \"%s\"", mask, mstr);
      mask = ~mask;
    }
  } else
    panic("unable to parse \"%s\"", mstr);
  return (mask);
}


x86 assembly (clang, -O0):
<mspectou32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1040 <strtou32@plt>
cmp    $0x0,%rax
je     119c <mspectou32+0x5c>
cmpl   $0x0,-0x10(%rbp)
je     118b <mspectou32+0x4b>
mov    $0x20,%ecx
sub    -0x10(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
mov    %eax,-0x1c(%rbp)
jmp    1191 <mspectou32+0x51>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    125f <mspectou32+0x11f>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <inet_aton@plt>
cmp    $0x0,%rax
je     1248 <mspectou32+0x108>
mov    -0x18(%rbp),%edi
call   1060 <ntohl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11e9 <mspectou32+0xa9>
jmp    11db <mspectou32+0x9b>
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c7 <mspectou32+0x87>
cmpl   $0x0,-0x10(%rbp)
je     1243 <mspectou32+0x103>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     121b <mspectou32+0xdb>
jmp    120d <mspectou32+0xcd>
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f9 <mspectou32+0xb9>
cmpl   $0x0,-0x10(%rbp)
je     123a <mspectou32+0xfa>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    125a <mspectou32+0x11a>
mov    -0x8(%rbp),%rsi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
jmp    125f <mspectou32+0x11f>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mspectou32>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <strtou32@plt>
test   %rax,%rax
je     1178 <mspectou32+0x38>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
neg    %cl
mov    $0xffffffff,%ebp
shl    %cl,%ebp
test   %eax,%eax
cmove  %eax,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <inet_aton@plt>
test   %rax,%rax
je     11d6 <mspectou32+0x96>
mov    0x10(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,%ebp
not    %ebp
mov    %ebp,%ecx
nopl   0x0(%rax)
mov    %ecx,%edx
sar    %ecx
test   $0x1,%dl
jne    11a0 <mspectou32+0x60>
test   %edx,%edx
je     11eb <mspectou32+0xab>
mov    %eax,%edx
nop
mov    %edx,%ecx
sar    %edx
test   $0x1,%cl
jne    11b0 <mspectou32+0x70>
mov    %ecx,0xc(%rsp)
test   %ecx,%ecx
je     116f <mspectou32+0x2f>
lea    0xe38(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <panic@plt>
jmp    116f <mspectou32+0x2f>
lea    0xe41(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <panic@plt>
jmp    116f <mspectou32+0x2f>
mov    %eax,%ebp
jmp    116f <mspectou32+0x2f>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [30 x i8] c"invalid mask 0x%08x from \22%s\22\00"
@.str.1 = [21 x i8] c"unable to parse \22%s\22\00"
define i32 @mspectou32(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.in_addr
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = call i64 @strtou32(i32* %4, i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* %4
%14 = sub nsw i32 32, %13
%15 = shl i32 -1, %14
br label %18
16: ; preds = %9
%17 = load i32, i32* %4
br label %18
18: ; preds = %16, %12
%19 = phi i32 [ %15, %12 ], [ %17, %16 ]
store i32 %19, i32* %3
br label %66
20: ; preds = %1
%21 = load i8*, i8** %2
%22 = call i64 @inet_aton(i8* %21, %struct.in_addr* %5)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %62
24: ; preds = %20
%25 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @ntohl(i32 %26)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = xor i32 %28, -1
store i32 %29, i32* %4
br label %30
30: ; preds = %35, %24
%31 = load i32, i32* %4
%32 = and i32 %31, 1
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %30
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = ashr i32 %36, 1
store i32 %37, i32* %4
br label %30
38: ; preds = %30
%39 = load i32, i32* %4
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %61
41: ; preds = %38
%42 = load i32, i32* %3
store i32 %42, i32* %4
br label %43
43: ; preds = %48, %41
%44 = load i32, i32* %4
%45 = and i32 %44, 1
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
br label %48
48: ; preds = %47
%49 = load i32, i32* %4
%50 = ashr i32 %49, 1
store i32 %50, i32* %4
br label %43
51: ; preds = %43
%52 = load i32, i32* %4
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i32, i32* %3
%56 = load i8*, i8** %2
%57 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %55, i8* %56)
br label %58
58: ; preds = %54, %51
%59 = load i32, i32* %3
%60 = xor i32 %59, -1
store i32 %60, i32* %3
br label %61
61: ; preds = %58, %38
br label %65
62: ; preds = %20
%63 = load i8*, i8** %2
%64 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %62, %61
br label %66
66: ; preds = %65, %18
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [30 x i8] c"invalid mask 0x%08x from \22%s\22\00"
@.str.1 = [21 x i8] c"unable to parse \22%s\22\00"
define i32 @mspectou32(i8* %0) {
%2 = alloca i32
%3 = alloca %struct.in_addr
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.in_addr* %3 to i8*
%6 = call i64 @strtou32(i32* %2, i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
%11 = sub nsw i32 32, %9
%12 = shl nsw i32 -1, %11
%13 = select i1 %10, i32 0, i32 %12
br label %40
14: ; preds = %1
%15 = call i64 @inet_aton(i8* %0, %struct.in_addr* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %38, label %17
17: ; preds = %14
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @ntohl(i32 %19)
%21 = xor i32 %20, -1
br label %22
22: ; preds = %22, %17
%23 = phi i32 [ %21, %17 ], [ %26, %22 ]
%24 = and i32 %23, 1
%25 = icmp eq i32 %24, 0
%26 = ashr i32 %23, 1
br i1 %25, label %27, label %22
27: ; preds = %22
%28 = icmp eq i32 %23, 0
br i1 %28, label %40, label %29
29: ; preds = %27, %29
%30 = phi i32 [ %33, %29 ], [ %20, %27 ]
%31 = and i32 %30, 1
%32 = icmp eq i32 %31, 0
%33 = ashr i32 %30, 1
br i1 %32, label %34, label %29
34: ; preds = %29
store i32 %30, i32* %2
%35 = icmp eq i32 %30, 0
br i1 %35, label %40, label %36
36: ; preds = %34
%37 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %0)
br label %40
38: ; preds = %14
%39 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %40
40: ; preds = %34, %36, %38, %27, %8
%41 = phi i32 [ %13, %8 ], [ %20, %27 ], [ 0, %38 ], [ %21, %36 ], [ %21, %34 ]
ret i32 %41
}