#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*/ fgets(char *, int, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ puts(char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int Saisie_Entier() {
  char entier[10];
  int ret, valeur;
  fgets(entier, 10, stdin);
  ret = sscanf(entier, "%d", &valeur);
  while (ret != 1 || entier[strlen(entier) - 1] != '\n') {
    if (entier[strlen(entier) - 1] != '\n') {
      while (getchar() != '\n')
        ;
      puts("Nombre trop grand");
    } else {
      puts("Saisie invalide");
    }
    fgets(entier, 10, stdin);
    ret = sscanf(entier, "%d", &valeur);
  }
  return valeur;
}


x86 assembly (clang, -O0):
<Saisie_Entier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0xa(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <fgets@plt>
lea    -0xa(%rbp),%rdi
lea    0xe86(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
mov    %eax,-0x10(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x10(%rbp)
mov    %al,-0x15(%rbp)
jne    11b1 <Saisie_Entier+0x61>
lea    -0xa(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0xa(%rbp,%rax,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11c1 <Saisie_Entier+0x71>
jmp    124a <Saisie_Entier+0xfa>
lea    -0xa(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0xa(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     120b <Saisie_Entier+0xbb>
jmp    11e2 <Saisie_Entier+0x92>
mov    $0x0,%al
call   1060 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11fa <Saisie_Entier+0xaa>
jmp    11e2 <Saisie_Entier+0x92>
lea    0xe02(%rip),%rdi
call   1030 <puts@plt>
jmp    1217 <Saisie_Entier+0xc7>
lea    0xe03(%rip),%rdi
call   1030 <puts@plt>
lea    -0xa(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <fgets@plt>
lea    -0xa(%rbp),%rdi
lea    0xdc7(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
mov    %eax,-0x10(%rbp)
jmp    1186 <Saisie_Entier+0x36>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Saisie_Entier>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e83(%rip),%r12
lea    0xe(%rsp),%rbx
lea    0xe8f(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe98(%rip),%r13
lea    0xe7f(%rip),%rbp
jmp    1195 <Saisie_Entier+0x45>
cs nopw 0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11ca <Saisie_Entier+0x7a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     11f0 <Saisie_Entier+0xa0>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
mov    %r13,%rdi
je     1190 <Saisie_Entier+0x40>
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    11e0 <Saisie_Entier+0x90>
mov    %rbp,%rdi
jmp    1190 <Saisie_Entier+0x40>
mov    0x8(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [18 x i8] c"Nombre trop grand\00"
@.str.2 = [16 x i8] c"Saisie invalide\00"
define i32 @Saisie_Entier() {
%1 = alloca [10 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 10, i32 %5)
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 %8, i32* %2
br label %9
9: ; preds = %42, %0
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 1
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br label %21
21: ; preds = %12, %9
%22 = phi i1 [ true, %9 ], [ %20, %12 ]
br i1 %22, label %23, label %48
23: ; preds = %21
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %40
32: ; preds = %23
br label %33
33: ; preds = %37, %32
%34 = call signext i8 (...) @getchar()
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %38
37: ; preds = %33
br label %33
38: ; preds = %33
%39 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %42
40: ; preds = %23
%41 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %38
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%44 = load i32, i32* @stdin
%45 = call i32 @fgets(i8* %43, i32 10, i32 %44)
%46 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%47 = call i32 @sscanf(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 %47, i32* %2
br label %9
48: ; preds = %21
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [18 x i8] c"Nombre trop grand\00"
@.str.2 = [16 x i8] c"Saisie invalide\00"
define i32 @Saisie_Entier() {
%1 = alloca [10 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %27, %0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 10, i32 %6)
%8 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = call i32 @strlen(i8* %3)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %30, label %17
17: ; preds = %5, %10
%18 = call i32 @strlen(i8* %3)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 10
br i1 %23, label %27, label %24
24: ; preds = %17, %24
%25 = call signext i8 (...) @getchar()
%26 = icmp eq i8 %25, 10
br i1 %26, label %27, label %24
27: ; preds = %24, %17
%28 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %17 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %24 ]
%29 = call i32 @puts(i8* dereferenceable(1) %28)
br label %5
30: ; preds = %10
%31 = load i32, i32* %2
ret i32 %31
}