#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ u_char;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ *__u6_addr8;
};
struct in6_addr {
  TYPE_1__ __in6_u;
};

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ setb(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int unsetmask(int af, u_char *adrspace, unsigned b) {
  int i;
  union {
    struct in6_addr *in6;
    struct in_addr *in;
  } adu;
  if (af == AF_INET6) {
    adu.in6 = (struct in6_addr *)adrspace;
    for (i = 128 - 1; i >= (128 - b); i--)
      setb((u_char *)&adu.in6->__in6_u.__u6_addr8[0], i, 0);
  }
  if (af == AF_INET) {
    adu.in = (struct in_addr *)adrspace;
    for (i = 32 - 1; i >= (32 - b); i--)
      setb((u_char *)&adu.in->s_addr, i, 0);
  }
  return (0);
}


x86 assembly (clang, -O0):
<unsetmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2eb4(%rip),%rcx
cmp    (%rcx),%eax
jne    117a <unsetmask+0x6a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x7f,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x80,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jb     1175 <unsetmask+0x65>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1030 <setb@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1143 <unsetmask+0x33>
jmp    117a <unsetmask+0x6a>
mov    -0x4(%rbp),%eax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%eax
jne    11cf <unsetmask+0xbf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1f,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x20,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jb     11ca <unsetmask+0xba>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
call   1030 <setb@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    119b <unsetmask+0x8b>
jmp    11cf <unsetmask+0xbf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unsetmask>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %edi,%r15d
mov    0x2eb8(%rip),%rax
cmp    %edi,(%rax)
jne    1154 <unsetmask+0x44>
mov    $0x80,%ebx
sub    %r14d,%ebx
cmp    $0x7f,%ebx
ja     1154 <unsetmask+0x44>
mov    $0x7f,%ebp
xchg   %ax,%ax
mov    (%r12),%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1030 <setb@plt>
add    $0xffffffff,%ebp
cmp    %ebx,%ebp
jae    1140 <unsetmask+0x30>
mov    0x2e8d(%rip),%rax
cmp    %r15d,(%rax)
jne    1193 <unsetmask+0x83>
mov    $0x20,%ebx
sub    %r14d,%ebx
cmp    $0x1f,%ebx
ja     1193 <unsetmask+0x83>
mov    $0x1f,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1030 <setb@plt>
add    $0xffffffff,%ebp
cmp    %ebx,%ebp
jae    1180 <unsetmask+0x70>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.anon = type { %struct.in6_addr* }
%struct.in6_addr = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32* }
%struct.in_addr = type { i32 }
@AF_INET6 = global i32 0
@AF_INET = global i32 0
define i32 @unsetmask(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %union.anon
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = load i32, i32* @AF_INET6
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %34
12: ; preds = %3
%13 = load i32*, i32** %5
%14 = bitcast i32* %13 to %struct.in6_addr*
%15 = bitcast %union.anon* %8 to %struct.in6_addr**
store %struct.in6_addr* %14, %struct.in6_addr** %15
store i32 127, i32* %7
br label %16
16: ; preds = %30, %12
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = sub i32 128, %18
%20 = icmp uge i32 %17, %19
br i1 %20, label %21, label %33
21: ; preds = %16
%22 = bitcast %union.anon* %8 to %struct.in6_addr**
%23 = load %struct.in6_addr*, %struct.in6_addr** %22
%24 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %23, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
%26 = load i32*, i32** %25
%27 = getelementptr inbounds i32, i32* %26, i64 0
%28 = load i32, i32* %7
%29 = call i32 @setb(i32* %27, i32 %28, i32 0)
br label %30
30: ; preds = %21
%31 = load i32, i32* %7
%32 = add nsw i32 %31, -1
store i32 %32, i32* %7
br label %16
33: ; preds = %16
br label %34
34: ; preds = %33, %3
%35 = load i32, i32* %4
%36 = load i32, i32* @AF_INET
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %57
38: ; preds = %34
%39 = load i32*, i32** %5
%40 = bitcast i32* %39 to %struct.in_addr*
%41 = bitcast %union.anon* %8 to %struct.in_addr**
store %struct.in_addr* %40, %struct.in_addr** %41
store i32 31, i32* %7
br label %42
42: ; preds = %53, %38
%43 = load i32, i32* %7
%44 = load i32, i32* %6
%45 = sub i32 32, %44
%46 = icmp uge i32 %43, %45
br i1 %46, label %47, label %56
47: ; preds = %42
%48 = bitcast %union.anon* %8 to %struct.in_addr**
%49 = load %struct.in_addr*, %struct.in_addr** %48
%50 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %49, i32 0, i32 0
%51 = load i32, i32* %7
%52 = call i32 @setb(i32* %50, i32 %51, i32 0)
br label %53
53: ; preds = %47
%54 = load i32, i32* %7
%55 = add nsw i32 %54, -1
store i32 %55, i32* %7
br label %42
56: ; preds = %42
br label %57
57: ; preds = %56, %34
ret i32 0
}

LLVM IR (-O2):
@AF_INET6 = global i32 0
@AF_INET = global i32 0
define i32 @unsetmask(i32 %0, i32* %1, i32 %2) {
%4 = load i32, i32* @AF_INET6
%5 = icmp eq i32 %4, %0
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = sub i32 128, %2
%8 = icmp ugt i32 %7, 127
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = bitcast i32* %1 to i32**
br label %11
11: ; preds = %9, %11
%12 = phi i32 [ 127, %9 ], [ %15, %11 ]
%13 = load i32*, i32** %10
%14 = tail call i32 @setb(i32* %13, i32 %12, i32 0)
%15 = add nsw i32 %12, -1
%16 = icmp ult i32 %15, %7
br i1 %16, label %17, label %11
17: ; preds = %11, %6, %3
%18 = load i32, i32* @AF_INET
%19 = icmp eq i32 %18, %0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = sub i32 32, %2
%22 = icmp ugt i32 %21, 31
br i1 %22, label %28, label %23
23: ; preds = %20, %23
%24 = phi i32 [ %26, %23 ], [ 31, %20 ]
%25 = tail call i32 @setb(i32* %1, i32 %24, i32 0)
%26 = add nsw i32 %24, -1
%27 = icmp ult i32 %26, %21
br i1 %27, label %28, label %23
28: ; preds = %23, %20, %17
ret i32 0
}