#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 /*<<< orphan*/ u_char;
struct in_addr {
  int /*<<< orphan*/ s_addr;
};
struct in6_addr {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ INET_ADDRSTRLEN;
int PF_INET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ bcopy(int /*<<< orphan*/ *, void *, int);
int /*<<< orphan*/ bzero(char *, int);
int getb(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ inet_ntop(int, int /*<<< orphan*/ *, char *,
                             int /*<<< orphan*/);
int /*<<< orphan*/ setb(int /*<<< orphan*/ *, int, int);
char *strdup(char *);
char *invert_mask(int af, void *addr, void *conv) {
  char buf[128];
  int i, bit;
  union {
    struct in6_addr *in6;
    struct in_addr *in;
  } adu;
  bzero(&buf[0], sizeof(buf));
  assert(af == PF_INET);
  adu.in = (struct in_addr *)addr;
  for (i = 32 - 1; i >= 0; i--) {
    bit = getb((u_char *)&adu.in->s_addr, i);
    if (bit == 0)
      setb((u_char *)&adu.in->s_addr, i, 1);
    else
      setb((u_char *)&adu.in->s_addr, i, 0);
  }
  if (conv != NULL)
    (void)bcopy(&adu.in->s_addr, conv, sizeof(adu.in->s_addr));
  inet_ntop(af, &adu.in->s_addr, &buf[0], INET_ADDRSTRLEN);
  return (strdup(&buf[0]));
}


x86 assembly (clang, -O0):
<invert_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
mov    $0x80,%esi
call   1080 <bzero@plt>
mov    -0x4(%rbp),%eax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0xb0(%rbp)
movl   $0x1f,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jl     1240 <invert_mask+0xd0>
mov    -0xb0(%rbp),%rdi
mov    -0xa4(%rbp),%esi
call   1040 <getb@plt>
mov    %eax,-0xa8(%rbp)
cmpl   $0x0,-0xa8(%rbp)
jne    1213 <invert_mask+0xa3>
mov    -0xb0(%rbp),%rdi
mov    -0xa4(%rbp),%esi
mov    $0x1,%edx
call   1060 <setb@plt>
jmp    1227 <invert_mask+0xb7>
mov    -0xb0(%rbp),%rdi
mov    -0xa4(%rbp),%esi
xor    %edx,%edx
call   1060 <setb@plt>
jmp    122c <invert_mask+0xbc>
mov    -0xa4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xa4(%rbp)
jmp    11c5 <invert_mask+0x55>
cmpq   $0x0,-0x18(%rbp)
je     1260 <invert_mask+0xf0>
mov    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1070 <bcopy@plt>
mov    -0x4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
mov    0x2d68(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
lea    -0xa0(%rbp),%rdi
call   1090 <strdup@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invert_mask>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsp,%rdi
mov    $0x80,%esi
call   1070 <bzero@plt>
mov    0x2e4e(%rip),%rax
xor    %edi,%edi
cmp    %r15d,(%rax)
sete   %dil
call   1050 <assert@plt>
mov    $0x1f,%ebp
nopl   (%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <getb@plt>
xor    %edx,%edx
test   %eax,%eax
sete   %dl
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <setb@plt>
add    $0xffffffff,%ebp
jb     11a0 <invert_mask+0x40>
test   %r14,%r14
je     11ca <invert_mask+0x6a>
mov    (%rbx),%eax
mov    %eax,(%r14)
mov    0x2e0f(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbp
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <inet_ntop@plt>
mov    %rbp,%rdi
call   1080 <strdup@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.anon = type { %struct.in6_addr* }
%struct.in6_addr = type { i32 }
%struct.in_addr = type { i32 }
@PF_INET = global i32 0
@INET_ADDRSTRLEN = global i32 0
define i8* @invert_mask(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca %union.anon
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%12 = call i32 @bzero(i8* %11, i32 128)
%13 = load i32, i32* %4
%14 = load i32, i32* @PF_INET
%15 = icmp eq i32 %13, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %5
%19 = bitcast i8* %18 to %struct.in_addr*
%20 = bitcast %union.anon* %10 to %struct.in_addr**
store %struct.in_addr* %19, %struct.in_addr** %20
store i32 31, i32* %8
br label %21
21: ; preds = %45, %3
%22 = load i32, i32* %8
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %48
24: ; preds = %21
%25 = bitcast %union.anon* %10 to %struct.in_addr**
%26 = load %struct.in_addr*, %struct.in_addr** %25
%27 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %26, i32 0, i32 0
%28 = load i32, i32* %8
%29 = call i32 @getb(i32* %27, i32 %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %24
%33 = bitcast %union.anon* %10 to %struct.in_addr**
%34 = load %struct.in_addr*, %struct.in_addr** %33
%35 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %34, i32 0, i32 0
%36 = load i32, i32* %8
%37 = call i32 @setb(i32* %35, i32 %36, i32 1)
br label %44
38: ; preds = %24
%39 = bitcast %union.anon* %10 to %struct.in_addr**
%40 = load %struct.in_addr*, %struct.in_addr** %39
%41 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %40, i32 0, i32 0
%42 = load i32, i32* %8
%43 = call i32 @setb(i32* %41, i32 %42, i32 0)
br label %44
44: ; preds = %38, %32
br label %45
45: ; preds = %44
%46 = load i32, i32* %8
%47 = add nsw i32 %46, -1
store i32 %47, i32* %8
br label %21
48: ; preds = %21
%49 = load i8*, i8** %6
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %57
51: ; preds = %48
%52 = bitcast %union.anon* %10 to %struct.in_addr**
%53 = load %struct.in_addr*, %struct.in_addr** %52
%54 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %53, i32 0, i32 0
%55 = load i8*, i8** %6
%56 = call i32 @bcopy(i32* %54, i8* %55, i32 4)
br label %57
57: ; preds = %51, %48
%58 = load i32, i32* %4
%59 = bitcast %union.anon* %10 to %struct.in_addr**
%60 = load %struct.in_addr*, %struct.in_addr** %59
%61 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %60, i32 0, i32 0
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%63 = load i32, i32* @INET_ADDRSTRLEN
%64 = call i32 @inet_ntop(i32 %58, i32* %61, i8* %62, i32 %63)
%65 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%66 = call i8* @strdup(i8* %65)
ret i8* %66
}

LLVM IR (-O2):
@PF_INET = global i32 0
@INET_ADDRSTRLEN = global i32 0
define noalias i8* @invert_mask(i32 %0, i8* %1, i8* writeonly %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = call i32 @bzero(i8* %5, i32 128)
%7 = load i32, i32* @PF_INET
%8 = icmp eq i32 %7, %0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = bitcast i8* %1 to i32*
br label %12
12: ; preds = %3, %12
%13 = phi i32 [ 31, %3 ], [ %18, %12 ]
%14 = tail call i32 @getb(i32* %11, i32 %13)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @setb(i32* %11, i32 %13, i32 %16)
%18 = add nsw i32 %13, -1
%19 = icmp eq i32 %13, 0
br i1 %19, label %20, label %12
20: ; preds = %12
%21 = icmp eq i8* %2, null
br i1 %21, label %25, label %22
22: ; preds = %20
%23 = bitcast i8* %2 to i32*
%24 = load i32, i32* %11
store i32 %24, i32* %23
br label %25
25: ; preds = %22, %20
%26 = load i32, i32* @INET_ADDRSTRLEN
%27 = call i32 @inet_ntop(i32 %0, i32* %11, i8* %5, i32 %26)
%28 = call i8* @strdup(i8* %5)
ret i8* %28
}