#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 */
int /*<<< orphan*/ check_file_handle(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
void load_weight_matrix(char *weight_matrix_filename, int motif_length,
                        float **weight_matrix) {
  FILE *weight_matrix_file;
  int i, j;
  float temp_float;
  weight_matrix_file = fopen(weight_matrix_filename, "r");
  check_file_handle(weight_matrix_file, weight_matrix_filename);
  for (i = 1; i <= 4; i++) {
    for (j = 1; j <= motif_length; j++) {
      fscanf(weight_matrix_file, "%f\n", &temp_float);
      weight_matrix[i][j] = temp_float;
    }
  }
  fclose(weight_matrix_file);
}


x86 assembly (clang, -O0):
<load_weight_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <check_file_handle@plt>
movl   $0x1,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jg     11e7 <load_weight_matrix+0xa7>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11d4 <load_weight_matrix+0x94>
mov    -0x20(%rbp),%rdi
lea    0xe5f(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <fscanf@plt>
movss  -0x2c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118c <load_weight_matrix+0x4c>
jmp    11d9 <load_weight_matrix+0x99>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117b <load_weight_matrix+0x3b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_weight_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <check_file_handle@plt>
test   %ebp,%ebp
jle    1296 <load_weight_matrix+0x156>
mov    %rbp,0x10(%rsp)
lea    0x1(%rbp),%eax
mov    %eax,%ebp
mov    $0x1,%r15d
lea    0xe73(%rip),%rbx
lea    0xc(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
movss  0xc(%rsp),%xmm0
mov    0x8(%r14),%rax
movss  %xmm0,(%rax,%r15,4)
add    $0x1,%r15
cmp    %r15,%rbp
jne    11a0 <load_weight_matrix+0x60>
cmpl   $0x0,0x10(%rsp)
jle    1296 <load_weight_matrix+0x156>
mov    $0x1,%ebx
lea    0xe24(%rip),%r15
lea    0xc(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
movss  0xc(%rsp),%xmm0
mov    0x10(%r14),%rax
movss  %xmm0,(%rax,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11f0 <load_weight_matrix+0xb0>
cmpl   $0x0,0x10(%rsp)
jle    1296 <load_weight_matrix+0x156>
mov    $0x1,%ebx
lea    0xdd9(%rip),%r15
lea    0xc(%rsp),%r13
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
movss  0xc(%rsp),%xmm0
mov    0x18(%r14),%rax
movss  %xmm0,(%rax,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1230 <load_weight_matrix+0xf0>
cmpl   $0x0,0x10(%rsp)
jle    1296 <load_weight_matrix+0x156>
mov    $0x1,%ebx
lea    0xd99(%rip),%r15
lea    0xc(%rsp),%r13
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
movss  0xc(%rsp),%xmm0
mov    0x20(%r14),%rax
movss  %xmm0,(%rax,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <load_weight_matrix+0x130>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%f\0A\00"
define void @load_weight_matrix(i8* %0, i32 %1, float** nocapture %2) {
%4 = alloca float
%5 = bitcast float* %4 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @check_file_handle(i32* %6, i8* %0)
%8 = icmp slt i32 %1, 1
%9 = add i32 %1, 1
br i1 %8, label %57, label %10
10: ; preds = %3
%11 = getelementptr inbounds float*, float** %2, i64 1
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 1, %10 ], [ %19, %13 ]
%15 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float* %4)
%16 = load float, float* %4
%17 = load float*, float** %11
%18 = getelementptr inbounds float, float* %17, i64 %14
store float %16, float* %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %21, label %13
21: ; preds = %13
br i1 %8, label %57, label %22
22: ; preds = %21
%23 = getelementptr inbounds float*, float** %2, i64 2
%24 = zext i32 %9 to i64
br label %25
25: ; preds = %25, %22
%26 = phi i64 [ 1, %22 ], [ %31, %25 ]
%27 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float* %4)
%28 = load float, float* %4
%29 = load float*, float** %23
%30 = getelementptr inbounds float, float* %29, i64 %26
store float %28, float* %30
%31 = add nuw nsw i64 %26, 1
%32 = icmp eq i64 %31, %24
br i1 %32, label %33, label %25
33: ; preds = %25
br i1 %8, label %57, label %34
34: ; preds = %33
%35 = getelementptr inbounds float*, float** %2, i64 3
%36 = zext i32 %9 to i64
br label %37
37: ; preds = %37, %34
%38 = phi i64 [ 1, %34 ], [ %43, %37 ]
%39 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float* %4)
%40 = load float, float* %4
%41 = load float*, float** %35
%42 = getelementptr inbounds float, float* %41, i64 %38
store float %40, float* %42
%43 = add nuw nsw i64 %38, 1
%44 = icmp eq i64 %43, %36
br i1 %44, label %45, label %37
45: ; preds = %37
br i1 %8, label %57, label %46
46: ; preds = %45
%47 = getelementptr inbounds float*, float** %2, i64 4
%48 = zext i32 %9 to i64
br label %49
49: ; preds = %49, %46
%50 = phi i64 [ 1, %46 ], [ %55, %49 ]
%51 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float* %4)
%52 = load float, float* %4
%53 = load float*, float** %47
%54 = getelementptr inbounds float, float* %53, i64 %50
store float %52, float* %54
%55 = add nuw nsw i64 %50, 1
%56 = icmp eq i64 %55, %48
br i1 %56, label %57, label %49
57: ; preds = %49, %3, %21, %33, %45
%58 = call i32 @fclose(i32* %6)
ret void
}