#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 *allocChar(int);
int /*<<< orphan*/ clearLineFromReadBuffer();
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printReversedString(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main(int argc, const char *argv[]) {
  int maxLen = 0;
  char *userString = NULL;
  puts("how long do you want to input? ");
  scanf("%d", &maxLen);
  clearLineFromReadBuffer();
  userString = allocChar(maxLen);
  printf("Enter a message: ");
  fgets(userString, maxLen, stdin);
  printReversedString(userString);
  free(userString);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
lea    0xe68(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1090 <scanf@plt>
mov    $0x0,%al
call   1050 <clearLineFromReadBuffer@plt>
mov    -0x14(%rbp),%edi
call   1080 <allocChar@plt>
mov    %rax,-0x20(%rbp)
lea    0xe48(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
call   1070 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <printReversedString@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe80(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1050 <clearLineFromReadBuffer@plt>
mov    0xc(%rsp),%edi
call   1080 <allocChar@plt>
mov    %rax,%rbx
lea    0xe5f(%rip),%rdi
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x2e14(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   10a0 <printReversedString@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"how long do you want to input? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"Enter a message: \00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
%8 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%10 = call i32 (...) @clearLineFromReadBuffer()
%11 = load i32, i32* %6
%12 = call i8* @allocChar(i32 %11)
store i8* %12, i8** %7
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%14 = load i8*, i8** %7
%15 = load i32, i32* %6
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %14, i32 %15, i32 %16)
%18 = load i8*, i8** %7
%19 = call i32 @printReversedString(i8* %18)
%20 = load i8*, i8** %7
%21 = call i32 @free(i8* %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"how long do you want to input? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"Enter a message: \00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = call i32 (...) @clearLineFromReadBuffer()
%8 = load i32, i32* %3
%9 = call i8* @allocChar(i32 %8)
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* %3
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %9, i32 %11, i32 %12)
%14 = call i32 @printReversedString(i8* %9)
%15 = call i32 @free(i8* %9)
ret i32 0
}