#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 */
typedef int uint32_t;

/* Variables and functions */
char UART_InChar();
int /*<<< orphan*/ UART_OutChar(char);
uint32_t UART_InUDec(void) {
  uint32_t number = 0, length = 0;
  char character;
  character = UART_InChar();
  while (character != 0x0D) {
    if ((character >= '0') && (character <= '9')) {
      number = 10 * number + (character - '0');
      length++;
      UART_OutChar(character);
    } else if ((character == 0x08) && length) {
      number /= 10;
      length--;
      UART_OutChar(character);
    }
    character = UART_InChar();
  }
  return number;
}


x86 assembly (clang, -O0):
<UART_InUDec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <UART_InChar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
je     11d9 <UART_InUDec+0xb9>
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jl     118e <UART_InUDec+0x6e>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
jg     118e <UART_InUDec+0x6e>
imul   $0xa,-0x4(%rbp),%eax
movsbl -0x9(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movsbl -0x9(%rbp),%edi
call   1040 <UART_OutChar@plt>
jmp    11ca <UART_InUDec+0xaa>
movsbl -0x9(%rbp),%eax
cmp    $0x8,%eax
jne    11c5 <UART_InUDec+0xa5>
cmpl   $0x0,-0x8(%rbp)
je     11c5 <UART_InUDec+0xa5>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
movsbl -0x9(%rbp),%edi
call   1040 <UART_OutChar@plt>
jmp    11ca <UART_InUDec+0xaa>
mov    $0x0,%al
call   1030 <UART_InChar@plt>
mov    %al,-0x9(%rbp)
jmp    1140 <UART_InUDec+0x20>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UART_InUDec>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <UART_InChar@plt>
cmp    $0xd,%al
jne    1139 <UART_InUDec+0x19>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1166 <UART_InUDec+0x46>
nop
movzbl %al,%ecx
lea    (%rbx,%rbx,4),%edx
lea    (%rcx,%rdx,2),%ebx
add    $0xffffffd0,%ebx
mov    $0x1,%ecx
add    %ecx,%ebp
movsbl %al,%edi
call   1040 <UART_OutChar@plt>
xor    %eax,%eax
call   1030 <UART_InChar@plt>
cmp    $0xd,%al
je     1130 <UART_InUDec+0x10>
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
jbe    1140 <UART_InUDec+0x20>
cmp    $0x8,%al
jne    115b <UART_InUDec+0x3b>
test   %ebp,%ebp
je     115b <UART_InUDec+0x3b>
movslq %ebx,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
mov    $0x8,%al
mov    $0xffffffff,%ecx
jmp    1151 <UART_InUDec+0x31>

LLVM IR (-O0):
define i32 @UART_InUDec() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call signext i8 (...) @UART_InChar()
store i8 %4, i8* %3
br label %5
5: ; preds = %43, %0
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 13
br i1 %8, label %9, label %45
9: ; preds = %5
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = icmp sge i32 %11, 48
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp sle i32 %15, 57
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i32, i32* %1
%19 = mul nsw i32 10, %18
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 48
%23 = add nsw i32 %19, %22
store i32 %23, i32* %1
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
%26 = load i8, i8* %3
%27 = call i32 @UART_OutChar(i8 signext %26)
br label %43
28: ; preds = %13, %9
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 8
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32, i32* %2
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i32, i32* %1
%37 = sdiv i32 %36, 10
store i32 %37, i32* %1
%38 = load i32, i32* %2
%39 = add nsw i32 %38, -1
store i32 %39, i32* %2
%40 = load i8, i8* %3
%41 = call i32 @UART_OutChar(i8 signext %40)
br label %42
42: ; preds = %35, %32, %28
br label %43
43: ; preds = %42, %17
%44 = call signext i8 (...) @UART_InChar()
store i8 %44, i8* %3
br label %5
45: ; preds = %5
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
define i32 @UART_InUDec() {
%1 = tail call signext i8 (...) @UART_InChar()
%2 = icmp eq i8 %1, 13
br i1 %2, label %31, label %3
3: ; preds = %0, %26
%4 = phi i8 [ %29, %26 ], [ %1, %0 ]
%5 = phi i32 [ %28, %26 ], [ 0, %0 ]
%6 = phi i32 [ %27, %26 ], [ 0, %0 ]
%7 = add i8 %4, -48
%8 = icmp ult i8 %7, 10
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = zext i8 %4 to i32
%11 = mul nsw i32 %6, 10
%12 = add i32 %11, -48
%13 = add i32 %12, %10
br label %20
14: ; preds = %3
%15 = icmp eq i8 %4, 8
%16 = icmp ne i32 %5, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = sdiv i32 %6, 10
br label %20
20: ; preds = %9, %18
%21 = phi i32 [ -1, %18 ], [ 1, %9 ]
%22 = phi i8 [ 8, %18 ], [ %4, %9 ]
%23 = phi i32 [ %19, %18 ], [ %13, %9 ]
%24 = add nsw i32 %5, %21
%25 = tail call i32 @UART_OutChar(i8 signext %22)
br label %26
26: ; preds = %20, %14
%27 = phi i32 [ %6, %14 ], [ %23, %20 ]
%28 = phi i32 [ %5, %14 ], [ %24, %20 ]
%29 = tail call signext i8 (...) @UART_InChar()
%30 = icmp eq i8 %29, 13
br i1 %30, label %31, label %3
31: ; preds = %26, %0
%32 = phi i32 [ 0, %0 ], [ %27, %26 ]
ret i32 %32
}