#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 GetDIP();
char ReadNumber(char *, char);
int /*<<< orphan*/ ResultOutput(char);
int /*<<< orphan*/ SendString(char *);
int /*<<< orphan*/ WriteUART(char);
void Calc(void) {
  signed char a = 0, b = 0, res = 0, last_operation = 0;
  if (GetDIP() != 128)
    return;
  last_operation = ReadNumber(&a, '-');
  if (last_operation != 0) {
    if (last_operation == 2) {
      SendString("\n\rinvalid operator\n\r\0");
      return;
    }
    if (last_operation == 1) {
      SendString("\n\rnumber not 0-99\n\r\0");
      return;
    }
  }
  if (GetDIP() != 128)
    return;
  last_operation = ReadNumber(&b, '=');
  if (last_operation != 0) {
    if (last_operation == 2) {
      SendString("\n\rinvalid operator\n\r\0");
      return;
    }
    if (last_operation == 1) {
      SendString("\n\rnumber not 0-99\n\r\0");
      return;
    }
  }
  if (GetDIP() != 128)
    return;
  res = a - b;
  ResultOutput(res);
  WriteUART('\n');
  WriteUART('\r');
}


x86 assembly (clang, -O0):
<Calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x1(%rbp)
movb   $0x0,-0x2(%rbp)
movb   $0x0,-0x3(%rbp)
movb   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <GetDIP@plt>
cmp    $0x80,%eax
je     117f <Calc+0x2f>
jmp    1295 <Calc+0x145>
lea    -0x1(%rbp),%rdi
mov    $0x2d,%esi
call   1070 <ReadNumber@plt>
mov    %al,-0x4(%rbp)
movsbl -0x4(%rbp),%eax
cmp    $0x0,%eax
je     11de <Calc+0x8e>
movsbl -0x4(%rbp),%eax
cmp    $0x2,%eax
jne    11bb <Calc+0x6b>
lea    0xe4f(%rip),%rdi
call   1060 <SendString@plt>
jmp    1295 <Calc+0x145>
movsbl -0x4(%rbp),%eax
cmp    $0x1,%eax
jne    11d9 <Calc+0x89>
lea    0xe47(%rip),%rdi
call   1060 <SendString@plt>
jmp    1295 <Calc+0x145>
jmp    11de <Calc+0x8e>
mov    $0x0,%al
call   1040 <GetDIP@plt>
cmp    $0x80,%eax
je     11f5 <Calc+0xa5>
jmp    1295 <Calc+0x145>
lea    -0x2(%rbp),%rdi
mov    $0x3d,%esi
call   1070 <ReadNumber@plt>
mov    %al,-0x4(%rbp)
movsbl -0x4(%rbp),%eax
cmp    $0x0,%eax
je     1254 <Calc+0x104>
movsbl -0x4(%rbp),%eax
cmp    $0x2,%eax
jne    1231 <Calc+0xe1>
lea    0xdd9(%rip),%rdi
call   1060 <SendString@plt>
jmp    1295 <Calc+0x145>
movsbl -0x4(%rbp),%eax
cmp    $0x1,%eax
jne    124f <Calc+0xff>
lea    0xdd1(%rip),%rdi
call   1060 <SendString@plt>
jmp    1295 <Calc+0x145>
jmp    1254 <Calc+0x104>
mov    $0x0,%al
call   1040 <GetDIP@plt>
cmp    $0x80,%eax
je     126b <Calc+0x11b>
jmp    1295 <Calc+0x145>
movsbl -0x1(%rbp),%eax
movsbl -0x2(%rbp),%ecx
sub    %ecx,%eax
mov    %al,-0x3(%rbp)
movsbl -0x3(%rbp),%edi
call   1030 <ResultOutput@plt>
mov    $0xa,%edi
call   1050 <WriteUART@plt>
mov    $0xd,%edi
call   1050 <WriteUART@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Calc>:
push   %rax
movb   $0x0,0x7(%rsp)
movb   $0x0,0x6(%rsp)
xor    %eax,%eax
call   1040 <GetDIP@plt>
cmp    $0x80,%eax
jne    11e0 <Calc+0x90>
lea    0x7(%rsp),%rdi
mov    $0x2d,%esi
call   1070 <ReadNumber@plt>
cmp    $0x1,%al
je     11e2 <Calc+0x92>
cmp    $0x2,%al
jne    1189 <Calc+0x39>
lea    0xe79(%rip),%rdi
jmp    11e9 <Calc+0x99>
xor    %eax,%eax
call   1040 <GetDIP@plt>
cmp    $0x80,%eax
jne    11e0 <Calc+0x90>
lea    0x6(%rsp),%rdi
mov    $0x3d,%esi
call   1070 <ReadNumber@plt>
cmp    $0x1,%al
je     11e2 <Calc+0x92>
cmp    $0x2,%al
je     1180 <Calc+0x30>
xor    %eax,%eax
call   1040 <GetDIP@plt>
cmp    $0x80,%eax
jne    11e0 <Calc+0x90>
mov    0x7(%rsp),%al
sub    0x6(%rsp),%al
movsbl %al,%edi
call   1030 <ResultOutput@plt>
mov    $0xa,%edi
call   1050 <WriteUART@plt>
mov    $0xd,%edi
call   1050 <WriteUART@plt>
pop    %rax
ret
lea    0xe2d(%rip),%rdi
call   1060 <SendString@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\0A\0Dinvalid operator\0A\0D\00\00"
@.str.1 = [21 x i8] c"\0A\0Dnumber not 0-99\0A\0D\00\00"
define void @Calc() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 0, i8* %1
store i8 0, i8* %2
store i8 0, i8* %3
store i8 0, i8* %4
%5 = call i32 (...) @GetDIP()
%6 = icmp ne i32 %5, 128
br i1 %6, label %7, label %8
7: ; preds = %0
br label %63
8: ; preds = %0
%9 = call signext i8 @ReadNumber(i8* %1, i8 signext 45)
store i8 %9, i8* %4
%10 = load i8, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %8
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @SendString(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %63
19: ; preds = %13
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @SendString(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %63
25: ; preds = %19
br label %26
26: ; preds = %25, %8
%27 = call i32 (...) @GetDIP()
%28 = icmp ne i32 %27, 128
br i1 %28, label %29, label %30
29: ; preds = %26
br label %63
30: ; preds = %26
%31 = call signext i8 @ReadNumber(i8* %2, i8 signext 61)
store i8 %31, i8* %4
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %30
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @SendString(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %63
41: ; preds = %35
%42 = load i8, i8* %4
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @SendString(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %63
47: ; preds = %41
br label %48
48: ; preds = %47, %30
%49 = call i32 (...) @GetDIP()
%50 = icmp ne i32 %49, 128
br i1 %50, label %51, label %52
51: ; preds = %48
br label %63
52: ; preds = %48
%53 = load i8, i8* %1
%54 = sext i8 %53 to i32
%55 = load i8, i8* %2
%56 = sext i8 %55 to i32
%57 = sub nsw i32 %54, %56
%58 = trunc i32 %57 to i8
store i8 %58, i8* %3
%59 = load i8, i8* %3
%60 = call i32 @ResultOutput(i8 signext %59)
%61 = call i32 @WriteUART(i8 signext 10)
%62 = call i32 @WriteUART(i8 signext 13)
br label %63
63: ; preds = %52, %51, %45, %39, %29, %23, %17, %7
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"\0A\0Dinvalid operator\0A\0D\00\00"
@.str.1 = [21 x i8] c"\0A\0Dnumber not 0-99\0A\0D\00\00"
define void @Calc() {
%1 = alloca i8
%2 = alloca i8
store i8 0, i8* %1
store i8 0, i8* %2
%3 = tail call i32 (...) @GetDIP()
%4 = icmp eq i32 %3, 128
br i1 %4, label %5, label %30
5: ; preds = %0
%6 = call signext i8 @ReadNumber(i8* %1, i8 signext 45)
switch i8 %6, label %11 [
i8 1, label %9
i8 2, label %7
]
7: ; preds = %5
%8 = call i32 @SendString(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %30
9: ; preds = %5
%10 = call i32 @SendString(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %30
11: ; preds = %5
%12 = call i32 (...) @GetDIP()
%13 = icmp eq i32 %12, 128
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = call signext i8 @ReadNumber(i8* %2, i8 signext 61)
switch i8 %15, label %20 [
i8 1, label %18
i8 2, label %16
]
16: ; preds = %14
%17 = call i32 @SendString(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %30
18: ; preds = %14
%19 = call i32 @SendString(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %30
20: ; preds = %14
%21 = call i32 (...) @GetDIP()
%22 = icmp eq i32 %21, 128
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i8, i8* %1
%25 = load i8, i8* %2
%26 = sub i8 %24, %25
%27 = call i32 @ResultOutput(i8 signext %26)
%28 = call i32 @WriteUART(i8 signext 10)
%29 = call i32 @WriteUART(i8 signext 13)
br label %30
30: ; preds = %20, %11, %0, %23, %18, %16, %9, %7
ret void
}