#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 __builtin_ffs(int);
int deduce(char *, char *, char *);
int /*<<< orphan*/ printf(char *, char, char *);
int scanf(char *, ...);
int main() {
  int n = 0;
  if (1 != scanf("%d", &n))
    return 0;
  int guesses;
  int counterfeit;
  int heavy;
  char left[8];
  char right[8];
  char rtilt[8];
  for (int i = 0; i < n; i++) {
    guesses = -1;
    for (int j = 0; j < 3; j++) {
      if (3 != scanf("%s %s %s", left, right, rtilt))
        return 0;
      guesses &= deduce(rtilt, left, right);
    }
    counterfeit = __builtin_ffs(guesses);
    heavy = counterfeit > sizeof(int) * 4;
    printf("%c is the counterfeit coin and it is %s.\n",
           'A' - 1 + (heavy ? counterfeit - sizeof(int) * 4 : counterfeit),
           heavy ? "heavy" : "light");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1173 <main+0x43>
movl   $0x0,-0x4(%rbp)
jmp    1286 <main+0x156>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127f <main+0x14f>
movl   $0xffffffff,-0xc(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x34(%rbp)
jge    11f8 <main+0xc8>
lea    -0x1c(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    %eax,%ecx
mov    $0x3,%eax
cmp    %ecx,%eax
je     11d3 <main+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    1286 <main+0x156>
lea    -0x2c(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <deduce@plt>
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1194 <main+0x64>
mov    -0xc(%rbp),%edx
bsf    %edx,%eax
add    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    $0x10,%rax
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     123a <main+0x10a>
movslq -0x10(%rbp),%rax
sub    $0x10,%rax
mov    %rax,-0x40(%rbp)
jmp    1242 <main+0x112>
movslq -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x40,%rax
mov    -0x14(%rbp),%esi
lea    0xde8(%rip),%rdx
lea    0xddb(%rip),%rcx
cmp    $0x0,%esi
cmovne %rcx,%rdx
lea    0xda3(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    117a <main+0x4a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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
movl   $0x0,0xc(%rsp)
lea    0xeb3(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    125e <main+0x12e>
cmpl   $0x0,0xc(%rsp)
jle    125e <main+0x12e>
lea    0x20(%rsp),%r15
lea    0x18(%rsp),%r12
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
nop
lea    0xe7c(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    125e <main+0x12e>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <deduce@plt>
mov    %eax,%ebp
lea    0xe4c(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    125e <main+0x12e>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <deduce@plt>
mov    %eax,%r13d
lea    0xe1b(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x3,%eax
jne    125e <main+0x12e>
and    %ebp,%r13d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <deduce@plt>
and    %r13d,%eax
bsf    %eax,%eax
mov    $0xffffffff,%ecx
cmove  %ecx,%eax
add    $0x1,%eax
lea    -0x10(%rax),%ecx
cmp    $0x11,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
lea    0xe0a(%rip),%rdx
lea    0xdfd(%rip),%rax
cmovae %rax,%rdx
add    $0x40,%cl
movsbl %cl,%esi
lea    0xdc2(%rip),%rdi
call   1030 <printf@plt>
add    $0x1,%r14d
cmp    0xc(%rsp),%r14d
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 = [9 x i8] c"%s %s %s\00"
@.str.2 = [42 x i8] c"%c is the counterfeit coin and it is %s.\0A\00"
@.str.3 = [6 x i8] c"heavy\00"
@.str.4 = [6 x i8] c"light\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x i8]
%7 = alloca [8 x i8]
%8 = alloca [8 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%12 = icmp ne i32 1, %11
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 0, i32* %1
br label %72
14: ; preds = %0
store i32 0, i32* %9
br label %15
15: ; preds = %68, %14
%16 = load i32, i32* %9
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %71
19: ; preds = %15
store i32 -1, i32* %3
store i32 0, i32* %10
br label %20
20: ; preds = %37, %19
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %25, i8* %26)
%28 = icmp ne i32 3, %27
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 0, i32* %1
br label %72
30: ; preds = %23
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%34 = call i32 @deduce(i8* %31, i8* %32, i8* %33)
%35 = load i32, i32* %3
%36 = and i32 %35, %34
store i32 %36, i32* %3
br label %37
37: ; preds = %30
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %20
40: ; preds = %20
%41 = load i32, i32* %3
%42 = call i32 @llvm.cttz.i32(i32 %41, i1 true)
%43 = add i32 %42, 1
%44 = icmp eq i32 %41, 0
%45 = select i1 %44, i32 0, i32 %43
store i32 %45, i32* %4
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = icmp ugt i64 %47, 16
%49 = zext i1 %48 to i32
store i32 %49, i32* %5
%50 = load i32, i32* %5
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %40
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = sub i64 %54, 16
br label %59
56: ; preds = %40
%57 = load i32, i32* %4
%58 = sext i32 %57 to i64
br label %59
59: ; preds = %56, %52
%60 = phi i64 [ %55, %52 ], [ %58, %56 ]
%61 = add i64 64, %60
%62 = trunc i64 %61 to i8
%63 = load i32, i32* %5
%64 = icmp ne i32 %63, 0
%65 = zext i1 %64 to i64
%66 = select i1 %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%67 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8 signext %62, i8* %66)
br label %68
68: ; preds = %59
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %15
71: ; preds = %15
store i32 0, i32* %1
br label %72
72: ; preds = %71, %29, %13
%73 = load i32, i32* %1
ret i32 %73
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%s %s %s\00"
@.str.2 = [42 x i8] c"%c is the counterfeit coin and it is %s.\0A\00"
@.str.3 = [6 x i8] c"heavy\00"
@.str.4 = [6 x i8] c"light\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [8 x i8]
%4 = alloca [8 x i8]
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %46
8: ; preds = %0
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %8, %26
%15 = phi i32 [ %42, %26 ], [ 0, %8 ]
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10, i8* %11)
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %45
18: ; preds = %14
%19 = call i32 @deduce(i8* %11, i8* %9, i8* %10)
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10, i8* %11)
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = call i32 @deduce(i8* %11, i8* %9, i8* %10)
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10, i8* %11)
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %45
26: ; preds = %22
%27 = and i32 %23, %19
%28 = call i32 @deduce(i8* %11, i8* %9, i8* %10)
%29 = and i32 %28, %27
%30 = call i32 @llvm.cttz.i32(i32 %29, i1 true)
%31 = add nuw nsw i32 %30, 1
%32 = icmp eq i32 %29, 0
%33 = select i1 %32, i32 0, i32 %31
%34 = zext i32 %33 to i64
%35 = icmp ugt i32 %33, 16
%36 = add nuw nsw i64 %34, 240
%37 = select i1 %35, i64 %36, i64 %34
%38 = trunc i64 %37 to i8
%39 = add i8 %38, 64
%40 = select i1 %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%41 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8 signext %39, i8* %40)
%42 = add nuw nsw i32 %15, 1
%43 = load i32, i32* %1
%44 = icmp slt i32 %42, %43
br i1 %44, label %14, label %45
45: ; preds = %26, %14, %18, %22, %8
br label %46
46: ; preds = %0, %45
ret i32 0
}