#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 char_to_digit(char);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char getc(int /*<<< orphan*/ *);
scalar_t__ is_digit(char);
int read_int(FILE *stream, char c) {
  int num = 0;
  while (!feof(stream) && is_digit(c)) {
    num = num * 10 + char_to_digit(c);
    c = getc(stream);
  }
  return num;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
jne    1185 <read_int+0x45>
movsbl -0x9(%rbp),%edi
call   1050 <is_digit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1195 <read_int+0x55>
jmp    11c0 <read_int+0x80>
imul   $0xa,-0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <char_to_digit@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,-0x9(%rbp)
jmp    1159 <read_int+0x19>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1040 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    1193 <read_int+0x53>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl %bpl,%ebp
mov    %ebp,%edi
call   1050 <is_digit@plt>
test   %rax,%rax
je     1193 <read_int+0x53>
lea    (%rbx,%rbx,4),%ebx
mov    %ebp,%edi
call   1030 <char_to_digit@plt>
lea    (%rax,%rbx,2),%ebx
mov    %r14,%rdi
call   1060 <getc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <feof@plt>
test   %eax,%eax
je     1160 <read_int+0x20>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_int(i32* %0, i8 signext %1) {
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
store i32* %0, i32** %3
store i8 %1, i8* %4
store i32 0, i32* %5
br label %6
6: ; preds = %16, %2
%7 = load i32*, i32** %3
%8 = call i32 @feof(i32* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = load i8, i8* %4
%12 = call i64 @is_digit(i8 signext %11)
%13 = icmp ne i64 %12, 0
br label %14
14: ; preds = %10, %6
%15 = phi i1 [ false, %6 ], [ %13, %10 ]
br i1 %15, label %16, label %24
16: ; preds = %14
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 10
%19 = load i8, i8* %4
%20 = call i32 @char_to_digit(i8 signext %19)
%21 = add nsw i32 %18, %20
store i32 %21, i32* %5
%22 = load i32*, i32** %3
%23 = call signext i8 @getc(i32* %22)
store i8 %23, i8* %4
br label %6
24: ; preds = %14
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
define i32 @read_int(i32* nocapture %0, i8 signext %1) {
%3 = tail call i32 @feof(i32* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %2, %10
%6 = phi i32 [ %13, %10 ], [ 0, %2 ]
%7 = phi i8 [ %14, %10 ], [ %1, %2 ]
%8 = tail call i64 @is_digit(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %5
%11 = mul nsw i32 %6, 10
%12 = tail call i32 @char_to_digit(i8 signext %7)
%13 = add nsw i32 %12, %11
%14 = tail call signext i8 @getc(i32* %0)
%15 = tail call i32 @feof(i32* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %5, label %17
17: ; preds = %5, %10, %2
%18 = phi i32 [ 0, %2 ], [ %13, %10 ], [ %6, %5 ]
ret i32 %18
}