#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*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *Saisie_Chaine() {
  char chaine_tmp[50 + 2], *chaine;
  printf("> ");
  fgets(chaine_tmp, 50 + 2, 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.");
    }
    printf("> ");
    fgets(chaine_tmp, 50 + 2, 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    $0x50,%rsp
lea    0xe81(%rip),%rdi
call   1060 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
mov    $0x34,%esi
call   1070 <fgets@plt>
movsbl -0x40(%rbp),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x49(%rbp)
je     11c9 <Saisie_Chaine+0x59>
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11d9 <Saisie_Chaine+0x69>
jmp    1257 <Saisie_Chaine+0xe7>
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     1223 <Saisie_Chaine+0xb3>
jmp    11fa <Saisie_Chaine+0x8a>
mov    $0x0,%al
call   1080 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1212 <Saisie_Chaine+0xa2>
jmp    11fa <Saisie_Chaine+0x8a>
lea    0xdea(%rip),%rdi
call   1040 <puts@plt>
jmp    122f <Saisie_Chaine+0xbf>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
lea    0xdca(%rip),%rdi
call   1060 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
mov    $0x34,%esi
call   1070 <fgets@plt>
jmp    119b <Saisie_Chaine+0x2b>
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1286 <Saisie_Chaine+0x116>
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Saisie_Chaine>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
lea    0xe7c(%rip),%r14
mov    %r14,%rdi
call   1060 <printf@plt>
mov    0x2e55(%rip),%r15
mov    %rsp,%rbx
lea    0xe87(%rip),%r12
lea    0xe5f(%rip),%r13
jmp    11c0 <Saisie_Chaine+0x50>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x34,%esi
call   1070 <fgets@plt>
cmpb   $0xa,(%rsp)
je     11e7 <Saisie_Chaine+0x77>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     120d <Saisie_Chaine+0x9d>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
mov    %r12,%rdi
je     11b3 <Saisie_Chaine+0x43>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
jne    1200 <Saisie_Chaine+0x90>
jmp    11b0 <Saisie_Chaine+0x40>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    122d <Saisie_Chaine+0xbd>
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   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.1 = [33 x i8] c"Nombre de caracteres trop grand.\00"
@.str.2 = [17 x i8] c"Saisie invalide.\00"
define i8* @Saisie_Chaine() {
%1 = alloca [52 x i8]
%2 = alloca i8*
%3 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 52, i32 %5)
br label %7
7: ; preds = %42, %0
%8 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 10
br i1 %11, label %21, label %12
12: ; preds = %7
%13 = getelementptr inbounds [52 x i8], [52 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 [52 x i8], [52 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, %7
%22 = phi i1 [ true, %7 ], [ %20, %12 ]
br i1 %22, label %23, label %47
23: ; preds = %21
%24 = getelementptr inbounds [52 x i8], [52 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 [52 x i8], [52 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 ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %42
40: ; preds = %23
%41 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %38
%43 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%44 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%45 = load i32, i32* @stdin
%46 = call i32 @fgets(i8* %44, i32 52, i32 %45)
br label %7
47: ; preds = %21
%48 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 10
br i1 %55, label %56, label %62
56: ; preds = %47
%57 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 %60
store i8 0, i8* %61
br label %62
62: ; preds = %56, %47
%63 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = sext i32 %64 to i64
%66 = mul i64 1, %65
%67 = add i64 %66, 1
%68 = trunc i64 %67 to i32
%69 = call i64 @malloc(i32 %68)
%70 = inttoptr i64 %69 to i8*
store i8* %70, i8** %2
%71 = load i8*, i8** %2
%72 = getelementptr inbounds [52 x i8], [52 x i8]* %1, i64 0, i64 0
%73 = call i32 @strcpy(i8* %71, i8* %72)
%74 = load i8*, i8** %2
ret i8* %74
}

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