#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 **getLines(char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  char *mess1 = "hello1\n1world1\n";
  int *len1 = (int *)malloc(sizeof(int));
  char **lines = getLines(mess1, len1);
  if (lines[0] == "hello1" && lines[1] == "1world1" && *len1 == 2) {
    puts("Passed Test 1");
  } else {
    printf("Failed with length: %d\n", *len1);
    printf("%s\n", lines[0]);
    printf("%s\n", lines[1]);
  }
  char *mess2 = "hello\nworld";
  int *len2;
  char **lines2 = getLines(mess2, len2);
  printf("length: %d lines[1]:%s\n", *len2, lines2[1]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <getLines@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
lea    0xe8c(%rip),%rcx
cmp    %rcx,(%rax)
jne    11c0 <main+0x80>
mov    -0x20(%rbp),%rax
lea    0xe7f(%rip),%rcx
cmp    %rcx,0x8(%rax)
jne    11c0 <main+0x80>
mov    -0x18(%rbp),%rax
cmpl   $0x2,(%rax)
jne    11c0 <main+0x80>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
jmp    11ff <main+0xbf>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <getLines@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xea8(%rip),%rdi
mov    %rax,%rsi
call   1060 <getLines@plt>
mov    %rax,%rbx
lea    0xea6(%rip),%rax
cmp    %rax,(%rbx)
jne    118b <main+0x4b>
lea    0xea1(%rip),%rax
cmp    %rax,0x8(%rbx)
jne    118b <main+0x4b>
cmpl   $0x2,(%r14)
jne    118b <main+0x4b>
lea    0xe96(%rip),%rdi
jmp    11a8 <main+0x68>
mov    (%r14),%esi
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
call   1030 <puts@plt>
lea    0xe91(%rip),%rdi
call   1060 <getLines@plt>
mov    0x8(%rax),%rdx
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"hello1\0A1world1\0A\00"
@.str.1 = [7 x i8] c"hello1\00"
@.str.2 = [8 x i8] c"1world1\00"
@.str.3 = [14 x i8] c"Passed Test 1\00"
@.str.4 = [24 x i8] c"Failed with length: %d\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [12 x i8] c"hello\0Aworld\00"
@.str.7 = [24 x i8] c"length: %d lines[1]:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8**
store i32 0, i32* %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = call i64 @malloc(i32 4)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %3
%10 = load i8*, i8** %2
%11 = load i32*, i32** %3
%12 = call i8** @getLines(i8* %10, i32* %11)
store i8** %12, i8*** %4
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
br i1 %16, label %17, label %28
17: ; preds = %0
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i32*, i32** %3
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %40
28: ; preds = %22, %17, %0
%29 = load i32*, i32** %3
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = load i8**, i8*** %4
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %28, %26
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8** %5
%41 = load i8*, i8** %5
%42 = load i32*, i32** %6
%43 = call i8** @getLines(i8* %41, i32* %42)
store i8** %43, i8*** %7
%44 = load i32*, i32** %6
%45 = load i32, i32* %44
%46 = load i8**, i8*** %7
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %45, i8* %48)
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [16 x i8] c"hello1\0A1world1\0A\00"
@.str.1 = [7 x i8] c"hello1\00"
@.str.2 = [8 x i8] c"1world1\00"
@.str.3 = [14 x i8] c"Passed Test 1\00"
@.str.4 = [24 x i8] c"Failed with length: %d\0A\00"
@.str.6 = [12 x i8] c"hello\0Aworld\00"
@.str.7 = [24 x i8] c"length: %d lines[1]:%s\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i8** @getLines(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* %2)
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = getelementptr inbounds i8*, i8** %3, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %23
15: ; preds = %10, %6, %0
%16 = load i32, i32* %2
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %3
%19 = tail call i32 @puts(i8* dereferenceable(1) %18)
%20 = getelementptr inbounds i8*, i8** %3, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
br label %23
23: ; preds = %15, %13
%24 = tail call i8** @getLines(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32* undef)
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 undef, i8* %26)
ret i32 0
}