#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__ utilIpCmp(unsigned char *, unsigned char *);
int /*<<< orphan*/ utilIpSubnetAddr(unsigned char *, unsigned char *,
                                    unsigned char *);
int /*<<< orphan*/ utilIpSubnetBcAddr(unsigned char *, unsigned char *,
                                      unsigned char *);
long utilIpIsSameSubnetAddr(unsigned char *byIp1, unsigned char *bySubmask1,
                            unsigned char *byIp2, unsigned char *bySubmask2) {
  unsigned char bySubAddr1[4];
  unsigned char bySubAddr2[4];
  unsigned char bySubBc1[4];
  unsigned char bySubBc2[4];
  if (byIp1 == (0) || bySubmask1 == (0) || byIp2 == (0) || bySubmask2 == (0))
    return (-1);
  if (utilIpCmp(bySubmask1, bySubmask2) != 0)
    return (0);
  utilIpSubnetAddr(byIp1, bySubmask1, bySubAddr1);
  utilIpSubnetAddr(byIp2, bySubmask2, bySubAddr2);
  utilIpSubnetBcAddr(byIp1, bySubmask1, bySubBc1);
  utilIpSubnetBcAddr(byIp2, bySubmask2, bySubBc2);
  if (utilIpCmp(bySubAddr1, bySubAddr2) == 0 &&
      utilIpCmp(bySubBc1, bySubBc2) == 0) {
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<utilIpIsSameSubnetAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1174 <utilIpIsSameSubnetAddr+0x44>
cmpq   $0x0,-0x18(%rbp)
je     1174 <utilIpIsSameSubnetAddr+0x44>
cmpq   $0x0,-0x20(%rbp)
je     1174 <utilIpIsSameSubnetAddr+0x44>
cmpq   $0x0,-0x28(%rbp)
jne    1181 <utilIpIsSameSubnetAddr+0x51>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    122c <utilIpIsSameSubnetAddr+0xfc>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <utilIpCmp@plt>
cmp    $0x0,%rax
je     11a5 <utilIpIsSameSubnetAddr+0x75>
movq   $0x0,-0x8(%rbp)
jmp    122c <utilIpIsSameSubnetAddr+0xfc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <utilIpSubnetAddr@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <utilIpSubnetAddr@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <utilIpSubnetBcAddr@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <utilIpSubnetBcAddr@plt>
lea    -0x2c(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <utilIpCmp@plt>
cmp    $0x0,%rax
jne    1224 <utilIpIsSameSubnetAddr+0xf4>
lea    -0x34(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <utilIpCmp@plt>
cmp    $0x0,%rax
jne    1224 <utilIpIsSameSubnetAddr+0xf4>
movq   $0x1,-0x8(%rbp)
jmp    122c <utilIpIsSameSubnetAddr+0xfc>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilIpIsSameSubnetAddr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffffffffffff,%rax
test   %rdi,%rdi
je     11ed <utilIpIsSameSubnetAddr+0xbd>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11ed <utilIpIsSameSubnetAddr+0xbd>
mov    %rdx,%r14
test   %rdx,%rdx
je     11ed <utilIpIsSameSubnetAddr+0xbd>
mov    %rcx,%r15
test   %rcx,%rcx
je     11ed <utilIpIsSameSubnetAddr+0xbd>
mov    %rdi,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <utilIpCmp@plt>
test   %rax,%rax
jne    11eb <utilIpIsSameSubnetAddr+0xbb>
lea    0x14(%rsp),%r13
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1040 <utilIpSubnetAddr@plt>
lea    0x10(%rsp),%rbp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <utilIpSubnetAddr@plt>
lea    0xc(%rsp),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <utilIpSubnetBcAddr@plt>
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <utilIpSubnetBcAddr@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <utilIpCmp@plt>
test   %rax,%rax
jne    11eb <utilIpIsSameSubnetAddr+0xbb>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <utilIpCmp@plt>
test   %rax,%rax
je     11fc <utilIpIsSameSubnetAddr+0xcc>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%eax
jmp    11ed <utilIpIsSameSubnetAddr+0xbd>

LLVM IR (-O0):
define i64 @utilIpIsSameSubnetAddr(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [4 x i8]
%11 = alloca [4 x i8]
%12 = alloca [4 x i8]
%13 = alloca [4 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %25, label %16
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i8*, i8** %9
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %22, %19, %16, %4
store i64 -1, i64* %5
br label %60
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = load i8*, i8** %9
%29 = call i64 @utilIpCmp(i8* %27, i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i64 0, i64* %5
br label %60
32: ; preds = %26
%33 = load i8*, i8** %6
%34 = load i8*, i8** %7
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%36 = call i32 @utilIpSubnetAddr(i8* %33, i8* %34, i8* %35)
%37 = load i8*, i8** %8
%38 = load i8*, i8** %9
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%40 = call i32 @utilIpSubnetAddr(i8* %37, i8* %38, i8* %39)
%41 = load i8*, i8** %6
%42 = load i8*, i8** %7
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%44 = call i32 @utilIpSubnetBcAddr(i8* %41, i8* %42, i8* %43)
%45 = load i8*, i8** %8
%46 = load i8*, i8** %9
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%48 = call i32 @utilIpSubnetBcAddr(i8* %45, i8* %46, i8* %47)
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%50 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%51 = call i64 @utilIpCmp(i8* %49, i8* %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %32
%54 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %13, i64 0, i64 0
%56 = call i64 @utilIpCmp(i8* %54, i8* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %53
store i64 1, i64* %5
br label %60
59: ; preds = %53, %32
store i64 0, i64* %5
br label %60
60: ; preds = %59, %58, %31, %25
%61 = load i64, i64* %5
ret i64 %61
}

LLVM IR (-O2):
define i64 @utilIpIsSameSubnetAddr(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [4 x i8]
%6 = alloca [4 x i8]
%7 = alloca [4 x i8]
%8 = alloca [4 x i8]
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%13 = icmp eq i8* %0, null
%14 = icmp eq i8* %1, null
%15 = or i1 %13, %14
%16 = icmp eq i8* %2, null
%17 = or i1 %15, %16
%18 = icmp eq i8* %3, null
%19 = or i1 %17, %18
br i1 %19, label %34, label %20
20: ; preds = %4
%21 = tail call i64 @utilIpCmp(i8* %1, i8* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %20
%24 = call i32 @utilIpSubnetAddr(i8* %0, i8* %1, i8* %9)
%25 = call i32 @utilIpSubnetAddr(i8* %2, i8* %3, i8* %10)
%26 = call i32 @utilIpSubnetBcAddr(i8* %0, i8* %1, i8* %11)
%27 = call i32 @utilIpSubnetBcAddr(i8* %2, i8* %3, i8* %12)
%28 = call i64 @utilIpCmp(i8* %9, i8* %10)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = call i64 @utilIpCmp(i8* %11, i8* %12)
%32 = icmp eq i64 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %30, %23
br label %34
34: ; preds = %30, %20, %4, %33
%35 = phi i64 [ 0, %33 ], [ -1, %4 ], [ 0, %20 ], [ 1, %30 ]
ret i64 %35
}