#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 **malloc(int);
int /*<<< orphan*/ xread(int, int *, int);
char *xread_str(int);
int xread_str_array(int fd, char ***s) {
  int i, n;
  xread(fd, &n, sizeof(int));
  *s = malloc(sizeof(char **) * n);
  for (i = 0; i < n; i++)
    (*s)[i] = xread_str(fd);
  return n;
}


x86 assembly (clang, -O0):
<xread_str_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <xread@plt>
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11a4 <xread_str_array+0x74>
mov    -0x4(%rbp),%edi
call   1050 <xread_str@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <xread_str_array+0x40>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xread_str_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <xread@plt>
mov    0x4(%rsp),%ebx
lea    0x0(,%rbx,8),%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
test   %ebx,%ebx
jle    118d <xread_str_array+0x5d>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
call   1050 <xread_str@plt>
mov    (%r14),%rcx
mov    %rax,(%rcx,%rbp,8)
add    $0x1,%rbp
movslq 0x4(%rsp),%rbx
cmp    %rbx,%rbp
jl     1170 <xread_str_array+0x40>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @xread_str_array(i32 %0, i8*** %1) {
%3 = alloca i32
%4 = alloca i8***
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8*** %1, i8**** %4
%7 = load i32, i32* %3
%8 = call i32 @xread(i32 %7, i32* %6, i32 4)
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = mul i64 8, %10
%12 = trunc i64 %11 to i32
%13 = call i8** @malloc(i32 %12)
%14 = load i8***, i8**** %4
store i8** %13, i8*** %14
store i32 0, i32* %5
br label %15
15: ; preds = %27, %2
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i8* @xread_str(i32 %20)
%22 = load i8***, i8**** %4
%23 = load i8**, i8*** %22
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
store i8* %21, i8** %26
br label %27
27: ; preds = %19
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %15
30: ; preds = %15
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
define i32 @xread_str_array(i32 %0, i8*** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @xread(i32 %0, i32* %3, i32 4)
%6 = load i32, i32* %3
%7 = shl i32 %6, 3
%8 = call i8** @malloc(i32 %7)
store i8** %8, i8*** %1
%9 = icmp sgt i32 %6, 0
br i1 %9, label %10, label %19
10: ; preds = %2, %10
%11 = phi i64 [ %15, %10 ], [ 0, %2 ]
%12 = call i8* @xread_str(i32 %0)
%13 = load i8**, i8*** %1
%14 = getelementptr inbounds i8*, i8** %13, i64 %11
store i8* %12, i8** %14
%15 = add nuw nsw i64 %11, 1
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %10, label %19
19: ; preds = %10, %2
%20 = phi i32 [ %6, %2 ], [ %16, %10 ]
ret i32 %20
}