#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();
scalar_t__ malloc(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *Saisie_Chaine() {
  char chaine_tmp[255], *chaine;
  fgets(chaine_tmp, 255, stdin);
  while (chaine_tmp[0] == '\n' || chaine_tmp[strlen(chaine_tmp) - 1] != '\n') {
    if (chaine_tmp[strlen(chaine_tmp) - 1] != '\n') {
      while (getchar() != '\n')
        ;
      puts("Nombre de caracteres trop grand");
    } else {
      puts("Saisie invalide");
    }
    fgets(chaine_tmp, 255, stdin);
  }
  if (chaine_tmp[strlen(chaine_tmp) - 1] == '\n') {
    chaine_tmp[strlen(chaine_tmp) - 1] = '\0';
  }
  chaine = (char *)malloc(sizeof(char) * strlen(chaine_tmp) + 1);
  strcpy(chaine, chaine_tmp);
  return chaine;
}


x86 assembly (clang, -O0):
<Saisie_Chaine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rdi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1060 <fgets@plt>
movsbl -0x100(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x109(%rbp)
je     11c2 <Saisie_Chaine+0x62>
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x100(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
setne  %al
mov    %al,-0x109(%rbp)
mov    -0x109(%rbp),%al
test   $0x1,%al
jne    11d5 <Saisie_Chaine+0x75>
jmp    1250 <Saisie_Chaine+0xf0>
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x100(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     1225 <Saisie_Chaine+0xc5>
jmp    11fc <Saisie_Chaine+0x9c>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1214 <Saisie_Chaine+0xb4>
jmp    11fc <Saisie_Chaine+0x9c>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
jmp    1231 <Saisie_Chaine+0xd1>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
lea    -0x100(%rbp),%rdi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1060 <fgets@plt>
jmp    1185 <Saisie_Chaine+0x25>
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x100(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    128b <Saisie_Chaine+0x12b>
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x100(%rbp,%rax,1)
lea    -0x100(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x108(%rbp),%rax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Saisie_Chaine>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    0x2e73(%rip),%r14
mov    %rsp,%rbx
lea    0xea1(%rip),%r15
lea    0xe7a(%rip),%r12
jmp    1198 <Saisie_Chaine+0x38>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <puts@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1060 <fgets@plt>
cmpb   $0xa,(%rsp)
je     11bf <Saisie_Chaine+0x5f>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     11ed <Saisie_Chaine+0x8d>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
mov    %r15,%rdi
je     1193 <Saisie_Chaine+0x33>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    11e0 <Saisie_Chaine+0x80>
jmp    1190 <Saisie_Chaine+0x30>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    120d <Saisie_Chaine+0xad>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [32 x i8] c"Nombre de caracteres trop grand\00"
@.str.1 = [16 x i8] c"Saisie invalide\00"
define i8* @Saisie_Chaine() {
%1 = alloca [255 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %3, i32 255, i32 %4)
br label %6
6: ; preds = %41, %0
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 10
br i1 %10, label %20, label %11
11: ; preds = %6
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br label %20
20: ; preds = %11, %6
%21 = phi i1 [ true, %6 ], [ %19, %11 ]
br i1 %21, label %22, label %45
22: ; preds = %20
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %39
31: ; preds = %22
br label %32
32: ; preds = %36, %31
%33 = call signext i8 (...) @getchar()
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 10
br i1 %35, label %36, label %37
36: ; preds = %32
br label %32
37: ; preds = %32
%38 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %41
39: ; preds = %22
%40 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
%42 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%43 = load i32, i32* @stdin
%44 = call i32 @fgets(i8* %42, i32 255, i32 %43)
br label %6
45: ; preds = %20
%46 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 10
br i1 %53, label %54, label %60
54: ; preds = %45
%55 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = sub nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %58
store i8 0, i8* %59
br label %60
60: ; preds = %54, %45
%61 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = sext i32 %62 to i64
%64 = mul i64 1, %63
%65 = add i64 %64, 1
%66 = trunc i64 %65 to i32
%67 = call i64 @malloc(i32 %66)
%68 = inttoptr i64 %67 to i8*
store i8* %68, i8** %2
%69 = load i8*, i8** %2
%70 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%71 = call i32 @strcpy(i8* %69, i8* %70)
%72 = load i8*, i8** %2
ret i8* %72
}

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