#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 Please enter an "
           "integer value, such as 25, -178, or 3: ");
  }
  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     119b <get_long+0x5b>
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>
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   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     11ab <get_long+0x6b>
lea    0xe9e(%rip),%r14
lea    0xe93(%rip),%r15
lea    0x8(%rsp),%rbx
jmp    1188 <get_long+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1180 <get_long+0x40>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1188 <get_long+0x48>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [77 x i8] c" is not an integer.\0A Please enter an integer value, such as 25, -178, or 3: \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 %16
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 ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0))
br label %3
16: ; preds = %3
%17 = load i64, i64* %1
ret i64 %17
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [77 x i8] c" is not an integer.\0A Please enter an integer value, such as 25, -178, or 3: \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 %17, 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 @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %5
17: ; preds = %13, %0
%18 = load i64, i64* %1
ret i64 %18
}