#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 check(char *, int);
int convert(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char num1[150];
  char num2[150];
  char num3[150];
  int num_1, num_2, num_3, test, count;
  scanf("%d", &count);
  for (; count > 0; count--) {
    scanf("%s + %s = %s", num1, num2, num3);
    if (check(num1, 1) == 1) {
      test = 1;
    }
    if (check(num2, 2) == 2) {
      test = 2;
    }
    if (check(num3, 3) == 3) {
      test = 3;
    }
    if (test == 1) {
      num_2 = convert(num2);
      num_3 = convert(num3);
      num_1 = num_3 - num_2;
      printf("%d + %d = %d\n", num_1, num_2, num_3);
    }
    if (test == 2) {
      num_1 = convert(num1);
      num_3 = convert(num3);
      num_2 = num_3 - num_1;
      printf("%d + %d = %d\n", num_1, num_2, num_3);
    }
    if (test == 3) {
      num_1 = convert(num1);
      num_2 = convert(num2);
      num_3 = num_2 + num_1;
      printf("%d + %d = %d\n", num_1, num_2, num_3);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x1f4(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x0,-0x1f4(%rbp)
jle    133f <main+0x1ff>
lea    -0xa0(%rbp),%rsi
lea    -0x140(%rbp),%rdx
lea    -0x1e0(%rbp),%rcx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x1,%esi
call   1060 <check@plt>
cmp    $0x1,%eax
jne    11bb <main+0x7b>
movl   $0x1,-0x1f0(%rbp)
lea    -0x140(%rbp),%rdi
mov    $0x2,%esi
call   1060 <check@plt>
cmp    $0x2,%eax
jne    11df <main+0x9f>
movl   $0x2,-0x1f0(%rbp)
lea    -0x1e0(%rbp),%rdi
mov    $0x3,%esi
call   1060 <check@plt>
cmp    $0x3,%eax
jne    1203 <main+0xc3>
movl   $0x3,-0x1f0(%rbp)
cmpl   $0x1,-0x1f0(%rbp)
jne    1264 <main+0x124>
lea    -0x140(%rbp),%rdi
call   1030 <convert@plt>
mov    %eax,-0x1e8(%rbp)
lea    -0x1e0(%rbp),%rdi
call   1030 <convert@plt>
mov    %eax,-0x1ec(%rbp)
mov    -0x1ec(%rbp),%eax
sub    -0x1e8(%rbp),%eax
mov    %eax,-0x1e4(%rbp)
mov    -0x1e4(%rbp),%esi
mov    -0x1e8(%rbp),%edx
mov    -0x1ec(%rbp),%ecx
lea    0xdb1(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x2,-0x1f0(%rbp)
jne    12c5 <main+0x185>
lea    -0xa0(%rbp),%rdi
call   1030 <convert@plt>
mov    %eax,-0x1e4(%rbp)
lea    -0x1e0(%rbp),%rdi
call   1030 <convert@plt>
mov    %eax,-0x1ec(%rbp)
mov    -0x1ec(%rbp),%eax
sub    -0x1e4(%rbp),%eax
mov    %eax,-0x1e8(%rbp)
mov    -0x1e4(%rbp),%esi
mov    -0x1e8(%rbp),%edx
mov    -0x1ec(%rbp),%ecx
lea    0xd50(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x3,-0x1f0(%rbp)
jne    1326 <main+0x1e6>
lea    -0xa0(%rbp),%rdi
call   1030 <convert@plt>
mov    %eax,-0x1e4(%rbp)
lea    -0x140(%rbp),%rdi
call   1030 <convert@plt>
mov    %eax,-0x1e8(%rbp)
mov    -0x1e8(%rbp),%eax
add    -0x1e4(%rbp),%eax
mov    %eax,-0x1ec(%rbp)
mov    -0x1e4(%rbp),%esi
mov    -0x1e8(%rbp),%edx
mov    -0x1ec(%rbp),%ecx
lea    0xcef(%rip),%rdi
call   1040 <printf@plt>
jmp    132b <main+0x1eb>
mov    -0x1f4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1f4(%rbp)
jmp    1167 <main+0x27>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1e8,%rsp
lea    0xea8(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1285 <main+0x145>
lea    0xe8d(%rip),%r14
lea    0x150(%rsp),%r15
lea    0xb0(%rsp),%r12
lea    0x10(%rsp),%rbx
jmp    11ca <main+0x8a>
nopl   (%rax)
mov    %r15,%rdi
call   1030 <convert@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <convert@plt>
mov    %eax,%edx
sub    %ebp,%edx
lea    0xe63(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%ecx
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x1,%eax
jle    1285 <main+0x145>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1060 <check@plt>
cmp    $0x1,%eax
cmove  %eax,%r13d
mov    %r12,%rdi
mov    $0x2,%esi
call   1060 <check@plt>
cmp    $0x2,%eax
cmove  %eax,%r13d
mov    %rbx,%rdi
mov    $0x3,%esi
call   1060 <check@plt>
cmp    $0x3,%eax
cmove  %eax,%r13d
cmp    $0x3,%r13d
je     1260 <main+0x120>
cmp    $0x2,%r13d
je     1190 <main+0x50>
cmp    $0x1,%r13d
jne    11b6 <main+0x76>
mov    %r12,%rdi
call   1030 <convert@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <convert@plt>
mov    %eax,%esi
sub    %ebp,%esi
lea    0xdc4(%rip),%rdi
mov    %ebp,%edx
jmp    11af <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1030 <convert@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <convert@plt>
lea    (%rax,%rbp,1),%ecx
lea    0xd94(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
jmp    11b1 <main+0x71>
xor    %eax,%eax
add    $0x1e8,%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 = [13 x i8] c"%s + %s = %s\00"
@.str.2 = [14 x i8] c"%d + %d = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [150 x i8]
%3 = alloca [150 x i8]
%4 = alloca [150 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
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* %9)
br label %11
11: ; preds = %79, %0
%12 = load i32, i32* %9
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %82
14: ; preds = %11
%15 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16, i8* %17)
%19 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 0
%20 = call i32 @check(i8* %19, i32 1)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 1, i32* %8
br label %23
23: ; preds = %22, %14
%24 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%25 = call i32 @check(i8* %24, i32 2)
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 2, i32* %8
br label %28
28: ; preds = %27, %23
%29 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%30 = call i32 @check(i8* %29, i32 3)
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 3, i32* %8
br label %33
33: ; preds = %32, %28
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%38 = call i32 @convert(i8* %37)
store i32 %38, i32* %6
%39 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%40 = call i32 @convert(i8* %39)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = load i32, i32* %6
%43 = sub nsw i32 %41, %42
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %45, i32 %46)
br label %48
48: ; preds = %36, %33
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, 2
br i1 %50, label %51, label %63
51: ; preds = %48
%52 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 0
%53 = call i32 @convert(i8* %52)
store i32 %53, i32* %5
%54 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%55 = call i32 @convert(i8* %54)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = load i32, i32* %5
%58 = sub nsw i32 %56, %57
store i32 %58, i32* %6
%59 = load i32, i32* %5
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %59, i32 %60, i32 %61)
br label %63
63: ; preds = %51, %48
%64 = load i32, i32* %8
%65 = icmp eq i32 %64, 3
br i1 %65, label %66, label %78
66: ; preds = %63
%67 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 0
%68 = call i32 @convert(i8* %67)
store i32 %68, i32* %5
%69 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%70 = call i32 @convert(i8* %69)
store i32 %70, i32* %6
%71 = load i32, i32* %6
%72 = load i32, i32* %5
%73 = add nsw i32 %71, %72
store i32 %73, i32* %7
%74 = load i32, i32* %5
%75 = load i32, i32* %6
%76 = load i32, i32* %7
%77 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %74, i32 %75, i32 %76)
br label %78
78: ; preds = %66, %63
br label %79
79: ; preds = %78
%80 = load i32, i32* %9
%81 = add nsw i32 %80, -1
store i32 %81, i32* %9
br label %11
82: ; preds = %11
ret i32 0
}

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