#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*/ __fpurge(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
size_t strcspn(char *, char *);
char *readStringRet(char headerMessage[], int stringLength) {
  char *value = (char *)malloc(stringLength * sizeof(char));
  printf("%s", headerMessage);
  fgets(value, stringLength, stdin);
  value[strcspn(value, "\n")] = '\0';
  __fpurge(stdin);
  return value;
}


x86 assembly (clang, -O0):
<readStringRet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1030 <__fpurge@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readStringRet>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe96(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    0x2e6f(%rip),%r14
mov    (%r14),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fgets@plt>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    (%r14),%edi
call   1030 <__fpurge@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i8* @readStringRet(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 i32, i32* %4
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 1
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %5
%15 = load i32, i32* %4
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %14, i32 %15, i32 %16)
%18 = load i8*, i8** %5
%19 = load i8*, i8** %5
%20 = call i64 @strcspn(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
%22 = load i32, i32* @stdin
%23 = call i32 @__fpurge(i32 %22)
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i8* @readStringRet(i8* %0, i32 %1) {
%3 = tail call i64 @malloc(i32 %1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = load i32, i32* @stdin
%7 = tail call i32 @fgets(i8* %4, i32 %1, i32 %6)
%8 = tail call i64 @strcspn(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds i8, i8* %4, i64 %8
store i8 0, i8* %9
%10 = load i32, i32* @stdin
%11 = tail call i32 @__fpurge(i32 %10)
ret i8* %4
}