#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 /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ tournament(int, int);
int main() {
  int first = 1;
  while (1) {
    int n;
    scanf("%d", &n);
    if (!n)
      break;
    if (first)
      first = 0;
    else
      printf("\n");
    int k;
    scanf("%d", &k);
    tournament(n, k * n * (n - 1) >> 1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1165 <main+0x35>
jmp    11b7 <main+0x87>
cmpl   $0x0,-0x8(%rbp)
je     117b <main+0x4b>
movl   $0x0,-0x8(%rbp)
jmp    1187 <main+0x57>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
lea    0xe72(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
imul   -0xc(%rbp),%esi
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
imul   %eax,%esi
sar    $0x1,%esi
call   1040 <tournament@plt>
jmp    1146 <main+0x16>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
je     11b1 <main+0x81>
lea    0xea8(%rip),%rbx
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%eax
imul   %edi,%eax
lea    -0x1(%rdi),%esi
imul   %eax,%esi
sar    %esi
call   1040 <tournament@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
je     11b1 <main+0x81>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1170 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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