#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 */
int /*<<< orphan*/ printf(char *, int, unsigned long long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int cases;
  scanf("%d", &cases);
  int cn = 0;
  while (cn++ < cases) {
    unsigned long long strength, size;
    scanf("%llu %llu", &strength, &size);
    unsigned long long result = 0;
    while (strength > 0) {
      if (strength % 2 == 1) {
        result += size;
      }
      strength /= 2;
      size *= 2;
    }
    printf("Situation #%d: %llu\n", cn, result);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    -0x8(%rbp),%eax
jge    11d8 <main+0xb8>
lea    0xea0(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11c0 <main+0xa0>
mov    -0x18(%rbp),%rax
and    $0x1,%rax
cmp    $0x1,%rax
jne    11a3 <main+0x83>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117a <main+0x5a>
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
jmp    1148 <main+0x28>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xecc(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11d9 <main+0xb9>
mov    $0x1,%ebx
lea    0xeac(%rip),%r14
lea    0x18(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xea5(%rip),%r13
jmp    1187 <main+0x67>
nopw   0x0(%rax,%rax,1)
xor    %edx,%edx
mov    %r13,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
lea    0x1(%rbx),%eax
cmp    0xc(%rsp),%ebx
mov    %eax,%ebx
jge    11d9 <main+0xb9>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x18(%rsp),%rax
test   %rax,%rax
je     1170 <main+0x50>
mov    0x10(%rsp),%rcx
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
mov    %rax,%rsi
mov    %esi,%edi
and    $0x1,%edi
neg    %rdi
and    %rcx,%rdi
add    %rdi,%rdx
shr    %rax
add    %rcx,%rcx
cmp    $0x1,%rsi
ja     11b0 <main+0x90>
mov    %rax,0x18(%rsp)
mov    %rcx,0x10(%rsp)
jmp    1172 <main+0x52>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"%llu %llu\00"
@.str.2 = [21 x i8] c"Situation #%d: %llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %8
8: ; preds = %31, %0
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %35
13: ; preds = %8
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %4, i64* %5)
store i64 0, i64* %6
br label %15
15: ; preds = %26, %13
%16 = load i64, i64* %4
%17 = icmp ugt i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = load i64, i64* %4
%20 = urem i64 %19, 2
%21 = icmp eq i64 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i64, i64* %5
%24 = load i64, i64* %6
%25 = add i64 %24, %23
store i64 %25, i64* %6
br label %26
26: ; preds = %22, %18
%27 = load i64, i64* %4
%28 = udiv i64 %27, 2
store i64 %28, i64* %4
%29 = load i64, i64* %5
%30 = mul i64 %29, 2
store i64 %30, i64* %5
br label %15
31: ; preds = %15
%32 = load i32, i32* %3
%33 = load i64, i64* %6
%34 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %32, i64 %33)
br label %8
35: ; preds = %8
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"%llu %llu\00"
@.str.2 = [21 x i8] c"Situation #%d: %llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i32* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %36
8: ; preds = %0
%9 = bitcast i64* %2 to i8*
%10 = bitcast i64* %3 to i8*
br label %11
11: ; preds = %8, %30
%12 = phi i32 [ 1, %8 ], [ %33, %30 ]
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64* %2, i64* %3)
%14 = load i64, i64* %2
%15 = icmp eq i64 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %11
%17 = load i64, i64* %3
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ %25, %18 ], [ 0, %16 ]
%20 = phi i64 [ %26, %18 ], [ %14, %16 ]
%21 = phi i64 [ %27, %18 ], [ %17, %16 ]
%22 = and i64 %20, 1
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i64 0, i64 %21
%25 = add i64 %24, %19
%26 = lshr i64 %20, 1
%27 = shl i64 %21, 1
%28 = icmp ult i64 %20, 2
br i1 %28, label %29, label %18
29: ; preds = %18
store i64 %26, i64* %2
store i64 %27, i64* %3
br label %30
30: ; preds = %29, %11
%31 = phi i64 [ %25, %29 ], [ 0, %11 ]
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %12, i64 %31)
%33 = add nuw nsw i32 %12, 1
%34 = load i32, i32* %1
%35 = icmp slt i32 %12, %34
br i1 %35, label %11, label %36
36: ; preds = %30, %0
ret i32 0
}