#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 */
typedef int in_addr_t;

/* Variables and functions */
in_addr_t IP2Broadcast(in_addr_t IP, in_addr_t Mask) {
  in_addr_t bcIP;
  in_addr_t bit;
  in_addr_t notbit;
  int i;
  bit = 0x80000000;
  notbit = 0xFFFFFFFF;
  bcIP = 0;
  for (i = 0; i < 31; i++) {
    if ((bit & Mask) == 0)
      break;
    bcIP |= (IP & bit);
    notbit &= ~bit;
    bit = bit >> 1;
  }
  return bcIP;
}


x86 assembly (clang, -O0):
<IP2Broadcast>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x80000000,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1f,-0x18(%rbp)
jge    1173 <IP2Broadcast+0x73>
mov    -0x10(%rbp),%eax
and    -0x8(%rbp),%eax
cmp    $0x0,%eax
jne    1144 <IP2Broadcast+0x44>
jmp    1173 <IP2Broadcast+0x73>
mov    -0x4(%rbp),%eax
and    -0x10(%rbp),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1126 <IP2Broadcast+0x26>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<IP2Broadcast>:
xor    %eax,%eax
test   %esi,%esi
jns    112c <IP2Broadcast+0x2c>
mov    $0x80000000,%edx
xor    %r9d,%r9d
xor    %eax,%eax
mov    %eax,%r8d
mov    %edx,%eax
and    %edi,%eax
or     %r8d,%eax
cmp    $0x1d,%r9d
ja     112c <IP2Broadcast+0x2c>
sar    %edx
add    $0x1,%r9d
mov    %edx,%ecx
and    %esi,%ecx
jne    1110 <IP2Broadcast+0x10>
ret

LLVM IR (-O0):
define i32 @IP2Broadcast(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 -2147483648, i32* %6
store i32 -1, i32* %7
store i32 0, i32* %5
store i32 0, i32* %8
br label %9
9: ; preds = %30, %2
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 31
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = and i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %33
18: ; preds = %12
%19 = load i32, i32* %3
%20 = load i32, i32* %6
%21 = and i32 %19, %20
%22 = load i32, i32* %5
%23 = or i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %6
%25 = xor i32 %24, -1
%26 = load i32, i32* %7
%27 = and i32 %26, %25
store i32 %27, i32* %7
%28 = load i32, i32* %6
%29 = ashr i32 %28, 1
store i32 %29, i32* %6
br label %30
30: ; preds = %18
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %9
33: ; preds = %17, %9
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
define i32 @IP2Broadcast(i32 %0, i32 %1) {
%3 = icmp sgt i32 %1, -1
br i1 %3, label %16, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %11, %4 ], [ 0, %2 ]
%6 = phi i32 [ %10, %4 ], [ -2147483648, %2 ]
%7 = phi i32 [ %9, %4 ], [ 0, %2 ]
%8 = and i32 %6, %0
%9 = or i32 %8, %7
%10 = ashr i32 %6, 1
%11 = add nuw nsw i32 %5, 1
%12 = icmp ugt i32 %5, 29
%13 = and i32 %10, %1
%14 = icmp eq i32 %13, 0
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %16, label %4
16: ; preds = %4, %2
%17 = phi i32 [ 0, %2 ], [ %9, %4 ]
ret i32 %17
}