#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 INT(char *);
scalar_t__ isNum(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int i, j, c, len, num, temp, t, res, num1, num2, num3;
  char str1[21], str2[21], str3[21];
  char e;
  scanf("%d", &t);
  while (t--) {
    scanf("%s %c %s %c %s", str1, &e, str2, &e, str3);
    if (isNum(str1)) {
      num1 = INT(str1);
      if (isNum(str2)) {
        num2 = INT(str2);
        num3 = num1 + num2;
      } else {
        num3 = INT(str3);
        num2 = num3 - num1;
      }
    } else {
      num2 = INT(str2);
      num3 = INT(str3);
      num1 = num3 - num2;
    }
    printf("%d + %d = %d\n", num1, num2, num3);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
je     1246 <main+0x106>
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rcx
lea    -0x90(%rbp),%r9
lea    0xe75(%rip),%rdi
lea    -0x91(%rbp),%r8
mov    %r8,%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <isNum@plt>
cmp    $0x0,%rax
je     1208 <main+0xc8>
lea    -0x50(%rbp),%rdi
call   1050 <INT@plt>
mov    %eax,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
call   1030 <isNum@plt>
cmp    $0x0,%rax
je     11eb <main+0xab>
lea    -0x70(%rbp),%rdi
call   1050 <INT@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1203 <main+0xc3>
lea    -0x90(%rbp),%rdi
call   1050 <INT@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    122c <main+0xec>
lea    -0x70(%rbp),%rdi
call   1050 <INT@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x90(%rbp),%rdi
call   1050 <INT@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
jmp    1164 <main+0x24>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xeab(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    1179 <main+0x39>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x50(%rsp),%rbx
lea    0x30(%rsp),%r15
lea    0xb(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    11c2 <main+0x82>
nop
mov    %r15,%rdi
call   1050 <INT@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1050 <INT@plt>
mov    %eax,%ecx
mov    %eax,%r14d
sub    %ebp,%r14d
lea    0xe61(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1040 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     1168 <main+0x28>
lea    0xe3a(%rip),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r13,%r9
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rbx,%rdi
call   1030 <isNum@plt>
test   %rax,%rax
je     1190 <main+0x50>
mov    %rbx,%rdi
call   1050 <INT@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1030 <isNum@plt>
test   %rax,%rax
je     1220 <main+0xe0>
mov    %r15,%rdi
call   1050 <INT@plt>
mov    %eax,%ebp
mov    %r14d,%ecx
add    %eax,%ecx
jmp    11aa <main+0x6a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   1050 <INT@plt>
mov    %eax,%ecx
mov    %eax,%ebp
sub    %r14d,%ebp
jmp    11aa <main+0x6a>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [15 x i8] c"%s %c %s %c %s\00"
@.str.2 = [14 x i8] c"%d + %d = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [21 x i8]
%14 = alloca [21 x i8]
%15 = alloca [21 x i8]
%16 = alloca i8
store i32 0, i32* %1
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
br label %18
18: ; preds = %57, %0
%19 = load i32, i32* %8
%20 = add nsw i32 %19, -1
store i32 %20, i32* %8
%21 = icmp ne i32 %19, 0
br i1 %21, label %22, label %62
22: ; preds = %18
%23 = getelementptr inbounds [21 x i8], [21 x i8]* %13, i64 0, i64 0
%24 = getelementptr inbounds [21 x i8], [21 x i8]* %14, i64 0, i64 0
%25 = getelementptr inbounds [21 x i8], [21 x i8]* %15, i64 0, i64 0
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %16, i8* %24, i8* %16, i8* %25)
%27 = getelementptr inbounds [21 x i8], [21 x i8]* %13, i64 0, i64 0
%28 = call i64 @isNum(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %49
30: ; preds = %22
%31 = getelementptr inbounds [21 x i8], [21 x i8]* %13, i64 0, i64 0
%32 = call i32 @INT(i8* %31)
store i32 %32, i32* %10
%33 = getelementptr inbounds [21 x i8], [21 x i8]* %14, i64 0, i64 0
%34 = call i64 @isNum(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %30
%37 = getelementptr inbounds [21 x i8], [21 x i8]* %14, i64 0, i64 0
%38 = call i32 @INT(i8* %37)
store i32 %38, i32* %11
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = add nsw i32 %39, %40
store i32 %41, i32* %12
br label %48
42: ; preds = %30
%43 = getelementptr inbounds [21 x i8], [21 x i8]* %15, i64 0, i64 0
%44 = call i32 @INT(i8* %43)
store i32 %44, i32* %12
%45 = load i32, i32* %12
%46 = load i32, i32* %10
%47 = sub nsw i32 %45, %46
store i32 %47, i32* %11
br label %48
48: ; preds = %42, %36
br label %57
49: ; preds = %22
%50 = getelementptr inbounds [21 x i8], [21 x i8]* %14, i64 0, i64 0
%51 = call i32 @INT(i8* %50)
store i32 %51, i32* %11
%52 = getelementptr inbounds [21 x i8], [21 x i8]* %15, i64 0, i64 0
%53 = call i32 @INT(i8* %52)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = load i32, i32* %11
%56 = sub nsw i32 %54, %55
store i32 %56, i32* %10
br label %57
57: ; preds = %49, %48
%58 = load i32, i32* %10
%59 = load i32, i32* %11
%60 = load i32, i32* %12
%61 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %58, i32 %59, i32 %60)
br label %18
62: ; preds = %18
ret i32 0
}

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