#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int count_lines(int /*<<< orphan*/ *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int len_name(char *);
char **malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ zero_array(char *);
char **name_array(FILE *fp) {
  int n_names = count_lines(fp);
  int counter = 0;
  char name[20];
  char **names = malloc(n_names * sizeof(char *));
  zero_array(name);
  while (EOF != fscanf(fp, "%s", name)) {
    names[counter] = (char *)malloc(len_name(name) * sizeof(char));
    for (int i = 0; i < len_name(name); ++i) {
      names[counter][i] = name[i];
    }
    counter++;
  }
  rewind(fp);
  return names;
}


x86 assembly (clang, -O0):
<name_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <count_lines@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1080 <zero_array@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe48(%rip),%rsi
call   1040 <fscanf@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
je     124c <name_array+0xec>
lea    -0x30(%rbp),%rdi
call   1070 <len_name@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x30(%rbp),%rdi
call   1070 <len_name@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jge    123e <name_array+0xde>
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%dl
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f9 <name_array+0x99>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119b <name_array+0x3b>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<name_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
call   1060 <count_lines@plt>
lea    0x0(,%rax,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <zero_array@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%rbp
lea    0xe5f(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
cmp    %rax,%rbp
jne    11cb <name_array+0x6b>
mov    %r15,%rdi
call   1030 <rewind@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    %rsp,%r13
jmp    1205 <name_array+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbp
mov    0x2dfd(%rip),%rax
mov    (%rax),%rbx
mov    %r15,%rdi
lea    0xe08(%rip),%rsi
mov    %r13,%rdx
call   1040 <fscanf@plt>
cmp    %rax,%rbx
je     11b1 <name_array+0x51>
mov    %r13,%rdi
call   1070 <len_name@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14,%rbp,8)
mov    %r13,%rdi
call   1070 <len_name@plt>
test   %eax,%eax
jle    11e0 <name_array+0x80>
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movzbl (%rsp,%r12,1),%eax
mov    %al,(%rbx,%r12,1)
add    $0x1,%r12
mov    %r13,%rdi
call   1070 <len_name@plt>
cltq
cmp    %rax,%r12
jl     1230 <name_array+0xd0>
jmp    11e0 <name_array+0x80>

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

LLVM IR (-O2):
@EOF = global i64 0
@.str = [3 x i8] c"%s\00"
define noalias i8** @name_array(i32* %0) {
%2 = alloca [20 x i8]
%3 = tail call i32 @count_lines(i32* %0)
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = shl i32 %3, 3
%6 = tail call i8** @malloc(i32 %5)
%7 = call i32 @zero_array(i8* %4)
%8 = load i64, i64* @EOF
%9 = call i64 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = icmp eq i64 %8, %9
br i1 %10, label %34, label %11
11: ; preds = %1, %20
%12 = phi i64 [ %21, %20 ], [ 0, %1 ]
%13 = call i32 @len_name(i8* %4)
%14 = call i8** @malloc(i32 %13)
%15 = getelementptr inbounds i8*, i8** %6, i64 %12
%16 = bitcast i8** %15 to i8***
store i8** %14, i8*** %16
%17 = call i32 @len_name(i8* %4)
%18 = icmp sgt i32 %17, 0
%19 = bitcast i8** %14 to i8*
br i1 %18, label %25, label %20
20: ; preds = %25, %11
%21 = add nuw i64 %12, 1
%22 = load i64, i64* @EOF
%23 = call i64 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%24 = icmp eq i64 %22, %23
br i1 %24, label %34, label %11
25: ; preds = %11, %25
%26 = phi i64 [ %30, %25 ], [ 0, %11 ]
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = getelementptr inbounds i8, i8* %19, i64 %26
store i8 %28, i8* %29
%30 = add nuw nsw i64 %26, 1
%31 = call i32 @len_name(i8* %4)
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %25, label %20
34: ; preds = %20, %1
%35 = call i32 @rewind(i32* %0)
ret i8** %6
}