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


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
mov    0x2e8c(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x9(%rbp)
je     1171 <read_int+0x41>
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1181 <read_int+0x51>
jmp    1199 <read_int+0x69>
imul   $0xa,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    113f <read_int+0xf>
mov    -0x8(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1050 <ungetc@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
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 <read_int+0x46>
xor    %r14d,%r14d
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1176 <read_int+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 <read_int+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 @read_int() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %13, %0
%4 = call i32 (...) @getchar()
store i32 %4, i32* %2
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = load i32, i32* %2
%9 = call i64 @isdigit(i32 %8)
%10 = icmp ne i64 %9, 0
br label %11
11: ; preds = %7, %3
%12 = phi i1 [ false, %3 ], [ %10, %7 ]
br i1 %12, label %13, label %20
13: ; preds = %11
%14 = load i32, i32* %1
%15 = mul nsw i32 %14, 10
store i32 %15, i32* %1
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, 48
%18 = load i32, i32* %1
%19 = add nsw i32 %18, %17
store i32 %19, i32* %1
br label %3
20: ; preds = %11
%21 = load i32, i32* %2
%22 = load i32, i32* @stdin
%23 = call i32 @ungetc(i32 %21, i32 %22)
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@EOF = global i32 0
@stdin = global i32 0
define i32 @read_int() {
%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
}