#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*/);
scalar_t__ memchr(char *, char, int);
int /*<<< orphan*/ purge_clavier();
int /*<<< orphan*/ stdin;
char *saisie_chaine(char *chaine, int taille) {
  char *p;
  fgets(chaine, taille, stdin);
  if ((p = (char *)memchr(chaine, '\n', taille)) != NULL) {
    *p = '\0';
  } else {
    purge_clavier();
  }
  chaine[taille] = '\0';
  return chaine;
}


x86 assembly (clang, -O0):
<saisie_chaine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0xa,%esi
call   1030 <memchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     117f <saisie_chaine+0x4f>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1186 <saisie_chaine+0x56>
mov    $0x0,%al
call   1050 <purge_clavier@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saisie_chaine>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2ea9(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %ebp,%edx
call   1030 <memchr@plt>
test   %rax,%rax
je     115f <saisie_chaine+0x2f>
movb   $0x0,(%rax)
jmp    1166 <saisie_chaine+0x36>
xor    %eax,%eax
call   1050 <purge_clavier@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i8* @saisie_chaine(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %6, i32 %7, i32 %8)
%10 = load i8*, i8** %3
%11 = load i32, i32* %4
%12 = call i64 @memchr(i8* %10, i8 signext 10, i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i8*, i8** %5
store i8 0, i8* %16
br label %19
17: ; preds = %2
%18 = call i32 (...) @purge_clavier()
br label %19
19: ; preds = %17, %15
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@stdin = global i32 0
define i8* @saisie_chaine(i8* returned %0, i32 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %0, i32 %1, i32 %3)
%5 = tail call i64 @memchr(i8* %0, i8 signext 10, i32 %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = inttoptr i64 %5 to i8*
store i8 0, i8* %8
br label %11
9: ; preds = %2
%10 = tail call i32 (...) @purge_clavier()
br label %11
11: ; preds = %9, %7
%12 = sext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 0, i8* %13
ret i8* %0
}