#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 get_positive_integer(void) {
  int character, number = 0;
  while (isdigit(character = getchar()))
    number = number * 10 + character - '0';
  if (character == EOF)
    return EOF;
  else
    return number;
}


x86 assembly (clang, -O0):
<get_positive_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%edi
mov    %edi,-0x8(%rbp)
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     115c <get_positive_integer+0x3c>
imul   $0xa,-0xc(%rbp),%eax
add    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    112f <get_positive_integer+0xf>
mov    -0x8(%rbp),%eax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%eax
jne    117f <get_positive_integer+0x5f>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1185 <get_positive_integer+0x65>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_positive_integer>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1161 <get_positive_integer+0x41>
xor    %r14d,%r14d
nop
lea    (%r14,%r14,4),%eax
lea    (%rbx,%rax,2),%r14d
add    $0xffffffd0,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1140 <get_positive_integer+0x20>
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ebx
cmove  %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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