#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 in_addr {
  int s_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ inet_pton(int /*<<< orphan*/, char *, struct in_addr *);
int __netif_shares_subnet(char *address, char *netmask, char *dest) {
  struct in_addr src_addr, src_mask, dst_addr;
  if (inet_pton(AF_INET, address, &src_addr) <= 0)
    return -1;
  if (inet_pton(AF_INET, netmask, &src_mask) <= 0)
    return -1;
  if (inet_pton(AF_INET, dest, &dst_addr) <= 0)
    return -1;
  if ((src_addr.s_addr & src_mask.s_addr) ==
      (dst_addr.s_addr & src_mask.s_addr))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<__netif_shares_subnet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <inet_pton@plt>
cmp    $0x0,%rax
jg     1150 <__netif_shares_subnet+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <__netif_shares_subnet+0xbf>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <inet_pton@plt>
cmp    $0x0,%rax
jg     117c <__netif_shares_subnet+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <__netif_shares_subnet+0xbf>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1030 <inet_pton@plt>
cmp    $0x0,%rax
jg     11a8 <__netif_shares_subnet+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <__netif_shares_subnet+0xbf>
mov    -0x28(%rbp),%eax
and    -0x30(%rbp),%eax
mov    -0x38(%rbp),%ecx
and    -0x30(%rbp),%ecx
cmp    %ecx,%eax
jne    11c8 <__netif_shares_subnet+0xb8>
movl   $0x1,-0x4(%rbp)
jmp    11cf <__netif_shares_subnet+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__netif_shares_subnet>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rsi
mov    0x2ebd(%rip),%r12
mov    (%r12),%edi
lea    0x10(%rsp),%rdx
call   1030 <inet_pton@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jle    117d <__netif_shares_subnet+0x6d>
mov    (%r12),%edi
lea    0x8(%rsp),%rdx
mov    %r15,%rsi
call   1030 <inet_pton@plt>
test   %rax,%rax
jle    117d <__netif_shares_subnet+0x6d>
mov    (%r12),%edi
mov    %rsp,%rdx
mov    %r14,%rsi
call   1030 <inet_pton@plt>
test   %rax,%rax
jle    117d <__netif_shares_subnet+0x6d>
mov    (%rsp),%eax
xor    0x10(%rsp),%eax
xor    %ebx,%ebx
test   %eax,0x8(%rsp)
sete   %bl
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
define i32 @__netif_shares_subnet(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.in_addr
%9 = alloca %struct.in_addr
%10 = alloca %struct.in_addr
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i32, i32* @AF_INET
%12 = load i8*, i8** %5
%13 = call i64 @inet_pton(i32 %11, i8* %12, %struct.in_addr* %8)
%14 = icmp sle i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %42
16: ; preds = %3
%17 = load i32, i32* @AF_INET
%18 = load i8*, i8** %6
%19 = call i64 @inet_pton(i32 %17, i8* %18, %struct.in_addr* %9)
%20 = icmp sle i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %4
br label %42
22: ; preds = %16
%23 = load i32, i32* @AF_INET
%24 = load i8*, i8** %7
%25 = call i64 @inet_pton(i32 %23, i8* %24, %struct.in_addr* %10)
%26 = icmp sle i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 -1, i32* %4
br label %42
28: ; preds = %22
%29 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%32 = load i32, i32* %31
%33 = and i32 %30, %32
%34 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i32 0, i32 0
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%37 = load i32, i32* %36
%38 = and i32 %35, %37
%39 = icmp eq i32 %33, %38
br i1 %39, label %40, label %41
40: ; preds = %28
store i32 1, i32* %4
br label %42
41: ; preds = %28
store i32 0, i32* %4
br label %42
42: ; preds = %41, %40, %27, %21, %15
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
define i32 @__netif_shares_subnet(i8* %0, i8* %1, i8* %2) {
%4 = alloca %struct.in_addr
%5 = alloca %struct.in_addr
%6 = alloca %struct.in_addr
%7 = bitcast %struct.in_addr* %4 to i8*
%8 = bitcast %struct.in_addr* %5 to i8*
%9 = bitcast %struct.in_addr* %6 to i8*
%10 = load i32, i32* @AF_INET
%11 = call i64 @inet_pton(i32 %10, i8* %0, %struct.in_addr* %4)
%12 = icmp slt i64 %11, 1
br i1 %12, label %32, label %13
13: ; preds = %3
%14 = load i32, i32* @AF_INET
%15 = call i64 @inet_pton(i32 %14, i8* %1, %struct.in_addr* %5)
%16 = icmp slt i64 %15, 1
br i1 %16, label %32, label %17
17: ; preds = %13
%18 = load i32, i32* @AF_INET
%19 = call i64 @inet_pton(i32 %18, i8* %2, %struct.in_addr* %6)
%20 = icmp slt i64 %19, 1
br i1 %20, label %32, label %21
21: ; preds = %17
%22 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i64 0, i32 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %6, i64 0, i32 0
%27 = load i32, i32* %26
%28 = xor i32 %27, %23
%29 = and i32 %28, %25
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %21, %17, %13, %3
%33 = phi i32 [ -1, %3 ], [ -1, %13 ], [ -1, %17 ], [ %31, %21 ]
ret i32 %33
}