#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 /*<<< orphan*/ gets(char *);
scalar_t__ isdigit(char);
int ScanInt(int current) {
  char reply[32], *r;
  gets(reply);
  if (isdigit(*(r = reply))) {
    current = 0;
    do {
      current *= 10;
      current += (*r++) - '0';
    } while (isdigit(*r));
  }
  return current;
}


x86 assembly (clang, -O0):
<ScanInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <gets@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
movsbl -0x30(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1193 <ScanInt+0x73>
movl   $0x0,-0x4(%rbp)
imul   $0xa,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movsbl (%rax),%eax
sub    $0x30,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    1156 <ScanInt+0x36>
jmp    1193 <ScanInt+0x73>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ScanInt>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r14d
mov    %rsp,%rdi
call   1040 <gets@plt>
movsbl (%rsp),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1171 <ScanInt+0x51>
lea    0x1(%rsp),%rbx
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
lea    (%r14,%r14,4),%eax
movsbl -0x1(%rbx),%ecx
lea    (%rcx,%rax,2),%r14d
add    $0xffffffd0,%r14d
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <ScanInt+0x30>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @ScanInt(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = call i32 @gets(i8* %5)
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
store i8* %7, i8** %4
%8 = load i8, i8* %7
%9 = call i64 @isdigit(i8 signext %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %1
store i32 0, i32* %2
br label %12
12: ; preds = %22, %11
%13 = load i32, i32* %2
%14 = mul nsw i32 %13, 10
store i32 %14, i32* %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %4
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
%19 = sub nsw i32 %18, 48
%20 = load i32, i32* %2
%21 = add nsw i32 %20, %19
store i32 %21, i32* %2
br label %22
22: ; preds = %12
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %12, label %27
27: ; preds = %22
br label %28
28: ; preds = %27, %1
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @ScanInt(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = call i32 @gets(i8* %3)
%5 = load i8, i8* %3
%6 = call i64 @isdigit(i8 signext %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %1, %8
%9 = phi i32 [ %16, %8 ], [ 0, %1 ]
%10 = phi i8* [ %12, %8 ], [ %3, %1 ]
%11 = mul nsw i32 %9, 10
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = load i8, i8* %10
%14 = sext i8 %13 to i32
%15 = add i32 %11, -48
%16 = add i32 %15, %14
%17 = load i8, i8* %12
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %8
20: ; preds = %8, %1
%21 = phi i32 [ %0, %1 ], [ %16, %8 ]
ret i32 %21
}