#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 */
scalar_t__ malloc(int);
char **realloc(char **, int);
int scanf(char *, char *);
int /*<<< orphan*/ str_copy(char *, char *);
size_t str_len(char *);
char **read_str_array(size_t *n, size_t *max_str_len) {
  size_t l, arr_size = 8;
  char **data = (char **)malloc(sizeof(char *) * arr_size);
  char *s = (char *)malloc(sizeof(char) * 256);
  *n = 0;
  while (scanf("%s", s) == 1) {
    if (*n >= arr_size) {
      arr_size *= 2;
      data = realloc(data, sizeof(char *) * arr_size);
    }
    l = str_len(s);
    if (*max_str_len < l)
      *max_str_len = l;
    data[*n] = (char *)malloc(sizeof(char) * l);
    str_copy(data[*n], s);
    (*n)++;
  }
  return data;
}


x86 assembly (clang, -O0):
<read_str_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x8,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x100,%edi
call   1030 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rsi
lea    0xe61(%rip),%rdi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1256 <read_str_array+0x106>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
jb     11e1 <read_str_array+0x91>
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <str_len@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jae    120a <read_str_array+0xba>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <str_copy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1194 <read_str_array+0x44>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_str_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x40,%edi
call   1030 <malloc@plt>
mov    %rax,(%rsp)
mov    $0x100,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
movq   $0x0,(%r12)
lea    0xe75(%rip),%rdi
mov    %rax,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    121c <read_str_array+0xcc>
mov    $0x8,%ebp
lea    0xe58(%rip),%r13
jmp    11e3 <read_str_array+0x93>
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <malloc@plt>
mov    (%r12),%rcx
mov    (%rsp),%rdx
mov    %rax,(%rdx,%rcx,8)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <str_copy@plt>
addq   $0x1,(%r12)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    121c <read_str_array+0xcc>
cmp    %rbp,(%r12)
jb     120a <read_str_array+0xba>
mov    %r13,%r14
mov    %rbp,%r13
add    %rbp,%r13
shl    $0x4,%ebp
mov    (%rsp),%rdi
mov    %ebp,%esi
call   1040 <realloc@plt>
mov    %rax,(%rsp)
mov    %r13,%rbp
mov    %r14,%r13
mov    %rbx,%rdi
call   1070 <str_len@plt>
cmp    %rax,(%r15)
jae    11b0 <read_str_array+0x60>
mov    %rax,(%r15)
jmp    11b0 <read_str_array+0x60>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i8** @read_str_array(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i8*
store i64* %0, i64** %3
store i64* %1, i64** %4
store i64 8, i64* %6
%9 = load i64, i64* %6
%10 = mul i64 8, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8**
store i8** %13, i8*** %7
%14 = call i64 @malloc(i32 256)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %8
%16 = load i64*, i64** %3
store i64 0, i64* %16
br label %17
17: ; preds = %44, %2
%18 = load i8*, i8** %8
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %64
21: ; preds = %17
%22 = load i64*, i64** %3
%23 = load i64, i64* %22
%24 = load i64, i64* %6
%25 = icmp uge i64 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %21
%27 = load i64, i64* %6
%28 = mul i64 %27, 2
store i64 %28, i64* %6
%29 = load i8**, i8*** %7
%30 = load i64, i64* %6
%31 = mul i64 8, %30
%32 = trunc i64 %31 to i32
%33 = call i8** @realloc(i8** %29, i32 %32)
store i8** %33, i8*** %7
br label %34
34: ; preds = %26, %21
%35 = load i8*, i8** %8
%36 = call i64 @str_len(i8* %35)
store i64 %36, i64* %5
%37 = load i64*, i64** %4
%38 = load i64, i64* %37
%39 = load i64, i64* %5
%40 = icmp ult i64 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i64, i64* %5
%43 = load i64*, i64** %4
store i64 %42, i64* %43
br label %44
44: ; preds = %41, %34
%45 = load i64, i64* %5
%46 = mul i64 1, %45
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8*
%50 = load i8**, i8*** %7
%51 = load i64*, i64** %3
%52 = load i64, i64* %51
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
store i8* %49, i8** %53
%54 = load i8**, i8*** %7
%55 = load i64*, i64** %3
%56 = load i64, i64* %55
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = load i8*, i8** %8
%60 = call i32 @str_copy(i8* %58, i8* %59)
%61 = load i64*, i64** %3
%62 = load i64, i64* %61
%63 = add i64 %62, 1
store i64 %63, i64* %61
br label %17
64: ; preds = %17
%65 = load i8**, i8*** %7
ret i8** %65
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i8** @read_str_array(i64* nocapture %0, i64* nocapture %1) {
%3 = tail call i64 @malloc(i32 64)
%4 = inttoptr i64 %3 to i8**
%5 = tail call i64 @malloc(i32 256)
%6 = inttoptr i64 %5 to i8*
store i64 0, i64* %0
%7 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %37
9: ; preds = %2, %26
%10 = phi i64 [ %21, %26 ], [ 8, %2 ]
%11 = phi i8** [ %20, %26 ], [ %4, %2 ]
%12 = load i64, i64* %0
%13 = icmp ult i64 %12, %10
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = shl i64 %10, 1
%16 = trunc i64 %10 to i32
%17 = shl i32 %16, 4
%18 = tail call i8** @realloc(i8** %11, i32 %17)
br label %19
19: ; preds = %14, %9
%20 = phi i8** [ %18, %14 ], [ %11, %9 ]
%21 = phi i64 [ %15, %14 ], [ %10, %9 ]
%22 = tail call i64 @str_len(i8* %6)
%23 = load i64, i64* %1
%24 = icmp ult i64 %23, %22
br i1 %24, label %25, label %26
25: ; preds = %19
store i64 %22, i64* %1
br label %26
26: ; preds = %25, %19
%27 = trunc i64 %22 to i32
%28 = tail call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
%30 = load i64, i64* %0
%31 = getelementptr inbounds i8*, i8** %20, i64 %30
store i8* %29, i8** %31
%32 = tail call i32 @str_copy(i8* %29, i8* %6)
%33 = load i64, i64* %0
%34 = add i64 %33, 1
store i64 %34, i64* %0
%35 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%36 = icmp eq i32 %35, 1
br i1 %36, label %9, label %37
37: ; preds = %26, %2
%38 = phi i8** [ %4, %2 ], [ %20, %26 ]
ret i8** %38
}