#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 uint;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int andProduct(void) {
  int numTestCases;
  scanf("%d", &numTestCases);
  while (numTestCases--) {
    uint low, high;
    scanf("%u %u", &low, &high);
    uint sharedBits = 0;
    for (uint bitIter = 1 << 31; bitIter > 0; bitIter >>= 1) {
      uint lowBitValue = low & bitIter;
      uint highBitValue = high & bitIter;
      if (lowBitValue != highBitValue) {
        break;
      } else {
        sharedBits |= highBitValue;
      }
    }
    printf("%u\n", sharedBits);
  }
  return 0;
}


x86 assembly (clang, -O0):
<andProduct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     11cf <andProduct+0xaf>
lea    0xeae(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x80000000,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11bb <andProduct+0x9b>
mov    -0x8(%rbp),%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     119f <andProduct+0x7f>
jmp    11bb <andProduct+0x9b>
mov    -0x1c(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11ad <andProduct+0x8d>
mov    -0x14(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <andProduct+0x52>
mov    -0x10(%rbp),%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    113a <andProduct+0x1a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<andProduct>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xece(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0xc(%rsp)
jb     1181 <andProduct+0x61>
lea    0xeb7(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xeac(%rip),%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
jae    1160 <andProduct+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%u %u\00"
@.str.2 = [4 x i8] c"%u\0A\00"
define i32 @andProduct() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
br label %9
9: ; preds = %37, %0
%10 = load i32, i32* %1
%11 = add nsw i32 %10, -1
store i32 %11, i32* %1
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %40
13: ; preds = %9
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
store i32 0, i32* %4
store i32 -2147483648, i32* %5
br label %15
15: ; preds = %34, %13
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %15
%19 = load i32, i32* %2
%20 = load i32, i32* %5
%21 = and i32 %19, %20
store i32 %21, i32* %6
%22 = load i32, i32* %3
%23 = load i32, i32* %5
%24 = and i32 %22, %23
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %18
br label %37
29: ; preds = %18
%30 = load i32, i32* %7
%31 = load i32, i32* %4
%32 = or i32 %31, %30
store i32 %32, i32* %4
br label %33
33: ; preds = %29
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = ashr i32 %35, 1
store i32 %36, i32* %5
br label %15
37: ; preds = %28, %15
%38 = load i32, i32* %4
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %9
40: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%u %u\00"
@.str.2 = [4 x i8] c"%u\0A\00"
define i32 @andProduct() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %18, label %9
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
br label %12
12: ; preds = %9, %12
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%15 = load i32, i32* %1
%16 = add nsw i32 %15, -1
store i32 %16, i32* %1
%17 = icmp eq i32 %15, 0
br i1 %17, label %18, label %12
18: ; preds = %12, %0
ret i32 0
}