#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*/ exit(int);
void *malloc(int);
int /*<<< orphan*/ printf(char *);
void allocate(char ***strings, int size) {
  int i = 0;
  int j = 0;
  *strings = malloc(sizeof(char *) * size);
  if (*strings == NULL) {
    printf("Failed to allocate memory\n");
    exit(1);
  }
  for (; i < size; ++i) {
    (*strings)[i] = malloc(sizeof(char) * 25);
    if ((*strings)[i] == NULL) {
      printf("Failed to allocate memory\n");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<allocate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    118a <allocate+0x5a>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    118f <allocate+0x5f>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f6 <allocate+0xc6>
mov    $0x19,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11e3 <allocate+0xb3>
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    11e8 <allocate+0xb8>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118f <allocate+0x5f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     118d <allocate+0x5d>
test   %r15d,%r15d
jle    1181 <allocate+0x51>
mov    %rax,%r12
mov    %r15d,%r15d
xor    %ebx,%ebx
mov    $0x19,%edi
call   1040 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
mov    (%r14),%r12
cmpq   $0x0,(%r12,%rbx,8)
je     118d <allocate+0x5d>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <allocate+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Failed to allocate memory\0A\00"
define void @allocate(i8*** %0, i32 %1) {
%3 = alloca i8***
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8*** %0, i8**** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
%12 = bitcast i8* %11 to i8**
%13 = load i8***, i8**** %3
store i8** %12, i8*** %13
%14 = load i8***, i8**** %3
%15 = load i8**, i8*** %14
%16 = icmp eq i8** %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
br label %21
21: ; preds = %43, %20
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %46
25: ; preds = %21
%26 = call i8* @malloc(i32 25)
%27 = load i8***, i8**** %3
%28 = load i8**, i8*** %27
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
store i8* %26, i8** %31
%32 = load i8***, i8**** %3
%33 = load i8**, i8*** %32
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %25
%40 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %25
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %21
46: ; preds = %21
ret void
}

LLVM IR (-O2):
@str.1 = [26 x i8] c"Failed to allocate memory\00"
define void @allocate(i8*** nocapture %0, i32 %1) {
%3 = shl i32 %1, 3
%4 = tail call i8* @malloc(i32 %3)
%5 = bitcast i8*** %0 to i8**
store i8* %4, i8** %5
%6 = icmp eq i8* %4, null
%7 = bitcast i8* %4 to i8**
br i1 %6, label %12, label %8
8: ; preds = %2
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %30
10: ; preds = %8
%11 = zext i32 %1 to i64
br label %17
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %17
%16 = icmp eq i64 %26, %11
br i1 %16, label %30, label %17
17: ; preds = %10, %15
%18 = phi i8** [ %7, %10 ], [ %22, %15 ]
%19 = phi i64 [ 0, %10 ], [ %26, %15 ]
%20 = tail call dereferenceable_or_null(25) i8* @malloc(i32 25)
%21 = getelementptr inbounds i8*, i8** %18, i64 %19
store i8* %20, i8** %21
%22 = load i8**, i8*** %0
%23 = getelementptr inbounds i8*, i8** %22, i64 %19
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
%26 = add nuw nsw i64 %19, 1
br i1 %25, label %27, label %15
27: ; preds = %17
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.1, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %15, %8
ret void
}