#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*/ display_binary(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
void main() {
  int Hex1, Hex2, T, i, res_op;
  char Operator;
  scanf("%d", &T);
  for (i = 0; i < T; i++) {
    scanf("%X %c %X", &Hex1, &Operator, &Hex2);
    if (Operator == '+')
      res_op = Hex1 + Hex2;
    else
      res_op = Hex1 - Hex2;
    display_binary(Hex1);
    printf(" %c ", Operator);
    display_binary(Hex2);
    printf(" = %d\n", res_op);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d8 <main+0xa8>
lea    0xe9f(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x15(%rbp),%rdx
lea    -0x8(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x2b,%eax
jne    1192 <main+0x62>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    119b <main+0x6b>
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <display_binary@plt>
movsbl -0x15(%rbp),%esi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <display_binary@plt>
mov    -0x14(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1151 <main+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xebb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11e4 <main+0xb4>
lea    0xb(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xe9f(%rip),%rbx
lea    0xe9d(%rip),%rbp
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
lea    0xe7c(%rip),%rdi
lea    0x14(%rsp),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%eax
mov    %eax,%r14d
neg    %r14d
cmpb   $0x2b,0xb(%rsp)
mov    0x14(%rsp),%edi
cmove  %eax,%r14d
add    %edi,%r14d
call   1050 <display_binary@plt>
movsbl 0xb(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%edi
call   1050 <display_binary@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
add    $0x1,%r15d
cmp    0xc(%rsp),%r15d
jl     1180 <main+0x50>
add    $0x18,%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"%X %c %X\00"
@.str.2 = [5 x i8] c" %c \00"
@.str.3 = [7 x i8] c" = %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %4
br label %8
8: ; preds = %35, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %38
12: ; preds = %8
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i8* %6, i32* %2)
%14 = load i8, i8* %6
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 43
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = add nsw i32 %18, %19
store i32 %20, i32* %5
br label %25
21: ; preds = %12
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %5
br label %25
25: ; preds = %21, %17
%26 = load i32, i32* %1
%27 = call i32 @display_binary(i32 %26)
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %2
%32 = call i32 @display_binary(i32 %31)
%33 = load i32, i32* %5
%34 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %25
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %8
38: ; preds = %8
ret void
}

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