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

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int atoi(char *);
char *inet_ntop(int /*<<< orphan*/, struct in6_addr *, char *, int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  struct in6_addr in;
  char buf[64];
  int mask, i;
  inet_pton(AF_INET6, argv[1], &in);
  mask = atoi(argv[2]);
  if (mask < 128) {
    in.s6_addr[mask / 8] &= 0xff << (8 - mask % 8);
    for (i = (mask + 7) / 8; i < 16; i++)
      in.s6_addr[i] = 0;
  }
  printf("result: %s\n", inet_ntop(AF_INET6, &in, buf, sizeof(buf)));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <inet_pton@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x80,-0x64(%rbp)
jge    120e <main+0xce>
mov    -0x64(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    $0x8,%ecx
sub    %edx,%ecx
mov    $0xff,%eax
shl    %cl,%eax
mov    %eax,-0x74(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x64(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x74(%rbp),%edx
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
movslq %ecx,%rcx
and    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x64(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x68(%rbp)
cmpl   $0x10,-0x68(%rbp)
jge    1209 <main+0xc9>
mov    -0x18(%rbp),%rax
movslq -0x68(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11e2 <main+0xa2>
jmp    120e <main+0xce>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    -0x18(%rbp),%rsi
mov    $0x40,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,%rsi
lea    0xdcd(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    0x2e87(%rip),%r14
mov    (%r14),%edi
mov    0x8(%rsi),%rsi
lea    0x8(%rsp),%rdx
call   1060 <inet_pton@plt>
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
cmp    $0x7f,%eax
jg     11e0 <main+0x90>
lea    0x7(%rax),%esi
test   %eax,%eax
mov    %eax,%edx
cmovs  %esi,%edx
mov    %edx,%ecx
and    $0xfffffff8,%ecx
mov    %eax,%edi
sub    %ecx,%edi
mov    $0x8,%cl
sub    %dil,%cl
mov    $0xff,%edi
shl    %cl,%edi
mov    0x8(%rsp),%rcx
sar    $0x3,%edx
movslq %edx,%rdx
and    %edi,(%rcx,%rdx,4)
lea    0xe(%rax),%edx
test   %esi,%esi
cmovns %esi,%edx
cmp    $0x78,%eax
jg     11e0 <main+0x90>
sar    $0x3,%edx
movslq %edx,%rax
lea    (%rcx,%rax,4),%rdi
cmp    $0x10,%eax
mov    $0xf,%ecx
cmovge %eax,%ecx
sub    %eax,%ecx
lea    0x4(,%rcx,4),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    $0x40,%ecx
call   1030 <inet_ntop@plt>
lea    0xe02(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32* }
@AF_INET6 = global i32 0
@.str = [12 x i8] c"result: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.in6_addr
%7 = alloca [64 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @AF_INET6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @inet_pton(i32 %10, i8* %13, %struct.in6_addr* %6)
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 128
br i1 %20, label %21, label %50
21: ; preds = %2
%22 = load i32, i32* %8
%23 = srem i32 %22, 8
%24 = sub nsw i32 8, %23
%25 = shl i32 255, %24
%26 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %6, i32 0, i32 0
%27 = load i32*, i32** %26
%28 = load i32, i32* %8
%29 = sdiv i32 %28, 8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
%32 = load i32, i32* %31
%33 = and i32 %32, %25
store i32 %33, i32* %31
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 7
%36 = sdiv i32 %35, 8
store i32 %36, i32* %9
br label %37
37: ; preds = %46, %21
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 16
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %6, i32 0, i32 0
%42 = load i32*, i32** %41
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 0, i32* %45
br label %46
46: ; preds = %40
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %37
49: ; preds = %37
br label %50
50: ; preds = %49, %2
%51 = load i32, i32* @AF_INET6
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%53 = call i8* @inet_ntop(i32 %51, %struct.in6_addr* %6, i8* %52, i32 64)
%54 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %53)
ret i32 0
}

LLVM IR (-O2):
%struct.in6_addr = type { i32* }
@AF_INET6 = global i32 0
@.str = [12 x i8] c"result: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in6_addr
%4 = alloca [64 x i8]
%5 = bitcast %struct.in6_addr* %3 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @AF_INET6
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @inet_pton(i32 %7, i8* %9, %struct.in6_addr* %3)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = call i32 @atoi(i8* %12)
%14 = icmp slt i32 %13, 128
br i1 %14, label %15, label %38
15: ; preds = %2
%16 = srem i32 %13, 8
%17 = sub nsw i32 8, %16
%18 = shl nuw nsw i32 255, %17
%19 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %3, i64 0, i32 0
%20 = load i32*, i32** %19
%21 = sdiv i32 %13, 8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = and i32 %24, %18
store i32 %25, i32* %23
%26 = add nsw i32 %13, 7
%27 = sdiv i32 %26, 8
%28 = icmp slt i32 %13, 121
br i1 %28, label %29, label %38
29: ; preds = %15
%30 = sext i32 %27 to i64
%31 = getelementptr i32, i32* %20, i64 %30
%32 = bitcast i32* %31 to i8*
%33 = call i32 @llvm.smax.i32(i32 %27, i32 15)
%34 = sub nsw i32 %33, %27
%35 = zext i32 %34 to i64
%36 = shl nuw nsw i64 %35, 2
%37 = add nuw nsw i64 %36, 4
br label %38
38: ; preds = %29, %15, %2
%39 = load i32, i32* @AF_INET6
%40 = call i8* @inet_ntop(i32 %39, %struct.in6_addr* %3, i8* %6, i32 64)
%41 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %40)
ret i32 0
}