#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 */
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int scanf(char *, long *);
long get_long(void) {
  long input;
  char ch;
  while (scanf("%ld", &input) != 1) {
    while ((ch = getchar()) != '\n')
      putchar(ch);
    printf(" is not an integer.\n");
    printf("Please enter an interger value:");
  }
  return input;
}


x86 assembly (clang, -O0):
<get_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     11a7 <get_long+0x67>
jmp    1166 <get_long+0x26>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     118a <get_long+0x4a>
movsbl -0x9(%rbp),%edi
call   1030 <putchar@plt>
jmp    1166 <get_long+0x26>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
jmp    1148 <get_long+0x8>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_long>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
je     11c3 <get_long+0x73>
lea    0xeb1(%rip),%r14
lea    0xe8a(%rip),%r15
lea    0xe7f(%rip),%r12
mov    %rsp,%rbx
jmp    1198 <get_long+0x48>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    1190 <get_long+0x40>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1198 <get_long+0x48>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [21 x i8] c" is not an integer.\0A\00"
@.str.2 = [32 x i8] c"Please enter an interger value:\00"
define i64 @get_long() {
%1 = alloca i64
%2 = alloca i8
br label %3
3: ; preds = %14, %0
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%5 = icmp ne i32 %4, 1
br i1 %5, label %6, label %17
6: ; preds = %3
br label %7
7: ; preds = %11, %6
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i8, i8* %2
%13 = call i32 @putchar(i8 signext %12)
br label %7
14: ; preds = %7
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %3
17: ; preds = %3
%18 = load i64, i64* %1
ret i64 %18
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@.str.2 = [32 x i8] c"Please enter an interger value:\00"
@str = [20 x i8] c" is not an integer.\00"
define i64 @get_long() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %18, label %5
5: ; preds = %0, %13
%6 = call signext i8 (...) @getchar()
%7 = icmp eq i8 %6, 10
br i1 %7, label %13, label %8
8: ; preds = %5, %8
%9 = phi i8 [ %11, %8 ], [ %6, %5 ]
%10 = call i32 @putchar(i8 signext %9)
%11 = call signext i8 (...) @getchar()
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %8
13: ; preds = %8, %5
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %5
18: ; preds = %13, %0
%19 = load i64, i64* %1
ret i64 %19
}