#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*/);
int /*<<< orphan*/ getchar();
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
unsigned long strtol(char *, int /*<<< orphan*/ *, int);
unsigned long getText(char **bufferPtr) {
  char input[3];
  unsigned long numOfLines = 0;
  printf("%s", "How many lines of text do you want to analyse: ");
  fgets(input, 3, stdin);
  numOfLines = strtol(input, NULL, 10);
  if (!numOfLines) {
    puts("Invalid input! Exiting...");
  } else if (numOfLines > 10) {
    puts("\nReading more than 10 lines is prohibited! Exiting...");
    numOfLines = 0;
  } else {
    printf("\n%s %lu %s", "Analysing", numOfLines,
           "lines of text\nPlease hit enter to begin entering text");
    getchar();
    for (unsigned int i = 0; i < numOfLines; i++) {
      bufferPtr[i] = malloc(sizeof(char) * 80);
      fgets(bufferPtr[i], 80, stdin);
    }
  }
  return numOfLines;
}


x86 assembly (clang, -O0):
<getText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xf0d(%rip),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%esi
call   1050 <fgets@plt>
lea    -0xb(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <getText+0x72>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
jmp    127f <getText+0x11f>
cmpq   $0xa,-0x18(%rbp)
jbe    11f6 <getText+0x96>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x18(%rbp)
jmp    127a <getText+0x11a>
mov    -0x18(%rbp),%rdx
lea    0xe7f(%rip),%rdi
lea    0xe83(%rip),%rsi
lea    0xe86(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    1275 <getText+0x115>
mov    $0x50,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1050 <fgets@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1224 <getText+0xc4>
jmp    127a <getText+0x11a>
jmp    127f <getText+0x11f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getText>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xf16(%rip),%rdi
lea    0xe87(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e61(%rip),%r15
mov    (%r15),%edx
lea    0x5(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
test   %rax,%rax
je     11c2 <getText+0x62>
mov    %rax,%r12
cmp    $0xa,%rax
jbe    11d3 <getText+0x73>
lea    0xe8a(%rip),%rdi
jmp    11c9 <getText+0x69>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
xor    %r12d,%r12d
jmp    1226 <getText+0xc6>
lea    0xea6(%rip),%rdi
lea    0xeaa(%rip),%rsi
lea    0xead(%rip),%rcx
xor    %ebx,%ebx
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
nopl   0x0(%rax,%rax,1)
mov    $0x50,%edi
call   1080 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0x50,%esi
call   1050 <fgets@plt>
add    $0x1,%ebx
cmp    %rbx,%r12
ja     1200 <getText+0xa0>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [48 x i8] c"How many lines of text do you want to analyse: \00"
@stdin = global i32 0
@.str.2 = [26 x i8] c"Invalid input! Exiting...\00"
@.str.3 = [54 x i8] c"\0AReading more than 10 lines is prohibited! Exiting...\00"
@.str.4 = [11 x i8] c"\0A%s %lu %s\00"
@.str.5 = [10 x i8] c"Analysing\00"
@.str.6 = [54 x i8] c"lines of text\0APlease hit enter to begin entering text\00"
define i64 @getText(i8** %0) {
%2 = alloca i8**
%3 = alloca [3 x i8]
%4 = alloca i64
%5 = alloca i32
store i8** %0, i8*** %2
store i64 0, i64* %4
%6 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 3, i32 %8)
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%11 = call i64 @strtol(i8* %10, i32* null, i32 10)
store i64 %11, i64* %4
%12 = load i64, i64* %4
%13 = icmp ne i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %48
16: ; preds = %1
%17 = load i64, i64* %4
%18 = icmp ugt i64 %17, 10
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @puts(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %4
br label %47
21: ; preds = %16
%22 = load i64, i64* %4
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i64 %22, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
%24 = call i32 (...) @getchar()
store i32 0, i32* %5
br label %25
25: ; preds = %43, %21
%26 = load i32, i32* %5
%27 = zext i32 %26 to i64
%28 = load i64, i64* %4
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %46
30: ; preds = %25
%31 = call i8* @malloc(i32 80)
%32 = load i8**, i8*** %2
%33 = load i32, i32* %5
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
store i8* %31, i8** %35
%36 = load i8**, i8*** %2
%37 = load i32, i32* %5
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %40, i32 80, i32 %41)
br label %43
43: ; preds = %30
%44 = load i32, i32* %5
%45 = add i32 %44, 1
store i32 %45, i32* %5
br label %25
46: ; preds = %25
br label %47
47: ; preds = %46, %19
br label %48
48: ; preds = %47, %14
%49 = load i64, i64* %4
ret i64 %49
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [48 x i8] c"How many lines of text do you want to analyse: \00"
@stdin = global i32 0
@.str.2 = [26 x i8] c"Invalid input! Exiting...\00"
@.str.3 = [54 x i8] c"\0AReading more than 10 lines is prohibited! Exiting...\00"
@.str.4 = [11 x i8] c"\0A%s %lu %s\00"
@.str.5 = [10 x i8] c"Analysing\00"
@.str.6 = [54 x i8] c"lines of text\0APlease hit enter to begin entering text\00"
define i64 @getText(i8** nocapture writeonly %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %3, i32 3, i32 %5)
%7 = call i64 @strtol(i8* nocapture %3, i32* null, i32 10)
%8 = icmp eq i64 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %1
%10 = icmp ugt i64 %7, 10
br i1 %10, label %23, label %11
11: ; preds = %9
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i64 %7, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
%13 = call i32 (...) @getchar()
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ %21, %14 ], [ 0, %11 ]
%16 = call dereferenceable_or_null(80) i8* @malloc(i32 80)
%17 = getelementptr inbounds i8*, i8** %0, i64 %15
store i8* %16, i8** %17
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %16, i32 80, i32 %18)
%20 = add nuw nsw i64 %15, 1
%21 = and i64 %20, 4294967295
%22 = icmp ugt i64 %7, %21
br i1 %22, label %14, label %26
23: ; preds = %9, %1
%24 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), %1 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), %9 ]
%25 = call i32 @puts(i8* dereferenceable(1) %24)
br label %26
26: ; preds = %14, %23
%27 = phi i64 [ 0, %23 ], [ %7, %14 ]
ret i64 %27
}