#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_char_console(unsigned char);
int /*<<< orphan*/ print_string_console(char *);
unsigned char read_char_console();
int read_input() {
  unsigned char buffer;
  int num_digits = 0;
  int is_digit = 0;
  int total = 0;
  int read_number;
  while (1) {
    buffer = read_char_console();
    is_digit = (buffer >= '0' && buffer <= '9') ? 1 : 0;
    if (num_digits == 0) {
      if (is_digit) {
        num_digits++;
        read_number = (int)(buffer - '0');
        total += read_number;
      } else if (buffer == '\n') {
        print_string_console(
            "Never got 2 digits followed by a newline, try again!!\n\n");
        return -1;
      } else {
        print_string_console("Invalid Character |");
        print_char_console(buffer);
        print_string_console("| skipping!!!\n");
      }
    } else if (num_digits == 1) {
      if (is_digit) {
        num_digits++;
        read_number = (int)(buffer - '0');
        total *= 10;
        total += read_number;
      } else if (buffer == '\n') {
        return total;
      } else {
        num_digits = 0;
        total = 0;
        print_string_console("Invalid Character |");
        print_char_console(buffer);
        print_string_console("| ignoring previous values!!!\n");
      }
    } else if (num_digits == 2) {
      if (buffer == '\n') {
        return total;
      } else {
        num_digits = 0;
        total = 0;
        print_string_console("Invalid Character |");
        print_char_console(buffer);
        print_string_console("| ignoring previous values!!!\n");
      }
    }
  }
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <read_char_console@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x19(%rbp)
jl     1176 <read_input+0x46>
movzbl -0x5(%rbp),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    120e <read_input+0xde>
cmpl   $0x0,-0x10(%rbp)
je     11be <read_input+0x8e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movzbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1209 <read_input+0xd9>
movzbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    11e3 <read_input+0xb3>
lea    0xe2e(%rip),%rdi
call   1050 <print_string_console@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1300 <read_input+0x1d0>
lea    0xe4e(%rip),%rdi
call   1050 <print_string_console@plt>
movzbl -0x5(%rbp),%edi
call   1040 <print_char_console@plt>
lea    0xe4d(%rip),%rdi
call   1050 <print_string_console@plt>
jmp    1209 <read_input+0xd9>
jmp    12fb <read_input+0x1cb>
cmpl   $0x1,-0xc(%rbp)
jne    129b <read_input+0x16b>
cmpl   $0x0,-0x10(%rbp)
je     124a <read_input+0x11a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movzbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1296 <read_input+0x166>
movzbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    1262 <read_input+0x132>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1300 <read_input+0x1d0>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xdc1(%rip),%rdi
call   1050 <print_string_console@plt>
movzbl -0x5(%rbp),%edi
call   1040 <print_char_console@plt>
lea    0xdcf(%rip),%rdi
call   1050 <print_string_console@plt>
jmp    1296 <read_input+0x166>
jmp    12f6 <read_input+0x1c6>
cmpl   $0x2,-0xc(%rbp)
jne    12f1 <read_input+0x1c1>
movzbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    12bd <read_input+0x18d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1300 <read_input+0x1d0>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xd66(%rip),%rdi
call   1050 <print_string_console@plt>
movzbl -0x5(%rbp),%edi
call   1040 <print_char_console@plt>
lea    0xd74(%rip),%rdi
call   1050 <print_string_console@plt>
jmp    12f1 <read_input+0x1c1>
jmp    12f6 <read_input+0x1c6>
jmp    12fb <read_input+0x1cb>
jmp    114d <read_input+0x1d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xef6(%rip),%r12
lea    0xf12(%rip),%r14
lea    0xefc(%rip),%r15
jmp    116d <read_input+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1040 <print_char_console@plt>
mov    %r14,%rdi
call   1050 <print_string_console@plt>
xor    %ebp,%ebp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <read_char_console@plt>
mov    %eax,%ebx
cmp    $0x2,%ebp
je     11f0 <read_input+0xc0>
cmp    $0x1,%ebp
je     11c3 <read_input+0x93>
test   %ebp,%ebp
jne    1180 <read_input+0x50>
lea    -0x30(%rbx),%eax
cmp    $0x9,%al
jbe    11de <read_input+0xae>
cmp    $0xa,%bl
je     1224 <read_input+0xf4>
mov    %r12,%rdi
call   1050 <print_string_console@plt>
movzbl %bl,%edi
call   1040 <print_char_console@plt>
mov    %r15,%rdi
call   1050 <print_string_console@plt>
xor    %ebp,%ebp
jmp    1180 <read_input+0x50>
movzbl %bl,%ebp
lea    -0x30(%rbx),%eax
cmp    $0x9,%al
ja     1210 <read_input+0xe0>
lea    0x0(%r13,%r13,4),%eax
lea    -0x30(%rbp,%rax,2),%r13d
mov    $0x2,%ebp
jmp    1180 <read_input+0x50>
movzbl %bl,%eax
add    %eax,%r13d
add    $0xffffffd0,%r13d
mov    $0x1,%ebp
jmp    1180 <read_input+0x50>
nop
cmp    $0xa,%bl
je     1236 <read_input+0x106>
mov    %r12,%rdi
call   1050 <print_string_console@plt>
movzbl %bl,%edi
jmp    1160 <read_input+0x30>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xa,%bl
je     1236 <read_input+0x106>
mov    %r12,%rdi
call   1050 <print_string_console@plt>
mov    %ebp,%edi
jmp    1160 <read_input+0x30>
lea    0xdd5(%rip),%rdi
call   1050 <print_string_console@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Never got 2 digits followed by a newline, try again!!\0A\0A\00"
@.str.1 = [20 x i8] c"Invalid Character |\00"
@.str.2 = [15 x i8] c"| skipping!!!\0A\00"
@.str.3 = [31 x i8] c"| ignoring previous values!!!\0A\00"
define i32 @read_input() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %0, %94
%8 = call zeroext i8 (...) @read_char_console()
store i8 %8, i8* %2
%9 = load i8, i8* %2
%10 = zext i8 %9 to i32
%11 = icmp sge i32 %10, 48
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i8, i8* %2
%14 = zext i8 %13 to i32
%15 = icmp sle i32 %14, 57
br label %16
16: ; preds = %12, %7
%17 = phi i1 [ false, %7 ], [ %15, %12 ]
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 1, i32 0
store i32 %19, i32* %4
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %47
22: ; preds = %16
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
%28 = load i8, i8* %2
%29 = zext i8 %28 to i32
%30 = sub nsw i32 %29, 48
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = load i32, i32* %5
%33 = add nsw i32 %32, %31
store i32 %33, i32* %5
br label %46
34: ; preds = %22
%35 = load i8, i8* %2
%36 = zext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @print_string_console(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %95
40: ; preds = %34
%41 = call i32 @print_string_console(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%42 = load i8, i8* %2
%43 = call i32 @print_char_console(i8 zeroext %42)
%44 = call i32 @print_string_console(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %40
br label %46
46: ; preds = %45, %25
br label %94
47: ; preds = %16
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %77
50: ; preds = %47
%51 = load i32, i32* %4
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %64
53: ; preds = %50
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
%56 = load i8, i8* %2
%57 = zext i8 %56 to i32
%58 = sub nsw i32 %57, 48
store i32 %58, i32* %6
%59 = load i32, i32* %5
%60 = mul nsw i32 %59, 10
store i32 %60, i32* %5
%61 = load i32, i32* %6
%62 = load i32, i32* %5
%63 = add nsw i32 %62, %61
store i32 %63, i32* %5
br label %76
64: ; preds = %50
%65 = load i8, i8* %2
%66 = zext i8 %65 to i32
%67 = icmp eq i32 %66, 10
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = load i32, i32* %5
store i32 %69, i32* %1
br label %95
70: ; preds = %64
store i32 0, i32* %3
store i32 0, i32* %5
%71 = call i32 @print_string_console(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%72 = load i8, i8* %2
%73 = call i32 @print_char_console(i8 zeroext %72)
%74 = call i32 @print_string_console(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %75
75: ; preds = %70
br label %76
76: ; preds = %75, %53
br label %93
77: ; preds = %47
%78 = load i32, i32* %3
%79 = icmp eq i32 %78, 2
br i1 %79, label %80, label %92
80: ; preds = %77
%81 = load i8, i8* %2
%82 = zext i8 %81 to i32
%83 = icmp eq i32 %82, 10
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = load i32, i32* %5
store i32 %85, i32* %1
br label %95
86: ; preds = %80
store i32 0, i32* %3
store i32 0, i32* %5
%87 = call i32 @print_string_console(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%88 = load i8, i8* %2
%89 = call i32 @print_char_console(i8 zeroext %88)
%90 = call i32 @print_string_console(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %91
91: ; preds = %86
br label %92
92: ; preds = %91, %77
br label %93
93: ; preds = %92, %76
br label %94
94: ; preds = %93, %46
br label %7
95: ; preds = %84, %68, %38
%96 = load i32, i32* %1
ret i32 %96
}

LLVM IR (-O2):
@.str = [56 x i8] c"Never got 2 digits followed by a newline, try again!!\0A\0A\00"
@.str.1 = [20 x i8] c"Invalid Character |\00"
@.str.2 = [15 x i8] c"| skipping!!!\0A\00"
@.str.3 = [31 x i8] c"| ignoring previous values!!!\0A\00"
define i32 @read_input() {
br label %1
1: ; preds = %43, %0
%2 = phi i32 [ 0, %0 ], [ %44, %43 ]
%3 = phi i32 [ 0, %0 ], [ %45, %43 ]
br label %4
4: ; preds = %1, %19
%5 = phi i32 [ 0, %19 ], [ %2, %1 ]
br label %6
6: ; preds = %4, %6
%7 = tail call zeroext i8 (...) @read_char_console()
switch i32 %5, label %6 [
i32 0, label %8
i32 1, label %23
i32 2, label %37
]
8: ; preds = %6
%9 = add i8 %7, -48
%10 = icmp ult i8 %9, 10
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = zext i8 %7 to i32
%13 = add nsw i32 %12, -48
%14 = add nsw i32 %13, %3
br label %43
15: ; preds = %8
%16 = icmp eq i8 %7, 10
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @print_string_console(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
br label %46
19: ; preds = %15
%20 = tail call i32 @print_string_console(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @print_char_console(i8 zeroext %7)
%22 = tail call i32 @print_string_console(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %4
23: ; preds = %6
%24 = zext i8 %7 to i32
%25 = add i8 %7, -48
%26 = icmp ult i8 %25, 10
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = add nsw i32 %24, -48
%29 = mul nsw i32 %3, 10
%30 = add nsw i32 %28, %29
br label %43
31: ; preds = %23
%32 = icmp eq i8 %7, 10
br i1 %32, label %46, label %33
33: ; preds = %31
%34 = tail call i32 @print_string_console(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%35 = tail call i32 @print_char_console(i8 zeroext %7)
%36 = tail call i32 @print_string_console(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %43
37: ; preds = %6
%38 = icmp eq i8 %7, 10
br i1 %38, label %46, label %39
39: ; preds = %37
%40 = tail call i32 @print_string_console(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%41 = tail call i32 @print_char_console(i8 zeroext %7)
%42 = tail call i32 @print_string_console(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %39, %33, %27, %11
%44 = phi i32 [ 1, %11 ], [ 2, %27 ], [ 0, %33 ], [ 0, %39 ]
%45 = phi i32 [ %14, %11 ], [ %30, %27 ], [ 0, %33 ], [ 0, %39 ]
br label %1
46: ; preds = %37, %31, %17
%47 = phi i32 [ -1, %17 ], [ %3, %31 ], [ %3, %37 ]
ret i32 %47
}