#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 */
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ subnet_calc_with_prefix(unsigned char *, unsigned char, int,
                                           unsigned char *);
int is_same_subnet(unsigned char *address, unsigned char *subnet,
                   unsigned char prefix, int is_ipv6) {
  unsigned char tmp_addr[16];
  int size = is_ipv6 ? 16 : 4;
  subnet_calc_with_prefix(address, prefix, is_ipv6, tmp_addr);
  if (memcmp(tmp_addr, subnet, size))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_same_subnet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x20(%rbp),%edx
mov    $0x4,%eax
mov    $0x10,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x19(%rbp),%al
mov    -0x20(%rbp),%edx
lea    -0x30(%rbp),%rcx
movzbl %al,%esi
call   1040 <subnet_calc_with_prefix@plt>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     118a <is_same_subnet+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    1191 <is_same_subnet+0x71>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_same_subnet>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
test   %ecx,%ecx
mov    $0x4,%eax
mov    $0x10,%ebp
cmove  %eax,%ebp
mov    %rsp,%r14
mov    %edx,%esi
mov    %ecx,%edx
mov    %r14,%rcx
call   1040 <subnet_calc_with_prefix@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @is_same_subnet(i8* %0, i8* %1, i8 zeroext %2, i32 %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32 %3, 0
%8 = select i1 %7, i32 4, i32 16
%9 = call i32 @subnet_calc_with_prefix(i8* %0, i8 zeroext %2, i32 %3, i8* %6)
%10 = call i64 @memcmp(i8* %6, i8* %1, i32 %8)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
ret i32 %12
}