#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 */
char getchar();
char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
char *getMessage(int nb_char_max) {
  char *message = malloc(sizeof(char) * nb_char_max);
  int cpt_char = 0;
  printf("Saisir %d caractères :", nb_char_max);
  while (cpt_char < nb_char_max) {
    message[cpt_char] = getchar();
    cpt_char++;
  }
  return message;
}


x86 assembly (clang, -O0):
<getMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%esi
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1192 <getMessage+0x62>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <getMessage+0x34>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMessage>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xebb(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
test   %ebp,%ebp
jle    1174 <getMessage+0x44>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <getMessage+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Saisir %d caract\C3\A8res :\00"
define i8* @getMessage(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = mul i64 1, %6
%8 = trunc i64 %7 to i32
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %3
store i32 0, i32* %4
%10 = load i32, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %16, %1
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = call signext i8 (...) @getchar()
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %17, i8* %21
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %12
24: ; preds = %12
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str = [24 x i8] c"Saisir %d caract\C3\A8res :\00"
define noalias i8* @getMessage(i32 %0) {
%2 = tail call i8* @malloc(i32 %0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %11, %7 ]
%9 = tail call signext i8 (...) @getchar()
%10 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 %9, i8* %10
%11 = add nuw nsw i64 %8, 1
%12 = icmp eq i64 %11, %6
br i1 %12, label %13, label %7
13: ; preds = %7, %1
ret i8* %2
}