#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*/ fprintf(int /*<<< orphan*/, char *);
char getchar();
int scanf(char const *, int *);
int /*<<< orphan*/ stderr;
bool s_scanf(const char *format, int *ele_loc) {
  int ret1, ret2;
  while ((ret1 = scanf(format, ele_loc)) != 1 || (ret2 = getchar()) != '\n') {
    if ((ret1 != 1))
      continue;
    while (getchar() != '\n')
      ;
    fprintf(stderr, "input invalid!\n");
  }
  return true;
}


x86 assembly (clang, -O0):
<s_scanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0x1,%al
cmp    $0x1,%ecx
mov    %al,-0x19(%rbp)
jne    1176 <s_scanf+0x46>
mov    $0x0,%al
call   1030 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0x18(%rbp)
cmp    $0xa,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1186 <s_scanf+0x56>
jmp    11cc <s_scanf+0x9c>
cmpl   $0x1,-0x14(%rbp)
je     1195 <s_scanf+0x65>
jmp    1140 <s_scanf+0x10>
jmp    119a <s_scanf+0x6a>
mov    $0x0,%al
call   1030 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11b2 <s_scanf+0x82>
jmp    119a <s_scanf+0x6a>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1140 <s_scanf+0x10>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_scanf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e9b(%rip),%r12
lea    0xeb4(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1150 <s_scanf+0x20>
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     1189 <s_scanf+0x59>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
jne    1170 <s_scanf+0x40>
mov    (%r12),%edi
mov    %r15,%rsi
call   1040 <fprintf@plt>
jmp    1150 <s_scanf+0x20>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"input invalid!\0A\00"
define i32 @s_scanf(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
br label %7
7: ; preds = %28, %21, %2
%8 = load i8*, i8** %3
%9 = load i32*, i32** %4
%10 = call i32 @scanf(i8* %8, i32* %9)
store i32 %10, i32* %5
%11 = icmp ne i32 %10, 1
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = call signext i8 (...) @getchar()
%14 = sext i8 %13 to i32
store i32 %14, i32* %6
%15 = icmp ne i32 %14, 10
br label %16
16: ; preds = %12, %7
%17 = phi i1 [ true, %7 ], [ %15, %12 ]
br i1 %17, label %18, label %31
18: ; preds = %16
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %18
br label %7
22: ; preds = %18
br label %23
23: ; preds = %27, %22
%24 = call signext i8 (...) @getchar()
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %23
br label %23
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %7
31: ; preds = %16
ret i32 1
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"input invalid!\0A\00"
define i32 @s_scanf(i8* nocapture %0, i32* %1) {
br label %3
3: ; preds = %15, %2
%4 = tail call i32 @scanf(i8* %0, i32* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = tail call signext i8 (...) @getchar()
%8 = icmp eq i8 %7, 10
br i1 %8, label %16, label %9
9: ; preds = %6, %9
%10 = tail call signext i8 (...) @getchar()
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %9
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %3
br label %3
16: ; preds = %6
ret i32 1
}