#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*/ printf(char *);
int scanf(char *, int *, char *);
int main(int argc, char **argv) {
  int num;
  char term;
  printf("Insert an integer :");
  if (scanf("%d%c", &num, &term) != 2 || term != '\n')
    printf("failure\n");
  else
    printf("valid integer followed by enter key\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x15(%rbp),%rdx
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    116c <main+0x4c>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     117d <main+0x5d>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
jmp    1189 <main+0x69>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x3(%rsp),%rdx
call   1050 <scanf@plt>
cmpb   $0xa,0x3(%rsp)
lea    0xede(%rip),%rcx
lea    0xeb3(%rip),%rdi
cmovne %rcx,%rdi
cmp    $0x2,%eax
cmovne %rcx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Insert an integer :\00"
@.str.1 = [5 x i8] c"%d%c\00"
@.str.2 = [9 x i8] c"failure\0A\00"
@.str.3 = [37 x i8] c"valid integer followed by enter key\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %7)
%10 = icmp ne i32 %9, 2
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i8, i8* %7
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %17
15: ; preds = %11, %2
%16 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %11
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Insert an integer :\00"
@.str.1 = [5 x i8] c"%d%c\00"
@str = [36 x i8] c"valid integer followed by enter key\00"
@str.4 = [8 x i8] c"failure\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %4)
%8 = icmp ne i32 %7, 2
%9 = load i8, i8* %4
%10 = icmp ne i8 %9, 10
%11 = select i1 %8, i1 true, i1 %10
%12 = select i1 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0)
%13 = call i32 @puts(i8* dereferenceable(1) %12)
ret i32 0
}