#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*/ copyString(char *, char *, int);
char *malloc(int);
int /*<<< orphan*/ printText(char **, int, int);
char **realloc(char **, int);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int stringLength(char *);
void readText(char **text, int *lines, int columns) {
  char *line = malloc(sizeof(char) * 41);
  int charIndex = 0;
  char *word = malloc(sizeof(char) * 40);
  scanf("%s", word);
  int length = stringLength(word);
  while (strcmp(word, "xxx") != 0) {
    if (charIndex + length <= 40) {
      copyString(line, word, charIndex);
      charIndex += length;
      if (charIndex != 40) {
        *(line + charIndex) = ' ';
        charIndex++;
      }
    } else {
      *(line + charIndex) = '\0';
      *(text + (*lines)++) = line;
      text = realloc(text, sizeof(char *) * (*lines + 1));
      line = malloc(sizeof(char) * 41);
      copyString(line, word, 0);
      charIndex = length;
      *(line + charIndex) = ' ';
      charIndex++;
    }
    scanf("%s", word);
    length = stringLength(word);
  }
  printText(text, columns, *lines);
}


x86 assembly (clang, -O0):
<readText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x29,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x30(%rbp),%rdi
call   1080 <stringLength@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     12c7 <readText+0x157>
mov    -0x24(%rbp),%eax
add    -0x34(%rbp),%eax
cmp    $0x28,%eax
jg     1228 <readText+0xb8>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <copyString@plt>
mov    -0x34(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x28,-0x24(%rbp)
je     1223 <readText+0xb3>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12a6 <readText+0x136>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x29,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1030 <copyString@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xd4f(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x30(%rbp),%rdi
call   1080 <stringLength@plt>
mov    %eax,-0x34(%rbp)
jmp    11c2 <readText+0x52>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1090 <printText@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readText>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
mov    $0x29,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe55(%rip),%rdi
mov    %rax,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
call   1080 <stringLength@plt>
mov    %eax,%r13d
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     128d <readText+0x11d>
xor    %r14d,%r14d
jmp    1263 <readText+0xf3>
xchg   %ax,%ax
movslq %r14d,%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    0x10(%rsp),%rdx
movslq (%rdx),%rax
lea    0x1(%rax),%ecx
mov    %ecx,(%rdx)
mov    %rbp,(%r12,%rax,8)
lea    0x10(,%rax,8),%esi
mov    %r12,%rdi
call   1060 <realloc@plt>
mov    %rax,%r12
mov    $0x29,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <copyString@plt>
mov    %r13d,%r15d
movslq %r15d,%r14
movb   $0x20,0x0(%rbp,%r14,1)
add    $0x1,%r14d
lea    0xdc4(%rip),%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
call   1080 <stringLength@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
lea    0xdaa(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     128d <readText+0x11d>
lea    (%r14,%r13,1),%r15d
cmp    $0x28,%r15d
jg     11e0 <readText+0x70>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <copyString@plt>
mov    $0x28,%r14d
cmp    $0x28,%r15d
jne    1228 <readText+0xb8>
jmp    1235 <readText+0xc5>
mov    0x10(%rsp),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    0xc(%rsp),%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <printText@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"xxx\00"
define void @readText(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%11 = call i8* @malloc(i32 41)
store i8* %11, i8** %7
store i32 0, i32* %8
%12 = call i8* @malloc(i32 40)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %9
%16 = call i32 @stringLength(i8* %15)
store i32 %16, i32* %10
br label %17
17: ; preds = %75, %3
%18 = load i8*, i8** %9
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %80
21: ; preds = %17
%22 = load i32, i32* %8
%23 = load i32, i32* %10
%24 = add nsw i32 %22, %23
%25 = icmp sle i32 %24, 40
br i1 %25, label %26, label %44
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = load i8*, i8** %9
%29 = load i32, i32* %8
%30 = call i32 @copyString(i8* %27, i8* %28, i32 %29)
%31 = load i32, i32* %10
%32 = load i32, i32* %8
%33 = add nsw i32 %32, %31
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 40
br i1 %35, label %36, label %43
36: ; preds = %26
%37 = load i8*, i8** %7
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 32, i8* %40
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %43
43: ; preds = %36, %26
br label %75
44: ; preds = %21
%45 = load i8*, i8** %7
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %7
%50 = load i8**, i8*** %4
%51 = load i32*, i32** %5
%52 = load i32, i32* %51
%53 = add nsw i32 %52, 1
store i32 %53, i32* %51
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8*, i8** %50, i64 %54
store i8* %49, i8** %55
%56 = load i8**, i8*** %4
%57 = load i32*, i32** %5
%58 = load i32, i32* %57
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = mul i64 8, %60
%62 = trunc i64 %61 to i32
%63 = call i8** @realloc(i8** %56, i32 %62)
store i8** %63, i8*** %4
%64 = call i8* @malloc(i32 41)
store i8* %64, i8** %7
%65 = load i8*, i8** %7
%66 = load i8*, i8** %9
%67 = call i32 @copyString(i8* %65, i8* %66, i32 0)
%68 = load i32, i32* %10
store i32 %68, i32* %8
%69 = load i8*, i8** %7
%70 = load i32, i32* %8
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 32, i8* %72
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %75
75: ; preds = %44, %43
%76 = load i8*, i8** %9
%77 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %76)
%78 = load i8*, i8** %9
%79 = call i32 @stringLength(i8* %78)
store i32 %79, i32* %10
br label %17
80: ; preds = %17
%81 = load i8**, i8*** %4
%82 = load i32, i32* %6
%83 = load i32*, i32** %5
%84 = load i32, i32* %83
%85 = call i32 @printText(i8** %81, i32 %82, i32 %84)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"xxx\00"
define void @readText(i8** %0, i32* nocapture %1, i32 %2) {
%4 = tail call dereferenceable_or_null(41) i8* @malloc(i32 41)
%5 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%6 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @stringLength(i8* %5)
%8 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %47, label %10
10: ; preds = %3, %39
%11 = phi i32 [ %44, %39 ], [ %7, %3 ]
%12 = phi i8** [ %42, %39 ], [ %0, %3 ]
%13 = phi i32 [ %41, %39 ], [ 0, %3 ]
%14 = phi i8* [ %40, %39 ], [ %4, %3 ]
%15 = add nsw i32 %11, %13
%16 = icmp slt i32 %15, 41
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = tail call i32 @copyString(i8* %14, i8* %5, i32 %13)
%19 = icmp eq i32 %15, 40
br i1 %19, label %39, label %32
20: ; preds = %10
%21 = sext i32 %13 to i64
%22 = getelementptr inbounds i8, i8* %14, i64 %21
store i8 0, i8* %22
%23 = load i32, i32* %1
%24 = add nsw i32 %23, 1
store i32 %24, i32* %1
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8*, i8** %12, i64 %25
store i8* %14, i8** %26
%27 = shl i32 %23, 3
%28 = add i32 %27, 16
%29 = tail call i8** @realloc(i8** %12, i32 %28)
%30 = tail call dereferenceable_or_null(41) i8* @malloc(i32 41)
%31 = tail call i32 @copyString(i8* %30, i8* %5, i32 0)
br label %32
32: ; preds = %17, %20
%33 = phi i32 [ %11, %20 ], [ %15, %17 ]
%34 = phi i8* [ %30, %20 ], [ %14, %17 ]
%35 = phi i8** [ %29, %20 ], [ %12, %17 ]
%36 = sext i32 %33 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 32, i8* %37
%38 = add nsw i32 %33, 1
br label %39
39: ; preds = %32, %17
%40 = phi i8* [ %14, %17 ], [ %34, %32 ]
%41 = phi i32 [ 40, %17 ], [ %38, %32 ]
%42 = phi i8** [ %12, %17 ], [ %35, %32 ]
%43 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%44 = tail call i32 @stringLength(i8* %5)
%45 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %10
47: ; preds = %39, %3
%48 = phi i8** [ %0, %3 ], [ %42, %39 ]
%49 = load i32, i32* %1
%50 = tail call i32 @printText(i8** %48, i32 %2, i32 %49)
ret void
}