#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 msk_calc(unsigned char, int, unsigned char *);
int subnet_calc_with_msk(unsigned char *, unsigned char *, int,
                         unsigned char *);
int subnet_calc_with_prefix(unsigned char *address, unsigned char prefix,
                            int is_ipv6, unsigned char *res) {
  unsigned char msk[16];
  int rs = msk_calc(prefix, is_ipv6, msk);
  if (rs < 0)
    return -1;
  return subnet_calc_with_msk(address, msk, is_ipv6, res);
}


x86 assembly (clang, -O0):
<subnet_calc_with_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x11(%rbp),%al
mov    -0x18(%rbp),%esi
lea    -0x30(%rbp),%rdx
movzbl %al,%edi
call   1040 <msk_calc@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1164 <subnet_calc_with_prefix+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    117b <subnet_calc_with_prefix+0x5b>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <subnet_calc_with_msk@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subnet_calc_with_prefix>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rdi,%rbx
mov    %rsp,%rdx
mov    %esi,%edi
mov    %ebp,%esi
call   1040 <msk_calc@plt>
test   %eax,%eax
js     1152 <subnet_calc_with_prefix+0x32>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
mov    %r14,%rcx
call   1030 <subnet_calc_with_msk@plt>
jmp    1157 <subnet_calc_with_prefix+0x37>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @subnet_calc_with_prefix(i8* %0, i8 zeroext %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [16 x i8]
%11 = alloca i32
store i8* %0, i8** %6
store i8 %1, i8* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%12 = load i8, i8* %7
%13 = load i32, i32* %8
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%15 = call i32 @msk_calc(i8 zeroext %12, i32 %13, i8* %14)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 -1, i32* %5
br label %25
19: ; preds = %4
%20 = load i8*, i8** %6
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%22 = load i32, i32* %8
%23 = load i8*, i8** %9
%24 = call i32 @subnet_calc_with_msk(i8* %20, i8* %21, i32 %22, i8* %23)
store i32 %24, i32* %5
br label %25
25: ; preds = %19, %18
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
define i32 @subnet_calc_with_prefix(i8* %0, i8 zeroext %1, i32 %2, i8* %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = call i32 @msk_calc(i8 zeroext %1, i32 %2, i8* %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 @subnet_calc_with_msk(i8* %0, i8* %6, i32 %2, i8* %3)
br label %11
11: ; preds = %4, %9
%12 = phi i32 [ %10, %9 ], [ -1, %4 ]
ret i32 %12
}