#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 getchar();
int getDecimalInteger(void) {
  int sum = 0;
  int ch = 0, flag = 0;
  while (1) {
    ch = getchar();
    if ((ch >= '0') && (ch <= '9')) {
      sum *= 10;
      sum = sum + (ch - '0');
      flag = 1;
    }
    if ((flag == 1) && ((ch < '0') || (ch > '9')))
      break;
  }
  return sum;
}


x86 assembly (clang, -O0):
<getDecimalInteger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x30,-0x8(%rbp)
jl     1167 <getDecimalInteger+0x57>
cmpl   $0x39,-0x8(%rbp)
jg     1167 <getDecimalInteger+0x57>
imul   $0xa,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    118a <getDecimalInteger+0x7a>
cmpl   $0x30,-0x8(%rbp)
jl     1185 <getDecimalInteger+0x75>
cmpl   $0x39,-0x8(%rbp)
jle    118a <getDecimalInteger+0x7a>
jmp    118f <getDecimalInteger+0x7f>
jmp    112d <getDecimalInteger+0x1d>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDecimalInteger>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%r14d
xor    %eax,%eax
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%ecx
lea    -0x30(%rcx),%eax
cmp    $0xa,%eax
lea    (%rbx,%rbx,4),%eax
lea    -0x30(%rcx,%rax,2),%eax
cmovae %ebx,%eax
cmovb  %r14d,%ebp
add    $0xffffffc6,%ecx
cmp    $0xfffffff5,%ecx
ja     1120 <getDecimalInteger+0x10>
cmp    $0x1,%ebp
jne    1120 <getDecimalInteger+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getDecimalInteger() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %0, %28
%5 = call i32 (...) @getchar()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp sge i32 %6, 48
br i1 %7, label %8, label %18
8: ; preds = %4
%9 = load i32, i32* %2
%10 = icmp sle i32 %9, 57
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* %1
%13 = mul nsw i32 %12, 10
store i32 %13, i32* %1
%14 = load i32, i32* %1
%15 = load i32, i32* %2
%16 = sub nsw i32 %15, 48
%17 = add nsw i32 %14, %16
store i32 %17, i32* %1
store i32 1, i32* %3
br label %18
18: ; preds = %11, %8, %4
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 48
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 57
br i1 %26, label %27, label %28
27: ; preds = %24, %21
br label %29
28: ; preds = %24, %18
br label %4
29: ; preds = %27
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
define i32 @getDecimalInteger() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 0, %0 ], [ %9, %1 ]
%3 = phi i32 [ 0, %0 ], [ %10, %1 ]
%4 = tail call i32 (...) @getchar()
%5 = add i32 %4, -48
%6 = icmp ult i32 %5, 10
%7 = mul nsw i32 %2, 10
%8 = add nsw i32 %5, %7
%9 = select i1 %6, i32 %8, i32 %2
%10 = select i1 %6, i32 1, i32 %3
%11 = icmp eq i32 %10, 1
%12 = add i32 %4, -58
%13 = icmp ult i32 %12, -10
%14 = and i1 %13, %11
br i1 %14, label %15, label %1
15: ; preds = %1
ret i32 %9
}