#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int read_char(int /*<<< orphan*/ *);
int read_int(FILE *fp) {
  int r, ch;
  do {
    ch = read_char(fp);
  } while (ch == ' ' || ch == '\n' || ch == '\t');
  if (ch < '0' || ch > '9')
    goto error;
  r = ch - '0';
  while ((ch = read_char(fp)) >= '0' && (ch <= '9')) {
    r *= 10;
    r += ch - '0';
  }
  return r;
error:
  return 0;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <read_char@plt>
mov    %eax,-0x18(%rbp)
mov    $0x1,%al
cmpl   $0x20,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     1150 <read_int+0x40>
mov    $0x1,%al
cmpl   $0xa,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     1150 <read_int+0x40>
cmpl   $0x9,-0x18(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    111c <read_int+0xc>
cmpl   $0x30,-0x18(%rbp)
jl     116f <read_int+0x5f>
cmpl   $0x39,-0x18(%rbp)
jle    1174 <read_int+0x64>
jmp    11d6 <read_int+0xc6>
mov    -0x18(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <read_char@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x1a(%rbp)
jl     11a3 <read_int+0x93>
cmpl   $0x39,-0x18(%rbp)
setle  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    11b3 <read_int+0xa3>
jmp    11cb <read_int+0xbb>
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x30,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    117d <read_int+0x6d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11dd <read_int+0xcd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
movabs $0x100000600,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <read_char@plt>
mov    %eax,%ebx
cmp    $0x20,%eax
ja     1147 <read_int+0x37>
mov    %ebx,%eax
bt     %rax,%r15
jb     1130 <read_int+0x20>
lea    -0x3a(%rbx),%eax
xor    %r15d,%r15d
cmp    $0xfffffff6,%eax
jb     1188 <read_int+0x78>
add    $0xffffffd0,%ebx
mov    %r14,%rdi
call   1030 <read_char@plt>
add    $0xffffffd0,%eax
mov    %ebx,%r15d
cmp    $0x9,%eax
ja     1188 <read_int+0x78>
nopl   0x0(%rax,%rax,1)
lea    (%r15,%r15,4),%ecx
lea    (%rax,%rcx,2),%r15d
mov    %r14,%rdi
call   1030 <read_char@plt>
add    $0xffffffd0,%eax
cmp    $0xa,%eax
jb     1170 <read_int+0x60>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @read_int(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
br label %6
6: ; preds = %18, %1
%7 = load i32*, i32** %3
%8 = call i32 @read_char(i32* %7)
store i32 %8, i32* %5
br label %9
9: ; preds = %6
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 32
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 10
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 9
br label %18
18: ; preds = %15, %12, %9
%19 = phi i1 [ true, %12 ], [ true, %9 ], [ %17, %15 ]
br i1 %19, label %6, label %20
20: ; preds = %18
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 48
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %5
%25 = icmp sgt i32 %24, 57
br i1 %25, label %26, label %27
26: ; preds = %23, %20
br label %48
27: ; preds = %23
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 48
store i32 %29, i32* %4
br label %30
30: ; preds = %39, %27
%31 = load i32*, i32** %3
%32 = call i32 @read_char(i32* %31)
store i32 %32, i32* %5
%33 = icmp sge i32 %32, 48
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %5
%36 = icmp sle i32 %35, 57
br label %37
37: ; preds = %34, %30
%38 = phi i1 [ false, %30 ], [ %36, %34 ]
br i1 %38, label %39, label %46
39: ; preds = %37
%40 = load i32, i32* %4
%41 = mul nsw i32 %40, 10
store i32 %41, i32* %4
%42 = load i32, i32* %5
%43 = sub nsw i32 %42, 48
%44 = load i32, i32* %4
%45 = add nsw i32 %44, %43
store i32 %45, i32* %4
br label %30
46: ; preds = %37
%47 = load i32, i32* %4
store i32 %47, i32* %2
br label %49
48: ; preds = %26
store i32 0, i32* %2
br label %49
49: ; preds = %48, %46
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
define i32 @read_int(i32* %0) {
br label %2
2: ; preds = %4, %1
%3 = tail call i32 @read_char(i32* %0)
switch i32 %3, label %5 [
i32 32, label %4
i32 10, label %4
i32 9, label %4
]
4: ; preds = %2, %2, %2
br label %2
5: ; preds = %2
%6 = add i32 %3, -58
%7 = icmp ult i32 %6, -10
br i1 %7, label %21, label %8
8: ; preds = %5
%9 = add nsw i32 %3, -48
%10 = tail call i32 @read_char(i32* %0)
%11 = add i32 %10, -48
%12 = icmp ult i32 %11, 10
br i1 %12, label %13, label %21
13: ; preds = %8, %13
%14 = phi i32 [ %19, %13 ], [ %11, %8 ]
%15 = phi i32 [ %17, %13 ], [ %9, %8 ]
%16 = mul nsw i32 %15, 10
%17 = add nsw i32 %14, %16
%18 = tail call i32 @read_char(i32* %0)
%19 = add i32 %18, -48
%20 = icmp ult i32 %19, 10
br i1 %20, label %13, label %21
21: ; preds = %13, %8, %5
%22 = phi i32 [ 0, %5 ], [ %9, %8 ], [ %17, %13 ]
ret i32 %22
}