#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*/ convertDecToBin(int, char *);
int convertHexToDec(char *);
int /*<<< orphan*/ printf(char *, char *, char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  int T, decimalOne, decimalTwo;
  char hexOne[13 + 1], hexTwo[13 + 1], binaryOne[13 + 1],
      binaryTwo[13 + 1], operator[13 + 1];
  scanf("%d", &T);
  while (T) {
    scanf("%s %s %s", hexOne, operator, hexTwo);
    decimalOne = convertHexToDec(hexOne);
    decimalTwo = convertHexToDec(hexTwo);
    convertDecToBin(decimalOne, binaryOne);
    convertDecToBin(decimalTwo, binaryTwo);
    if (operator[0] == '+')
      printf("%s + %s = %d\n", binaryOne, binaryTwo, decimalOne + decimalTwo);
    else
      printf("%s - %s = %d\n", binaryOne, binaryTwo, decimalOne - decimalTwo);
    T--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1209 <main+0xc9>
lea    -0x1e(%rbp),%rsi
lea    -0x56(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x1e(%rbp),%rdi
call   1050 <convertHexToDec@plt>
mov    %eax,-0xc(%rbp)
lea    -0x2c(%rbp),%rdi
call   1050 <convertHexToDec@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x3a(%rbp),%rsi
call   1040 <convertDecToBin@plt>
mov    -0x10(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   1040 <convertDecToBin@plt>
movsbl -0x56(%rbp),%eax
cmp    $0x2b,%eax
jne    11e1 <main+0xa1>
lea    -0x3a(%rbp),%rsi
lea    -0x48(%rbp),%rdx
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
jmp    11fb <main+0xbb>
lea    -0x3a(%rbp),%rsi
lea    -0x48(%rbp),%rdx
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1161 <main+0x21>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xeab(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
je     1210 <main+0xd0>
lea    0x4a(%rsp),%r12
lea    0x3c(%rsp),%r13
lea    0x2e(%rsp),%rbx
lea    0x20(%rsp),%rbp
jmp    11af <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
sub    %r15d,%r14d
lea    0xe80(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1030 <printf@plt>
addl   $0xffffffff,0xc(%rsp)
je     1210 <main+0xd0>
lea    0xe4d(%rip),%rdi
mov    %r12,%rsi
lea    0x12(%rsp),%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r12,%rdi
call   1050 <convertHexToDec@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1050 <convertHexToDec@plt>
mov    %eax,%r15d
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <convertDecToBin@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1040 <convertDecToBin@plt>
cmpb   $0x2b,0x12(%rsp)
jne    1190 <main+0x50>
add    %r14d,%r15d
lea    0xe07(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r15d,%ecx
jmp    11a3 <main+0x63>
xor    %eax,%eax
add    $0x58,%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 = [14 x i8] c"%s + %s = %d\0A\00"
@.str.3 = [14 x i8] c"%s - %s = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [14 x i8]
%6 = alloca [14 x i8]
%7 = alloca [14 x i8]
%8 = alloca [14 x i8]
%9 = alloca [14 x i8]
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %11
11: ; preds = %47, %0
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %50
14: ; preds = %11
%15 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%17 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16, i8* %17)
%19 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%20 = call i32 @convertHexToDec(i8* %19)
store i32 %20, i32* %3
%21 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%22 = call i32 @convertHexToDec(i8* %21)
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%25 = call i32 @convertDecToBin(i32 %23, i8* %24)
%26 = load i32, i32* %4
%27 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%28 = call i32 @convertDecToBin(i32 %26, i8* %27)
%29 = getelementptr inbounds [14 x i8], [14 x i8]* %9, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 43
br i1 %32, label %33, label %40
33: ; preds = %14
%34 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = add nsw i32 %36, %37
%39 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %34, i8* %35, i32 %38)
br label %47
40: ; preds = %14
%41 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%42 = getelementptr inbounds [14 x i8], [14 x i8]* %8, i64 0, i64 0
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = sub nsw i32 %43, %44
%46 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %41, i8* %42, i32 %45)
br label %47
47: ; preds = %40, %33
%48 = load i32, i32* %2
%49 = add nsw i32 %48, -1
store i32 %49, i32* %2
br label %11
50: ; preds = %11
ret i32 0
}

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