#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 */
scalar_t__ INT_MAX;
int /*<<< orphan*/ flushInputBuffer();
scalar_t__ isdigit(char);
int /*<<< orphan*/ scanf(char *, char *);
short scanInt(int *data) {
  if (data) {
    unsigned int datanum = 0;
    char check;
    short isNumber = 1;
    int counter = 0;
    short negative = 1;
    scanf("%c", &check);
    if (isdigit(check))
      datanum += check - '0';
    else if ('-' == check)
      negative = -1;
    else {
      flushInputBuffer();
      return 0;
    }
    while (isNumber) {
      scanf("%c", &check);
      if (isdigit(check))
        datanum = datanum * 10 + check - '0';
      else {
        if (check != '\n')
          isNumber = 0;
        else
          break;
      }
      if (datanum > (unsigned int)INT_MAX) {
        flushInputBuffer();
        isNumber = 0;
      }
      counter++;
    }
    if (isNumber) {
      *data = negative * datanum;
      return 1;
    }
  }
  flushInputBuffer();
  return 0;
}


x86 assembly (clang, -O0):
<scanInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     128c <scanInt+0x15c>
movl   $0x0,-0x14(%rbp)
movw   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movw   $0x1,-0x1e(%rbp)
lea    0xe98(%rip),%rdi
lea    -0x15(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x15(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1196 <scanInt+0x66>
movsbl -0x15(%rbp),%eax
sub    $0x30,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11c9 <scanInt+0x99>
movsbl -0x15(%rbp),%ecx
mov    $0x2d,%eax
cmp    %ecx,%eax
jne    11b2 <scanInt+0x82>
movw   $0xffff,-0x1e(%rbp)
jmp    11c4 <scanInt+0x94>
mov    $0x0,%al
call   1050 <flushInputBuffer@plt>
movw   $0x0,-0x2(%rbp)
jmp    1299 <scanInt+0x169>
jmp    11c9 <scanInt+0x99>
jmp    11ce <scanInt+0x9e>
cmpw   $0x0,-0x18(%rbp)
je     1263 <scanInt+0x133>
lea    0xe20(%rip),%rdi
lea    -0x15(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x15(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1211 <scanInt+0xe1>
imul   $0xa,-0x14(%rbp),%eax
movsbl -0x15(%rbp),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    1233 <scanInt+0x103>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     1229 <scanInt+0xf9>
movw   $0x0,-0x18(%rbp)
jmp    122e <scanInt+0xfe>
jmp    1263 <scanInt+0x133>
jmp    1233 <scanInt+0x103>
mov    -0x14(%rbp),%eax
mov    0x2dab(%rip),%rcx
mov    (%rcx),%rcx
cmp    %ecx,%eax
jbe    1255 <scanInt+0x125>
mov    $0x0,%al
call   1050 <flushInputBuffer@plt>
movw   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ce <scanInt+0x9e>
cmpw   $0x0,-0x18(%rbp)
je     1287 <scanInt+0x157>
movswl -0x1e(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movw   $0x1,-0x2(%rbp)
jmp    1299 <scanInt+0x169>
jmp    128c <scanInt+0x15c>
mov    $0x0,%al
call   1050 <flushInputBuffer@plt>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scanInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11ea <scanInt+0xba>
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
movsbl 0x7(%rsp),%edi
call   1030 <isdigit@plt>
movsbl 0x7(%rsp),%ebx
test   %rax,%rax
je     1177 <scanInt+0x47>
add    $0xffffffd0,%ebx
mov    $0x1,%r13d
jmp    1184 <scanInt+0x54>
cmp    $0x2d,%bl
jne    11ea <scanInt+0xba>
mov    $0xffffffff,%r13d
xor    %ebx,%ebx
lea    0xe75(%rip),%r15
lea    0x7(%rsp),%r12
mov    0x2e51(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
movsbl 0x7(%rsp),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11d0 <scanInt+0xa0>
lea    (%rbx,%rbx,4),%ecx
movsbl 0x7(%rsp),%edx
lea    (%rdx,%rcx,2),%ebx
add    $0xffffffd0,%ebx
jmp    11d7 <scanInt+0xa7>
nopw   0x0(%rax,%rax,1)
cmpb   $0xa,0x7(%rsp)
je     1204 <scanInt+0xd4>
cmp    0x0(%rbp),%ebx
ja     11e3 <scanInt+0xb3>
test   %rax,%rax
jne    11a0 <scanInt+0x70>
jmp    11ea <scanInt+0xba>
xor    %eax,%eax
call   1050 <flushInputBuffer@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <flushInputBuffer@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
imul   %r13d,%ebx
mov    %ebx,(%r14)
mov    $0x1,%bx
jmp    11f3 <scanInt+0xc3>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@INT_MAX = global i64 0
define signext i16 @scanInt(i32* %0) {
%2 = alloca i16
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i16
%7 = alloca i32
%8 = alloca i16
store i32* %0, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %73
11: ; preds = %1
store i32 0, i32* %4
store i16 1, i16* %6
store i32 0, i32* %7
store i16 1, i16* %8
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%13 = load i8, i8* %5
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = sub nsw i32 %18, 48
%20 = load i32, i32* %4
%21 = add i32 %20, %19
store i32 %21, i32* %4
br label %30
22: ; preds = %11
%23 = load i8, i8* %5
%24 = sext i8 %23 to i32
%25 = icmp eq i32 45, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i16 -1, i16* %8
br label %29
27: ; preds = %22
%28 = call i32 (...) @flushInputBuffer()
store i16 0, i16* %2
br label %75
29: ; preds = %26
br label %30
30: ; preds = %29, %16
br label %31
31: ; preds = %60, %30
%32 = load i16, i16* %6
%33 = icmp ne i16 %32, 0
br i1 %33, label %34, label %63
34: ; preds = %31
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%36 = load i8, i8* %5
%37 = call i64 @isdigit(i8 signext %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %34
%40 = load i32, i32* %4
%41 = mul i32 %40, 10
%42 = load i8, i8* %5
%43 = sext i8 %42 to i32
%44 = add i32 %41, %43
%45 = sub i32 %44, 48
store i32 %45, i32* %4
br label %53
46: ; preds = %34
%47 = load i8, i8* %5
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 10
br i1 %49, label %50, label %51
50: ; preds = %46
store i16 0, i16* %6
br label %52
51: ; preds = %46
br label %63
52: ; preds = %50
br label %53
53: ; preds = %52, %39
%54 = load i32, i32* %4
%55 = load i64, i64* @INT_MAX
%56 = trunc i64 %55 to i32
%57 = icmp ugt i32 %54, %56
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 (...) @flushInputBuffer()
store i16 0, i16* %6
br label %60
60: ; preds = %58, %53
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %31
63: ; preds = %51, %31
%64 = load i16, i16* %6
%65 = icmp ne i16 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %63
%67 = load i16, i16* %8
%68 = sext i16 %67 to i32
%69 = load i32, i32* %4
%70 = mul i32 %68, %69
%71 = load i32*, i32** %3
store i32 %70, i32* %71
store i16 1, i16* %2
br label %75
72: ; preds = %63
br label %73
73: ; preds = %72, %1
%74 = call i32 (...) @flushInputBuffer()
store i16 0, i16* %2
br label %75
75: ; preds = %73, %66, %27
%76 = load i16, i16* %2
ret i16 %76
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@INT_MAX = global i64 0
define signext i16 @scanInt(i32* writeonly %0) {
%2 = alloca i8
%3 = icmp eq i32* %0, null
br i1 %3, label %48, label %4
4: ; preds = %1
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%6 = load i8, i8* %2
%7 = call i64 @isdigit(i8 signext %6)
%8 = icmp eq i64 %7, 0
%9 = load i8, i8* %2
br i1 %8, label %13, label %10
10: ; preds = %4
%11 = sext i8 %9 to i32
%12 = add nsw i32 %11, -48
br label %17
13: ; preds = %4
%14 = icmp eq i8 %9, 45
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = call i32 (...) @flushInputBuffer()
br label %45
17: ; preds = %13, %10
%18 = phi i32 [ %12, %10 ], [ 0, %13 ]
%19 = phi i32 [ 1, %10 ], [ -1, %13 ]
br label %20
20: ; preds = %17, %42
%21 = phi i32 [ %18, %17 ], [ %36, %42 ]
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%23 = load i8, i8* %2
%24 = call i64 @isdigit(i8 signext %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %20
%27 = mul i32 %21, 10
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = add i32 %27, -48
%31 = add i32 %30, %29
br label %35
32: ; preds = %20
%33 = load i8, i8* %2
%34 = icmp eq i8 %33, 10
br i1 %34, label %43, label %35
35: ; preds = %32, %26
%36 = phi i32 [ %31, %26 ], [ %21, %32 ]
%37 = load i64, i64* @INT_MAX
%38 = trunc i64 %37 to i32
%39 = icmp ugt i32 %36, %38
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 (...) @flushInputBuffer()
br label %47
42: ; preds = %35
br i1 %25, label %47, label %20
43: ; preds = %32
%44 = mul i32 %21, %19
store i32 %44, i32* %0
br label %45
45: ; preds = %43, %15
%46 = phi i16 [ 0, %15 ], [ 1, %43 ]
br label %50
47: ; preds = %42, %40
br label %48
48: ; preds = %47, %1
%49 = call i32 (...) @flushInputBuffer()
br label %50
50: ; preds = %45, %48
%51 = phi i16 [ 0, %48 ], [ %46, %45 ]
ret i16 %51
}