#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();
int /*<<< orphan*/ IsDigit(char);
char ReadUART();
int /*<<< orphan*/ WriteUART(char);
signed char ReadNumber(signed char *num, signed char operator) {
  signed char c = 0, i = 0;
  *num = 0;
  for (i = 0; i < 3; i++) {
    c = 0;
    while (!c) {
      if (GetDIP() != 128)
        break;
      c = ReadUART();
    }
    if (GetDIP() != 128)
      break;
    WriteUART(c);
    if (c == operator) {
      return 0;
    }
    if (!IsDigit(c)) {
      return 2;
    }
    if (i > 1) {
      return 1;
    }
    *num *= 10;
    *num += c & 0x0F;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ReadNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movb   $0x0,-0x12(%rbp)
movb   $0x0,-0x13(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movb   $0x0,-0x13(%rbp)
movsbl -0x13(%rbp),%eax
cmp    $0x3,%eax
jge    1247 <ReadNumber+0x107>
movb   $0x0,-0x12(%rbp)
cmpb   $0x0,-0x12(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118c <ReadNumber+0x4c>
jmp    11b2 <ReadNumber+0x72>
mov    $0x0,%al
call   1030 <GetDIP@plt>
cmp    $0x80,%eax
je     11a3 <ReadNumber+0x63>
jmp    11b2 <ReadNumber+0x72>
mov    $0x0,%al
call   1050 <ReadUART@plt>
mov    %al,-0x12(%rbp)
jmp    1176 <ReadNumber+0x36>
mov    $0x0,%al
call   1030 <GetDIP@plt>
cmp    $0x80,%eax
je     11c9 <ReadNumber+0x89>
jmp    1247 <ReadNumber+0x107>
movsbl -0x12(%rbp),%edi
call   1040 <WriteUART@plt>
movsbl -0x12(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    11eb <ReadNumber+0xab>
movb   $0x0,-0x1(%rbp)
jmp    124b <ReadNumber+0x10b>
movsbl -0x12(%rbp),%edi
call   1060 <IsDigit@plt>
cmp    $0x0,%eax
jne    1206 <ReadNumber+0xc6>
movb   $0x2,-0x1(%rbp)
jmp    124b <ReadNumber+0x10b>
movsbl -0x13(%rbp),%eax
cmp    $0x1,%eax
jle    121c <ReadNumber+0xdc>
movb   $0x1,-0x1(%rbp)
jmp    124b <ReadNumber+0x10b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
imul   $0xa,%ecx,%ecx
mov    %cl,(%rax)
movsbl -0x12(%rbp),%edx
and    $0xf,%edx
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
add    %edx,%ecx
mov    %cl,(%rax)
mov    -0x13(%rbp),%al
add    $0x1,%al
mov    %al,-0x13(%rbp)
jmp    1165 <ReadNumber+0x25>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadNumber>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
movb   $0x0,(%rdi)
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <GetDIP@plt>
cmp    $0x80,%eax
jne    116d <ReadNumber+0x2d>
xor    %eax,%eax
call   1050 <ReadUART@plt>
test   %al,%al
je     1150 <ReadNumber+0x10>
mov    %eax,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <GetDIP@plt>
cmp    $0x80,%eax
jne    1280 <ReadNumber+0x140>
movsbl %bpl,%ebx
mov    %ebx,%edi
call   1040 <WriteUART@plt>
cmp    %r14b,%bl
jne    1198 <ReadNumber+0x58>
xor    %ebx,%ebx
jmp    1280 <ReadNumber+0x140>
mov    %ebx,%edi
call   1060 <IsDigit@plt>
mov    $0x2,%bl
test   %eax,%eax
je     1280 <ReadNumber+0x140>
movzbl (%r15),%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
and    $0xf,%bpl
add    %al,%bpl
mov    %bpl,(%r15)
nopl   0x0(%rax)
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <GetDIP@plt>
cmp    $0x80,%eax
jne    11dd <ReadNumber+0x9d>
xor    %eax,%eax
call   1050 <ReadUART@plt>
test   %al,%al
je     11c0 <ReadNumber+0x80>
mov    %eax,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <GetDIP@plt>
cmp    $0x80,%eax
jne    1280 <ReadNumber+0x140>
movsbl %bpl,%ebx
mov    %ebx,%edi
call   1040 <WriteUART@plt>
cmp    %r14b,%bl
je     1191 <ReadNumber+0x51>
mov    %ebx,%edi
call   1060 <IsDigit@plt>
mov    $0x2,%bl
test   %eax,%eax
je     1280 <ReadNumber+0x140>
movzbl (%r15),%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
and    $0xf,%bpl
add    %al,%bpl
mov    %bpl,(%r15)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <GetDIP@plt>
cmp    $0x80,%eax
jne    124d <ReadNumber+0x10d>
xor    %eax,%eax
call   1050 <ReadUART@plt>
test   %al,%al
je     1230 <ReadNumber+0xf0>
mov    %eax,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <GetDIP@plt>
cmp    $0x80,%eax
jne    1280 <ReadNumber+0x140>
movsbl %bpl,%ebx
mov    %ebx,%edi
call   1040 <WriteUART@plt>
cmp    %r14b,%bl
je     1191 <ReadNumber+0x51>
mov    %ebx,%edi
call   1060 <IsDigit@plt>
cmp    $0x1,%eax
mov    $0x1,%bl
adc    $0x0,%bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @ReadNumber(i8* %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8 0, i8* %6
store i8 0, i8* %7
%8 = load i8*, i8** %4
store i8 0, i8* %8
store i8 0, i8* %7
br label %9
9: ; preds = %61, %2
%10 = load i8, i8* %7
%11 = sext i8 %10 to i32
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %64
13: ; preds = %9
store i8 0, i8* %6
br label %14
14: ; preds = %22, %13
%15 = load i8, i8* %6
%16 = icmp ne i8 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = call i32 (...) @GetDIP()
%20 = icmp ne i32 %19, 128
br i1 %20, label %21, label %22
21: ; preds = %18
br label %24
22: ; preds = %18
%23 = call signext i8 (...) @ReadUART()
store i8 %23, i8* %6
br label %14
24: ; preds = %21, %14
%25 = call i32 (...) @GetDIP()
%26 = icmp ne i32 %25, 128
br i1 %26, label %27, label %28
27: ; preds = %24
br label %64
28: ; preds = %24
%29 = load i8, i8* %6
%30 = call i32 @WriteUART(i8 signext %29)
%31 = load i8, i8* %6
%32 = sext i8 %31 to i32
%33 = load i8, i8* %5
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %32, %34
br i1 %35, label %36, label %37
36: ; preds = %28
store i8 0, i8* %3
br label %65
37: ; preds = %28
%38 = load i8, i8* %6
%39 = call i32 @IsDigit(i8 signext %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %37
store i8 2, i8* %3
br label %65
42: ; preds = %37
%43 = load i8, i8* %7
%44 = sext i8 %43 to i32
%45 = icmp sgt i32 %44, 1
br i1 %45, label %46, label %47
46: ; preds = %42
store i8 1, i8* %3
br label %65
47: ; preds = %42
%48 = load i8*, i8** %4
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = mul nsw i32 %50, 10
%52 = trunc i32 %51 to i8
store i8 %52, i8* %48
%53 = load i8, i8* %6
%54 = sext i8 %53 to i32
%55 = and i32 %54, 15
%56 = load i8*, i8** %4
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = add nsw i32 %58, %55
%60 = trunc i32 %59 to i8
store i8 %60, i8* %56
br label %61
61: ; preds = %47
%62 = load i8, i8* %7
%63 = add i8 %62, 1
store i8 %63, i8* %7
br label %9
64: ; preds = %27, %9
store i8 0, i8* %3
br label %65
65: ; preds = %64, %46, %41, %36
%66 = load i8, i8* %3
ret i8 %66
}

LLVM IR (-O2):
define signext i8 @ReadNumber(i8* nocapture %0, i8 signext %1) {
store i8 0, i8* %0
br label %3
3: ; preds = %2, %6
%4 = tail call i32 (...) @GetDIP()
%5 = icmp eq i32 %4, 128
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call signext i8 (...) @ReadUART()
%8 = icmp eq i8 %7, 0
br i1 %8, label %3, label %9
9: ; preds = %3, %6
%10 = phi i8 [ 0, %3 ], [ %7, %6 ]
%11 = tail call i32 (...) @GetDIP()
%12 = icmp eq i32 %11, 128
br i1 %12, label %13, label %62
13: ; preds = %9
%14 = tail call i32 @WriteUART(i8 signext %10)
%15 = icmp eq i8 %10, %1
br i1 %15, label %62, label %16
16: ; preds = %13
%17 = tail call i32 @IsDigit(i8 signext %10)
%18 = icmp eq i32 %17, 0
br i1 %18, label %62, label %19
19: ; preds = %16
%20 = load i8, i8* %0
%21 = mul i8 %20, 10
%22 = and i8 %10, 15
%23 = add i8 %21, %22
store i8 %23, i8* %0
br label %24
24: ; preds = %27, %19
%25 = tail call i32 (...) @GetDIP()
%26 = icmp eq i32 %25, 128
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call signext i8 (...) @ReadUART()
%29 = icmp eq i8 %28, 0
br i1 %29, label %24, label %30
30: ; preds = %27, %24
%31 = phi i8 [ 0, %24 ], [ %28, %27 ]
%32 = tail call i32 (...) @GetDIP()
%33 = icmp eq i32 %32, 128
br i1 %33, label %34, label %62
34: ; preds = %30
%35 = tail call i32 @WriteUART(i8 signext %31)
%36 = icmp eq i8 %31, %1
br i1 %36, label %62, label %37
37: ; preds = %34
%38 = tail call i32 @IsDigit(i8 signext %31)
%39 = icmp eq i32 %38, 0
br i1 %39, label %62, label %40
40: ; preds = %37
%41 = load i8, i8* %0
%42 = mul i8 %41, 10
%43 = and i8 %31, 15
%44 = add i8 %42, %43
store i8 %44, i8* %0
br label %45
45: ; preds = %48, %40
%46 = tail call i32 (...) @GetDIP()
%47 = icmp eq i32 %46, 128
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = tail call signext i8 (...) @ReadUART()
%50 = icmp eq i8 %49, 0
br i1 %50, label %45, label %51
51: ; preds = %48, %45
%52 = phi i8 [ 0, %45 ], [ %49, %48 ]
%53 = tail call i32 (...) @GetDIP()
%54 = icmp eq i32 %53, 128
br i1 %54, label %55, label %62
55: ; preds = %51
%56 = tail call i32 @WriteUART(i8 signext %52)
%57 = icmp eq i8 %52, %1
br i1 %57, label %62, label %58
58: ; preds = %55
%59 = tail call i32 @IsDigit(i8 signext %52)
%60 = icmp eq i32 %59, 0
%61 = select i1 %60, i8 2, i8 1
br label %62
62: ; preds = %58, %55, %51, %37, %34, %30, %9, %16, %13
%63 = phi i8 [ 0, %13 ], [ 2, %16 ], [ 0, %9 ], [ 0, %30 ], [ 0, %34 ], [ 2, %37 ], [ 0, %51 ], [ 0, %55 ], [ %61, %58 ]
ret i8 %63
}