#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__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ vider_buffer();
char *getStr() {
  int len;
  char tmp[1000];
  char *input;
  printf("\n>>  ");
  if (fgets(tmp, 1000, stdin) == NULL || tmp[0] == '\n') {
    printf("Vous n'avez rien saisie, veuillez reesayer:\n");
    return NULL;
  }
  if (tmp[strlen(tmp) - 1] != '\n') {
    vider_buffer();
    printf("Vous avez saisie trop de caractere, veuillez reesayer:\n");
    return NULL;
  }
  tmp[strlen(tmp) - 1] = '\0';
  for (len = 0; tmp[len] != '\0' || len > 999; ++len)
    ;
  input = (char *)malloc(len + 1 * sizeof(char));
  strncpy(input, tmp, len + 1);
  input[len] = '\0';
  return input;
}


x86 assembly (clang, -O0):
<getStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    0xe8e(%rip),%rdi
call   1050 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11ab <getStr+0x4b>
movsbl -0x400(%rbp),%eax
cmp    $0xa,%eax
jne    11c4 <getStr+0x64>
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c2 <getStr+0x162>
lea    -0x400(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     1206 <getStr+0xa6>
mov    $0x0,%al
call   1080 <vider_buffer@plt>
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c2 <getStr+0x162>
lea    -0x400(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x400(%rbp,%rax,1)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%ecx
ff
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x409(%rbp)
jne    1253 <getStr+0xf3>
cmpl   $0x3e7,-0xc(%rbp)
setg   %al
mov    %al,-0x409(%rbp)
mov    -0x409(%rbp),%al
test   $0x1,%al
jne    1266 <getStr+0x106>
jmp    1279 <getStr+0x119>
jmp    126b <getStr+0x10b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1226 <getStr+0xc6>
movslq -0xc(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rdi
lea    -0x400(%rbp),%rsi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x408(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x408(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getStr>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
lea    0xe7f(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1204 <getStr+0x94>
cmpb   $0xa,(%rsp)
je     1204 <getStr+0x94>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1215 <getStr+0xa5>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %rbx,%rax
add    $0x1,%rbx
cmpb   $0x0,(%rsp,%rax,1)
jne    11d0 <getStr+0x60>
cmp    $0x3e7,%rax
ja     11d0 <getStr+0x60>
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rsp,%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r14,%rbx,1)
jmp    122b <getStr+0xbb>
lea    0xe32(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
jmp    122b <getStr+0xbb>
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <vider_buffer@plt>
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\0A>> \00"
@stdin = global i32 0
@.str.1 = [45 x i8] c"Vous n'avez rien saisie, veuillez reesayer:\0A\00"
@.str.2 = [56 x i8] c"Vous avez saisie trop de caractere, veuillez reesayer:\0A\00"
define i8* @getStr() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [1000 x i8]
%4 = alloca i8*
%5 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 1000, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %0
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %17
15: ; preds = %10, %0
%16 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %1
br label %68
17: ; preds = %10
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %29
26: ; preds = %17
%27 = call i32 (...) @vider_buffer()
%28 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
br label %68
29: ; preds = %17
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
store i32 0, i32* %2
br label %35
35: ; preds = %48, %29
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %35
%43 = load i32, i32* %2
%44 = icmp sgt i32 %43, 999
br label %45
45: ; preds = %42, %35
%46 = phi i1 [ true, %35 ], [ %44, %42 ]
br i1 %46, label %47, label %51
47: ; preds = %45
br label %48
48: ; preds = %47
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
store i32 %50, i32* %2
br label %35
51: ; preds = %45
%52 = load i32, i32* %2
%53 = sext i32 %52 to i64
%54 = add i64 %53, 1
%55 = trunc i64 %54 to i32
%56 = call i64 @malloc(i32 %55)
%57 = inttoptr i64 %56 to i8*
store i8* %57, i8** %4
%58 = load i8*, i8** %4
%59 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%60 = load i32, i32* %2
%61 = add nsw i32 %60, 1
%62 = call i32 @strncpy(i8* %58, i8* %59, i32 %61)
%63 = load i8*, i8** %4
%64 = load i32, i32* %2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %4
store i8* %67, i8** %1
br label %68
68: ; preds = %51, %26, %15
%69 = load i8*, i8** %1
ret i8* %69
}

LLVM IR (-O2):
@.str = [6 x i8] c"\0A>> \00"
@stdin = global i32 0
@str = [55 x i8] c"Vous avez saisie trop de caractere, veuillez reesayer:\00"
@str.3 = [44 x i8] c"Vous n'avez rien saisie, veuillez reesayer:\00"
define i8* @getStr() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %2, i32 1000, i32 %4)
%6 = icmp eq i32* %5, null
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 10
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.3, i64 0, i64 0))
br label %42
12: ; preds = %0
%13 = call i32 @strlen(i8* %2)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = call i32 (...) @vider_buffer()
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
br label %42
22: ; preds = %12
%23 = call i32 @strlen(i8* %2)
%24 = add nsw i32 %23, -1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %27, %22
%28 = phi i64 [ %34, %27 ], [ 0, %22 ]
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
%32 = icmp ugt i64 %28, 999
%33 = select i1 %31, i1 true, i1 %32
%34 = add nuw i64 %28, 1
br i1 %33, label %27, label %35
35: ; preds = %27
%36 = trunc i64 %28 to i32
%37 = add nuw nsw i32 %36, 1
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i8*
%40 = call i32 @strncpy(i8* %39, i8* %2, i32 %37)
%41 = getelementptr inbounds i8, i8* %39, i64 %28
store i8 0, i8* %41
br label %42
42: ; preds = %35, %19, %10
%43 = phi i8* [ null, %10 ], [ null, %19 ], [ %39, %35 ]
ret i8* %43
}