#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*/ Nimsum(long, long, long);
int /*<<< orphan*/ printf(char *, long, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int p, i;
  scanf("%d", &p);
  for (i = 0; i < p; i++) {
    long n, B, x, y;
    scanf("%ld%ld%ld%ld", &n, &B, &x, &y);
    printf("%ld %ld \n", n, Nimsum(B, x, y));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11bb <main+0x8b>
lea    0xe98(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%r8
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <Nimsum@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1158 <main+0x28>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xebb(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11cd <main+0x9d>
lea    0x18(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rbx
lea    0xea2(%rip),%rbp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe7c(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x20(%rsp),%r14
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
call   1030 <Nimsum@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
add    $0x1,%r15d
cmp    0x4(%rsp),%r15d
jl     1180 <main+0x50>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"%ld%ld%ld%ld\00"
@.str.2 = [10 x i8] c"%ld %ld \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = 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 %9
9: ; preds = %21, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64* %4, i64* %5, i64* %6, i64* %7)
%15 = load i64, i64* %4
%16 = load i64, i64* %5
%17 = load i64, i64* %6
%18 = load i64, i64* %7
%19 = call i32 @Nimsum(i64 %16, i64 %17, i64 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %15, i32 %19)
br label %21
21: ; preds = %13
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %9
24: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"%ld%ld%ld%ld\00"
@.str.2 = [10 x i8] c"%ld %ld \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i32* %1 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %0
%11 = bitcast i64* %2 to i8*
%12 = bitcast i64* %3 to i8*
%13 = bitcast i64* %4 to i8*
%14 = bitcast i64* %5 to i8*
br label %15
15: ; preds = %10, %15
%16 = phi i32 [ 0, %10 ], [ %24, %15 ]
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64* %2, i64* %3, i64* %4, i64* %5)
%18 = load i64, i64* %2
%19 = load i64, i64* %3
%20 = load i64, i64* %4
%21 = load i64, i64* %5
%22 = call i32 @Nimsum(i64 %19, i64 %20, i64 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %18, i32 %22)
%24 = add nuw nsw i32 %16, 1
%25 = load i32, i32* %1
%26 = icmp slt i32 %24, %25
br i1 %26, label %15, label %27
27: ; preds = %15, %0
ret i32 0
}