#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 strlen(char *);
int /*<<< orphan*/ submask_sub(char *, int);
unsigned int submask_zip(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/, int /*<<< orphan*/);
int _submask_unmask(char ip[16], char mask[16]) {
  if (strlen(mask) > 2) {
    int c;
    unsigned int i = submask_zip(submask_sub(mask, 1), submask_sub(mask, 2),
                                 submask_sub(mask, 3), submask_sub(mask, 4));
    i = ~i;
    for (c = 1; c <= 32; c++) {
      if ((i & 1) == 0)
        break;
      i = i >> 1;
    }
    for (c++; c <= 32; c++) {
      if ((i & 1) == 1) {
        return 1;
      }
      i = i >> 1;
    }
  } else {
    unsigned int i = submask_zip(submask_sub(ip, 1), submask_sub(ip, 2),
                                 submask_sub(ip, 3), submask_sub(ip, 4));
    i = i >> (32 - atoi(mask));
    if (i == 0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<_submask_unmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jle    1245 <_submask_unmask+0x105>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <submask_sub@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2,%esi
call   1030 <submask_sub@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3,%esi
call   1030 <submask_sub@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1030 <submask_sub@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    %eax,%ecx
call   1050 <submask_zip@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jg     11fb <_submask_unmask+0xbb>
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11e4 <_submask_unmask+0xa4>
jmp    11fb <_submask_unmask+0xbb>
mov    -0x20(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c6 <_submask_unmask+0x86>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jg     1240 <_submask_unmask+0x100>
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    1229 <_submask_unmask+0xe9>
movl   $0x1,-0x4(%rbp)
jmp    12db <_submask_unmask+0x19b>
mov    -0x20(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1204 <_submask_unmask+0xc4>
jmp    12d4 <_submask_unmask+0x194>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <submask_sub@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1030 <submask_sub@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
call   1030 <submask_sub@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1030 <submask_sub@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    %eax,%ecx
call   1050 <submask_zip@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%edx
mov    -0x34(%rbp),%eax
mov    $0x20,%ecx
sub    %edx,%ecx
shr    %cl,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    12cf <_submask_unmask+0x18f>
movl   $0x1,-0x4(%rbp)
jmp    12db <_submask_unmask+0x19b>
jmp    12d4 <_submask_unmask+0x194>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_submask_unmask>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jl     11c1 <_submask_unmask+0x81>
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <submask_sub@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <submask_sub@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <submask_sub@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <submask_sub@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %eax,%ecx
call   1050 <submask_zip@plt>
not    %eax
test   $0x1,%al
jne    123d <_submask_unmask+0xfd>
mov    %eax,%ecx
jmp    1263 <_submask_unmask+0x123>
mov    $0x1,%r14d
mov    %rbp,%rdi
mov    $0x1,%esi
call   1030 <submask_sub@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
mov    $0x2,%esi
call   1030 <submask_sub@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
mov    $0x3,%esi
call   1030 <submask_sub@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
mov    $0x4,%esi
call   1030 <submask_sub@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %eax,%ecx
call   1050 <submask_zip@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <atoi@plt>
neg    %al
mov    %eax,%ecx
shr    %cl,%ebp
test   %ebp,%ebp
je     122b <_submask_unmask+0xeb>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
mov    %eax,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edx
shr    %ecx
lea    0x1(%rdx),%ebp
cmp    $0x1f,%edx
ja     1263 <_submask_unmask+0x123>
and    $0x2,%eax
mov    %ecx,%eax
jne    1250 <_submask_unmask+0x110>
cmp    $0x20,%ebp
setb   %al
jae    1296 <_submask_unmask+0x156>
mov    %ecx,%edx
and    $0x1,%edx
jne    1296 <_submask_unmask+0x156>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x1f,%ebp
setb   %al
jae    1296 <_submask_unmask+0x156>
add    $0x1,%ebp
mov    %ecx,%edx
shr    %edx
and    $0x2,%ecx
mov    %edx,%ecx
je     1280 <_submask_unmask+0x140>
mov    $0x1,%r14d
test   %al,%al
je     1228 <_submask_unmask+0xe8>
jmp    122b <_submask_unmask+0xeb>

LLVM IR (-O0):
define i32 @_submask_unmask(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %56
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i32 @submask_sub(i8* %13, i32 1)
%15 = load i8*, i8** %5
%16 = call i32 @submask_sub(i8* %15, i32 2)
%17 = load i8*, i8** %5
%18 = call i32 @submask_sub(i8* %17, i32 3)
%19 = load i8*, i8** %5
%20 = call i32 @submask_sub(i8* %19, i32 4)
%21 = call i32 @submask_zip(i32 %14, i32 %16, i32 %18, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = xor i32 %22, -1
store i32 %23, i32* %7
store i32 1, i32* %6
br label %24
24: ; preds = %35, %12
%25 = load i32, i32* %6
%26 = icmp sle i32 %25, 32
br i1 %26, label %27, label %38
27: ; preds = %24
%28 = load i32, i32* %7
%29 = and i32 %28, 1
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %38
32: ; preds = %27
%33 = load i32, i32* %7
%34 = lshr i32 %33, 1
store i32 %34, i32* %7
br label %35
35: ; preds = %32
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %24
38: ; preds = %31, %24
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %41
41: ; preds = %52, %38
%42 = load i32, i32* %6
%43 = icmp sle i32 %42, 32
br i1 %43, label %44, label %55
44: ; preds = %41
%45 = load i32, i32* %7
%46 = and i32 %45, 1
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 1, i32* %3
br label %76
49: ; preds = %44
%50 = load i32, i32* %7
%51 = lshr i32 %50, 1
store i32 %51, i32* %7
br label %52
52: ; preds = %49
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %41
55: ; preds = %41
br label %75
56: ; preds = %2
%57 = load i8*, i8** %4
%58 = call i32 @submask_sub(i8* %57, i32 1)
%59 = load i8*, i8** %4
%60 = call i32 @submask_sub(i8* %59, i32 2)
%61 = load i8*, i8** %4
%62 = call i32 @submask_sub(i8* %61, i32 3)
%63 = load i8*, i8** %4
%64 = call i32 @submask_sub(i8* %63, i32 4)
%65 = call i32 @submask_zip(i32 %58, i32 %60, i32 %62, i32 %64)
store i32 %65, i32* %8
%66 = load i32, i32* %8
%67 = load i8*, i8** %5
%68 = call i32 @atoi(i8* %67)
%69 = sub nsw i32 32, %68
%70 = lshr i32 %66, %69
store i32 %70, i32* %8
%71 = load i32, i32* %8
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %56
store i32 1, i32* %3
br label %76
74: ; preds = %56
br label %75
75: ; preds = %74, %55
store i32 0, i32* %3
br label %76
76: ; preds = %75, %73, %48
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
define i32 @_submask_unmask(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 2
br i1 %4, label %5, label %41
5: ; preds = %2
%6 = tail call i32 @submask_sub(i8* %1, i32 1)
%7 = tail call i32 @submask_sub(i8* %1, i32 2)
%8 = tail call i32 @submask_sub(i8* %1, i32 3)
%9 = tail call i32 @submask_sub(i8* %1, i32 4)
%10 = tail call i32 @submask_zip(i32 %6, i32 %7, i32 %8, i32 %9)
%11 = xor i32 %10, -1
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %21, %5
%15 = phi i32 [ 1, %5 ], [ %25, %21 ]
%16 = phi i32 [ %11, %5 ], [ %24, %21 ]
%17 = icmp ult i32 %15, 32
%18 = and i32 %16, 1
%19 = icmp eq i32 %18, 0
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %30, label %39
21: ; preds = %5, %21
%22 = phi i32 [ %24, %21 ], [ %11, %5 ]
%23 = phi i32 [ %25, %21 ], [ 1, %5 ]
%24 = lshr i32 %22, 1
%25 = add nuw nsw i32 %23, 1
%26 = icmp ugt i32 %23, 31
%27 = and i32 %22, 2
%28 = icmp eq i32 %27, 0
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %14, label %21
30: ; preds = %14, %30
%31 = phi i32 [ %34, %30 ], [ %16, %14 ]
%32 = phi i32 [ %33, %30 ], [ %15, %14 ]
%33 = add nuw nsw i32 %32, 1
%34 = lshr i32 %31, 1
%35 = icmp ult i32 %32, 31
%36 = and i32 %31, 2
%37 = icmp eq i32 %36, 0
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %30, label %39
39: ; preds = %30, %14
%40 = phi i1 [ %17, %14 ], [ %35, %30 ]
br i1 %40, label %52, label %51
41: ; preds = %2
%42 = tail call i32 @submask_sub(i8* %0, i32 1)
%43 = tail call i32 @submask_sub(i8* %0, i32 2)
%44 = tail call i32 @submask_sub(i8* %0, i32 3)
%45 = tail call i32 @submask_sub(i8* %0, i32 4)
%46 = tail call i32 @submask_zip(i32 %42, i32 %43, i32 %44, i32 %45)
%47 = tail call i32 @atoi(i8* %1)
%48 = sub nsw i32 32, %47
%49 = lshr i32 %46, %48
%50 = icmp eq i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %41, %39
br label %52
52: ; preds = %41, %39, %51
%53 = phi i32 [ 1, %39 ], [ 0, %51 ], [ 1, %41 ]
ret i32 %53
}