#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 EXIT_SUCCESS;
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ isdigit(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/);
int main(void) {
  int ch, value;
  fputs("Write any integer do you want: ", stdout);
  while ((ch = fgetc(stdin)) != EOF && isdigit(ch)) {
    value *= 10;
    value += ch - '0';
    fputc(ch, stdout);
  }
  ungetc(ch, stdin);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
mov    0x2e50(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0xd(%rbp)
je     11ad <main+0x5d>
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11bd <main+0x6d>
jmp    11e6 <main+0x96>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
call   1060 <fputc@plt>
jmp    1174 <main+0x24>
mov    -0x8(%rbp),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1070 <ungetc@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e71(%rip),%r15
mov    (%r15),%esi
lea    0xe97(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e73(%rip),%r14
mov    (%r14),%edi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    0x2e5a(%rip),%r12
cmp    (%r12),%eax
je     11b6 <main+0x66>
nopl   0x0(%rax)
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11b6 <main+0x66>
mov    (%r15),%esi
mov    %ebx,%edi
call   1060 <fputc@plt>
mov    (%r14),%edi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cmp    (%r12),%eax
jne    1190 <main+0x40>
mov    (%r14),%esi
mov    %ebx,%edi
call   1070 <ungetc@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Write any integer do you want: \00"
@stdout = global i32 0
@stdin = global i32 0
@EOF = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @stdout
%5 = call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %6
6: ; preds = %17, %0
%7 = load i32, i32* @stdin
%8 = call i32 @fgetc(i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i32, i32* %2
%13 = call i64 @isdigit(i32 %12)
%14 = icmp ne i64 %13, 0
br label %15
15: ; preds = %11, %6
%16 = phi i1 [ false, %6 ], [ %14, %11 ]
br i1 %16, label %17, label %27
17: ; preds = %15
%18 = load i32, i32* %3
%19 = mul nsw i32 %18, 10
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = sub nsw i32 %20, 48
%22 = load i32, i32* %3
%23 = add nsw i32 %22, %21
store i32 %23, i32* %3
%24 = load i32, i32* %2
%25 = load i32, i32* @stdout
%26 = call i32 @fputc(i32 %24, i32 %25)
br label %6
27: ; preds = %15
%28 = load i32, i32* %2
%29 = load i32, i32* @stdin
%30 = call i32 @ungetc(i32 %28, i32 %29)
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}

LLVM IR (-O2):
@.str = [32 x i8] c"Write any integer do you want: \00"
@stdout = global i32 0
@stdin = global i32 0
@EOF = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgetc(i32 %3)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %18, label %7
7: ; preds = %0, %11
%8 = phi i32 [ %15, %11 ], [ %4, %0 ]
%9 = tail call i64 @isdigit(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = load i32, i32* @stdout
%13 = tail call i32 @fputc(i32 %8, i32 %12)
%14 = load i32, i32* @stdin
%15 = tail call i32 @fgetc(i32 %14)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %7
18: ; preds = %7, %11, %0
%19 = phi i32 [ %4, %0 ], [ %15, %11 ], [ %8, %7 ]
%20 = load i32, i32* @stdin
%21 = tail call i32 @ungetc(i32 %19, i32 %20)
%22 = load i32, i32* @EXIT_SUCCESS
ret i32 %22
}