#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, char);
scalar_t__ scanf(char *, char *, char *);
int main(void) {
  char t1, t2, ball = 'A';
  while (scanf("%c,%c\n", &t1, &t2) != EOF) {
    if (ball == t1) {
      ball = t2;
    } else if (ball == t2) {
      ball = t1;
    }
  }
  printf("%c\n", ball);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x41,-0x7(%rbp)
lea    0xec6(%rip),%rdi
lea    -0x5(%rbp),%rsi
lea    -0x6(%rbp),%rdx
call   1040 <scanf@plt>
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
je     1192 <main+0x72>
movsbl -0x7(%rbp),%eax
movsbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
jne    1172 <main+0x52>
mov    -0x6(%rbp),%al
mov    %al,-0x7(%rbp)
jmp    118d <main+0x6d>
movsbl -0x7(%rbp),%eax
movsbl -0x6(%rbp),%ecx
cmp    %ecx,%eax
jne    1188 <main+0x68>
mov    -0x5(%rbp),%al
mov    %al,-0x7(%rbp)
jmp    118d <main+0x6d>
jmp    1133 <main+0x13>
lea    0xe6a(%rip),%rdi
movsbl -0x7(%rbp),%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecd(%rip),%rdi
lea    0xf(%rsp),%rsi
lea    0xe(%rsp),%rdx
call   1040 <scanf@plt>
mov    0x2e9f(%rip),%r12
mov    $0x41,%bpl
cmp    (%r12),%rax
je     119f <main+0x7f>
mov    $0x41,%bpl
lea    0xea4(%rip),%r14
lea    0xf(%rsp),%r15
lea    0xe(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl 0xf(%rsp),%eax
movzbl 0xe(%rsp),%ecx
cmp    %cl,%bpl
movzbl %bpl,%edx
mov    %eax,%ebp
cmovne %edx,%ebp
cmp    %al,%dl
cmove  %ecx,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <scanf@plt>
cmp    (%r12),%rax
jne    1170 <main+0x50>
movsbl %bpl,%esi
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%c,%c\0A\00"
@EOF = global i64 0
@.str.1 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = call i64 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%4 = load i64, i64* @EOF
%5 = icmp eq i64 %3, %4
br i1 %5, label %17, label %6
6: ; preds = %0, %6
%7 = phi i8 [ %13, %6 ], [ 65, %0 ]
%8 = load i8, i8* %1
%9 = icmp eq i8 %7, %8
%10 = load i8, i8* %2
%11 = icmp eq i8 %7, %10
%12 = select i1 %11, i8 %8, i8 %7
%13 = select i1 %9, i8 %10, i8 %12
%14 = call i64 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %6
17: ; preds = %6, %0
%18 = phi i8 [ 65, %0 ], [ %13, %6 ]
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %18)
ret i32 0
}