#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*/ print_bits(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int num_cases;
  int op1, op2;
  char oper;
  int result;
  scanf("%d\n", &num_cases);
  while (num_cases-- > 0) {
    scanf("%x %c %x\n", &op1, &oper, &op2);
    result = (oper == '+') ? op1 + op2 : op1 - op2;
    print_bits(op1, 13);
    printf(" %c ", oper);
    print_bits(op2, 13);
    printf(" = %d\n", result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecc(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    11e7 <main+0xb7>
lea    0xe94(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x11(%rbp),%rdx
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x2b,%eax
jne    119a <main+0x6a>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11a3 <main+0x73>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    $0xd,%esi
call   1040 <print_bits@plt>
movsbl -0x11(%rbp),%esi
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%edi
mov    $0xd,%esi
call   1040 <print_bits@plt>
mov    -0x18(%rbp),%esi
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
jmp    1151 <main+0x21>
xor    %eax,%eax
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    0xecd(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    1200 <main+0xd0>
lea    0x14(%rsp),%r15
lea    0xb(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xe90(%rip),%rbx
lea    0xe8e(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe69(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1050 <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
mov    $0xd,%esi
call   1040 <print_bits@plt>
movsbl 0xb(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0x10(%rsp),%edi
mov    $0xd,%esi
call   1040 <print_bits@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jg     1190 <main+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [10 x i8] c"%x %c %x\0A\00"
@.str.2 = [5 x i8] c" %c \00"
@.str.3 = [7 x i8] c" = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %36
12: ; preds = %8
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %5, i32* %4)
%14 = load i8, i8* %5
%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* %3
%19 = load i32, i32* %4
%20 = add nsw i32 %18, %19
br label %25
21: ; preds = %12
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = sub nsw i32 %22, %23
br label %25
25: ; preds = %21, %17
%26 = phi i32 [ %20, %17 ], [ %24, %21 ]
store i32 %26, i32* %6
%27 = load i32, i32* %3
%28 = call i32 @print_bits(i32 %27, i32 13)
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %4
%33 = call i32 @print_bits(i32 %32, i32 13)
%34 = load i32, i32* %6
%35 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %8
36: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [10 x i8] c"%x %c %x\0A\00"
@.str.2 = [5 x i8] c" %c \00"
@.str.3 = [7 x i8] c" = %d\0A\00"
define i32 @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 ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = add nsw i32 %9, -1
store i32 %10, i32* %1
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %31
12: ; preds = %0, %12
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %2, i8* %4, i32* %3)
%14 = load i8, i8* %4
%15 = icmp eq i8 %14, 43
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = sub i32 0, %17
%19 = select i1 %15, i32 %17, i32 %18
%20 = add i32 %16, %19
%21 = call i32 @print_bits(i32 %16, i32 13)
%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* %3
%26 = call i32 @print_bits(i32 %25, i32 13)
%27 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%28 = load i32, i32* %1
%29 = add nsw i32 %28, -1
store i32 %29, i32* %1
%30 = icmp sgt i32 %28, 0
br i1 %30, label %12, label %31
31: ; preds = %12, %0
ret i32 0
}