#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 */
unsigned char *inputWord(unsigned long *);
scalar_t__ malloc(int);
int /*<<< orphan*/ readNumPatterns(unsigned long *, unsigned long *);
void loadPatterns(unsigned char ***patterns, unsigned long **lens,
                  unsigned long *numpatt, unsigned long *numwordsperpattern) {
  unsigned long i;
  readNumPatterns(numpatt, numwordsperpattern);
  unsigned char **pats;
  unsigned long length, *thelens;
  pats = (unsigned char **)malloc(sizeof(unsigned char *) * (*numpatt));
  thelens = (unsigned long *)malloc(sizeof(unsigned long) * (*numpatt));
  for (i = 0; i < (*numpatt); i++) {
    pats[i] = inputWord(&length);
    thelens[i] = length;
  }
  *patterns = pats;
  *lens = thelens;
}


x86 assembly (clang, -O0):
<loadPatterns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <readNumPatterns@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jae    11d3 <loadPatterns+0xa3>
lea    -0x38(%rbp),%rdi
call   1050 <inputWord@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1189 <loadPatterns+0x59>
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadPatterns>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %rsi,0x8(%rsp)
mov    %rdi,%r15
mov    %rdx,%rdi
mov    %rcx,%rsi
call   1030 <readNumPatterns@plt>
mov    (%r12),%edi
shl    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    (%r12),%edi
shl    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
cmpq   $0x0,(%r12)
je     11b0 <loadPatterns+0x80>
xor    %r14d,%r14d
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1050 <inputWord@plt>
mov    %rax,0x0(%r13,%r14,8)
mov    0x10(%rsp),%rax
mov    %rax,(%rbx,%r14,8)
add    $0x1,%r14
cmp    (%r12),%r14
jb     1190 <loadPatterns+0x60>
mov    %r13,(%r15)
mov    0x8(%rsp),%rax
mov    %rbx,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @loadPatterns(i8*** %0, i64** %1, i64* %2, i64* %3) {
%5 = alloca i8***
%6 = alloca i64**
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i8**
%11 = alloca i64
%12 = alloca i64*
store i8*** %0, i8**** %5
store i64** %1, i64*** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
%13 = load i64*, i64** %7
%14 = load i64*, i64** %8
%15 = call i32 @readNumPatterns(i64* %13, i64* %14)
%16 = load i64*, i64** %7
%17 = load i64, i64* %16
%18 = mul i64 8, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8**
store i8** %21, i8*** %10
%22 = load i64*, i64** %7
%23 = load i64, i64* %22
%24 = mul i64 8, %23
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i64*
store i64* %27, i64** %12
store i64 0, i64* %9
br label %28
28: ; preds = %42, %4
%29 = load i64, i64* %9
%30 = load i64*, i64** %7
%31 = load i64, i64* %30
%32 = icmp ult i64 %29, %31
br i1 %32, label %33, label %45
33: ; preds = %28
%34 = call i8* @inputWord(i64* %11)
%35 = load i8**, i8*** %10
%36 = load i64, i64* %9
%37 = getelementptr inbounds i8*, i8** %35, i64 %36
store i8* %34, i8** %37
%38 = load i64, i64* %11
%39 = load i64*, i64** %12
%40 = load i64, i64* %9
%41 = getelementptr inbounds i64, i64* %39, i64 %40
store i64 %38, i64* %41
br label %42
42: ; preds = %33
%43 = load i64, i64* %9
%44 = add i64 %43, 1
store i64 %44, i64* %9
br label %28
45: ; preds = %28
%46 = load i8**, i8*** %10
%47 = load i8***, i8**** %5
store i8** %46, i8*** %47
%48 = load i64*, i64** %12
%49 = load i64**, i64*** %6
store i64* %48, i64** %49
ret void
}

LLVM IR (-O2):
define void @loadPatterns(i8*** nocapture writeonly %0, i64** nocapture writeonly %1, i64* %2, i64* %3) {
%5 = alloca i64
%6 = tail call i32 @readNumPatterns(i64* %2, i64* %3)
%7 = bitcast i64* %5 to i8*
%8 = load i64, i64* %2
%9 = trunc i64 %8 to i32
%10 = shl i32 %9, 3
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8**
%13 = load i64, i64* %2
%14 = trunc i64 %13 to i32
%15 = shl i32 %14, 3
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i64*
%18 = load i64, i64* %2
%19 = icmp eq i64 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %4, %20
%21 = phi i64 [ %26, %20 ], [ 0, %4 ]
%22 = call i8* @inputWord(i64* %5)
%23 = getelementptr inbounds i8*, i8** %12, i64 %21
store i8* %22, i8** %23
%24 = load i64, i64* %5
%25 = getelementptr inbounds i64, i64* %17, i64 %21
store i64 %24, i64* %25
%26 = add nuw i64 %21, 1
%27 = load i64, i64* %2
%28 = icmp ult i64 %26, %27
br i1 %28, label %20, label %29
29: ; preds = %20, %4
store i8** %12, i8*** %0
store i64* %17, i64** %1
ret void
}