#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 EOF;
int getchar();
scalar_t__ isdigit(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/);
int main(void) {
  int value = 0;
  int ch;
  while ((ch = getchar()) != EOF && isdigit(ch)) {
    value *= 10;
    value += ch - '0';
  }
  ungetc(ch, stdin);
  return value;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e85(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0xd(%rbp)
je     1178 <main+0x48>
mov    -0xc(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1188 <main+0x58>
jmp    11a0 <main+0x70>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x30,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>
mov    -0xc(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1050 <ungetc@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    0x2e98(%rip),%r15
cmp    (%r15),%eax
je     1176 <main+0x46>
xor    %r14d,%r14d
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1176 <main+0x46>
lea    (%r14,%r14,4),%eax
lea    (%rbx,%rax,2),%r14d
add    $0xffffffd0,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
cmp    (%r15),%eax
jne    1150 <main+0x20>
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <ungetc@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %4
4: ; preds = %14, %0
%5 = call i32 (...) @getchar()
store i32 %5, i32* %3
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i32, i32* %3
%10 = call i64 @isdigit(i32 %9)
%11 = icmp ne i64 %10, 0
br label %12
12: ; preds = %8, %4
%13 = phi i1 [ false, %4 ], [ %11, %8 ]
br i1 %13, label %14, label %21
14: ; preds = %12
%15 = load i32, i32* %2
%16 = mul nsw i32 %15, 10
store i32 %16, i32* %2
%17 = load i32, i32* %3
%18 = sub nsw i32 %17, 48
%19 = load i32, i32* %2
%20 = add nsw i32 %19, %18
store i32 %20, i32* %2
br label %4
21: ; preds = %12
%22 = load i32, i32* %3
%23 = load i32, i32* @stdin
%24 = call i32 @ungetc(i32 %22, i32 %23)
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@EOF = global i32 0
@stdin = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %16, label %4
4: ; preds = %0, %9
%5 = phi i32 [ %13, %9 ], [ %1, %0 ]
%6 = phi i32 [ %12, %9 ], [ 0, %0 ]
%7 = tail call i64 @isdigit(i32 %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = mul nsw i32 %6, 10
%11 = add nsw i32 %5, -48
%12 = add nsw i32 %11, %10
%13 = tail call i32 (...) @getchar()
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %4
16: ; preds = %4, %9, %0
%17 = phi i32 [ 0, %0 ], [ %12, %9 ], [ %6, %4 ]
%18 = phi i32 [ %1, %0 ], [ %13, %9 ], [ %5, %4 ]
%19 = load i32, i32* @stdin
%20 = tail call i32 @ungetc(i32 %18, i32 %19)
ret i32 %17
}