#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 in_buffer_getc();
int /*<<< orphan*/ in_buffer_ungetc();
scalar_t__ isdigit(int);
long parsenum(void) {
  int c;
  long ret = 0;
  for (c = in_buffer_getc(); isdigit(c); c = in_buffer_getc())
    ret = (ret * 10) + (c - '0');
  in_buffer_ungetc();
  return ret;
}


x86 assembly (clang, -O0):
<parsenum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <in_buffer_getc@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1180 <parsenum+0x50>
imul   $0xa,-0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x30,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <in_buffer_getc@plt>
mov    %eax,-0x4(%rbp)
jmp    114a <parsenum+0x1a>
mov    $0x0,%al
call   1050 <in_buffer_ungetc@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsenum>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <in_buffer_getc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1174 <parsenum+0x44>
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%rbx,%rbx,4),%rax
movslq %ebp,%rcx
lea    (%rcx,%rax,2),%rbx
add    $0xffffffffffffffd0,%rbx
xor    %eax,%eax
call   1040 <in_buffer_getc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1150 <parsenum+0x20>
xor    %eax,%eax
call   1050 <in_buffer_ungetc@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @parsenum() {
%1 = alloca i32
%2 = alloca i64
store i64 0, i64* %2
%3 = call i32 (...) @in_buffer_getc()
store i32 %3, i32* %1
br label %4
4: ; preds = %15, %0
%5 = load i32, i32* %1
%6 = call i64 @isdigit(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %4
%9 = load i64, i64* %2
%10 = mul nsw i64 %9, 10
%11 = load i32, i32* %1
%12 = sub nsw i32 %11, 48
%13 = sext i32 %12 to i64
%14 = add nsw i64 %10, %13
store i64 %14, i64* %2
br label %15
15: ; preds = %8
%16 = call i32 (...) @in_buffer_getc()
store i32 %16, i32* %1
br label %4
17: ; preds = %4
%18 = call i32 (...) @in_buffer_ungetc()
%19 = load i64, i64* %2
ret i64 %19
}

LLVM IR (-O2):
define i64 @parsenum() {
%1 = tail call i32 (...) @in_buffer_getc()
%2 = tail call i64 @isdigit(i32 %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %0, %4
%5 = phi i64 [ %10, %4 ], [ 0, %0 ]
%6 = phi i32 [ %11, %4 ], [ %1, %0 ]
%7 = mul nsw i64 %5, 10
%8 = add nsw i32 %6, -48
%9 = sext i32 %8 to i64
%10 = add nsw i64 %7, %9
%11 = tail call i32 (...) @in_buffer_getc()
%12 = tail call i64 @isdigit(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %4, %0
%15 = phi i64 [ 0, %0 ], [ %10, %4 ]
%16 = tail call i32 (...) @in_buffer_ungetc()
ret i64 %15
}