#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*/ read_vector_from_file(char *, int, int, float *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int);
void read_data_from_file(char *data_folder, int *persons, int num_of_persons,
                         int num_of_categories, int num_of_examples,
                         int num_of_points, int dim, float *data_vectors,
                         int *class_labels, int *total_num_of_vectors,
                         int max_number_of_vectors) {
  int cat_id, person_id, example_id, person_i;
  char filename[301];
  int i = 0;
  int dim2 = dim;
  for (person_i = 0; person_i < num_of_persons; person_i++) {
    person_id = persons[person_i];
    for (cat_id = 1; cat_id <= num_of_categories; cat_id++) {
      for (example_id = 1; example_id <= num_of_examples; example_id++) {
        sprintf(filename, "%s/data_%d_%d_%d.txt", data_folder, person_id,
                cat_id, example_id);
        read_vector_from_file(filename, dim, dim2, data_vectors + i * dim2);
        class_labels[i] = cat_id;
        i = i + 1;
        if (i == max_number_of_vectors) {
          *total_num_of_vectors = i;
          return;
        }
      }
    }
  }
  *total_num_of_vectors = i;
}


x86 assembly (clang, -O0):
<read_data_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
movl   $0x0,-0x164(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,-0x168(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1277 <read_data_from_file+0x157>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1264 <read_data_from_file+0x144>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1251 <read_data_from_file+0x131>
lea    -0x160(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
lea    0xe36(%rip),%rsi
call   1030 <sprintf@plt>
lea    -0x160(%rbp),%rdi
mov    0x10(%rbp),%esi
mov    -0x168(%rbp),%edx
mov    0x18(%rbp),%rcx
mov    -0x164(%rbp),%eax
imul   -0x168(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rcx
call   1040 <read_vector_from_file@plt>
mov    -0x24(%rbp),%edx
mov    0x20(%rbp),%rax
movslq -0x164(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x164(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x164(%rbp)
mov    -0x164(%rbp),%eax
cmp    0x30(%rbp),%eax
jne    123e <read_data_from_file+0x11e>
mov    -0x164(%rbp),%ecx
mov    0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    1283 <read_data_from_file+0x163>
jmp    1243 <read_data_from_file+0x123>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a1 <read_data_from_file+0x81>
jmp    1256 <read_data_from_file+0x136>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118e <read_data_from_file+0x6e>
jmp    1269 <read_data_from_file+0x149>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    116d <read_data_from_file+0x4d>
mov    -0x164(%rbp),%ecx
mov    0x28(%rbp),%rax
mov    %ecx,(%rax)
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%rsp
mov    %rdi,0x58(%rsp)
test   %edx,%edx
jle    12b7 <read_data_from_file+0x197>
mov    0x1e0(%rsp),%r9
mov    0x1d8(%rsp),%rbp
movslq 0x1d0(%rsp),%rbx
mov    %edx,%eax
mov    %rax,0x20(%rsp)
lea    0x0(,%rbx,4),%rax
mov    %rax,0x50(%rsp)
mov    %r8d,%eax
mov    %rax,0x48(%rsp)
mov    $0x1,%edi
sub    0x1f0(%rsp),%edi
xor    %eax,%eax
xor    %edx,%edx
mov    %rsi,0x28(%rsp)
test   %ecx,%ecx
mov    %rax,0x40(%rsp)
jle    1290 <read_data_from_file+0x170>
mov    (%rsi,%rax,4),%eax
mov    %eax,0x14(%rsp)
mov    $0x1,%r12d
mov    %r8d,0x10(%rsp)
mov    %ecx,0xc(%rsp)
mov    %rbx,0x38(%rsp)
mov    %rdi,0x30(%rsp)
jmp    11d1 <read_data_from_file+0xb1>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%r12),%eax
cmp    %ecx,%r12d
mov    %eax,%r12d
je     1290 <read_data_from_file+0x170>
test   %r8d,%r8d
jle    11c0 <read_data_from_file+0xa0>
mov    %rdx,0x18(%rsp)
movslq %edx,%rax
mov    %rbx,%rcx
imul   %rax,%rcx
lea    0x0(,%rcx,4),%r13
add    %rbp,%r13
lea    (%r9,%rax,4),%rbx
mov    %eax,%r14d
add    %rdi,%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
lea    0x1(%rbp),%r9d
lea    0x60(%rsp),%r15
mov    %r15,%rdi
lea    0xded(%rip),%rsi
mov    0x58(%rsp),%rdx
mov    0x14(%rsp),%ecx
mov    %r12d,%r8d
call   1030 <sprintf@plt>
mov    %r15,%rdi
mov    0x1d0(%rsp),%edx
mov    %edx,%esi
mov    %r13,%rcx
call   1040 <read_vector_from_file@plt>
mov    %r12d,(%rbx,%rbp,4)
mov    %r14d,%eax
add    %ebp,%eax
je     12ab <read_data_from_file+0x18b>
add    0x50(%rsp),%r13
add    $0x1,%rbp
cmp    %ebp,0x48(%rsp)
jne    1200 <read_data_from_file+0xe0>
mov    0x18(%rsp),%rdx
add    %ebp,%edx
mov    0x10(%rsp),%r8d
mov    0xc(%rsp),%ecx
mov    0x1e0(%rsp),%r9
mov    0x1d8(%rsp),%rbp
mov    0x38(%rsp),%rbx
mov    0x30(%rsp),%rdi
jmp    11c0 <read_data_from_file+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x40(%rsp),%rax
add    $0x1,%rax
cmp    0x20(%rsp),%rax
mov    0x28(%rsp),%rsi
jne    1187 <read_data_from_file+0x67>
jmp    12b9 <read_data_from_file+0x199>
mov    0x18(%rsp),%rdx
add    %ebp,%edx
add    $0x1,%edx
jmp    12b9 <read_data_from_file+0x199>
xor    %edx,%edx
mov    0x1e8(%rsp),%rax
mov    %edx,(%rax)
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%s/data_%d_%d_%d.txt\00"
define void @read_data_from_file(i8* %0, i32* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, float* %7, i32* %8, i32* %9, i32 %10) {
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca float*
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca [301 x i8]
%28 = alloca i32
%29 = alloca i32
store i8* %0, i8** %12
store i32* %1, i32** %13
store i32 %2, i32* %14
store i32 %3, i32* %15
store i32 %4, i32* %16
store i32 %5, i32* %17
store i32 %6, i32* %18
store float* %7, float** %19
store i32* %8, i32** %20
store i32* %9, i32** %21
store i32 %10, i32* %22
store i32 0, i32* %28
%30 = load i32, i32* %18
store i32 %30, i32* %29
store i32 0, i32* %26
br label %31
31: ; preds = %89, %11
%32 = load i32, i32* %26
%33 = load i32, i32* %14
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %92
35: ; preds = %31
%36 = load i32*, i32** %13
%37 = load i32, i32* %26
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
store i32 %40, i32* %24
store i32 1, i32* %23
br label %41
41: ; preds = %85, %35
%42 = load i32, i32* %23
%43 = load i32, i32* %15
%44 = icmp sle i32 %42, %43
br i1 %44, label %45, label %88
45: ; preds = %41
store i32 1, i32* %25
br label %46
46: ; preds = %81, %45
%47 = load i32, i32* %25
%48 = load i32, i32* %16
%49 = icmp sle i32 %47, %48
br i1 %49, label %50, label %84
50: ; preds = %46
%51 = getelementptr inbounds [301 x i8], [301 x i8]* %27, i64 0, i64 0
%52 = load i8*, i8** %12
%53 = load i32, i32* %24
%54 = load i32, i32* %23
%55 = load i32, i32* %25
%56 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %52, i32 %53, i32 %54, i32 %55)
%57 = getelementptr inbounds [301 x i8], [301 x i8]* %27, i64 0, i64 0
%58 = load i32, i32* %18
%59 = load i32, i32* %29
%60 = load float*, float** %19
%61 = load i32, i32* %28
%62 = load i32, i32* %29
%63 = mul nsw i32 %61, %62
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds float, float* %60, i64 %64
%66 = call i32 @read_vector_from_file(i8* %57, i32 %58, i32 %59, float* %65)
%67 = load i32, i32* %23
%68 = load i32*, i32** %20
%69 = load i32, i32* %28
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
store i32 %67, i32* %71
%72 = load i32, i32* %28
%73 = add nsw i32 %72, 1
store i32 %73, i32* %28
%74 = load i32, i32* %28
%75 = load i32, i32* %22
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %80
77: ; preds = %50
%78 = load i32, i32* %28
%79 = load i32*, i32** %21
store i32 %78, i32* %79
br label %95
80: ; preds = %50
br label %81
81: ; preds = %80
%82 = load i32, i32* %25
%83 = add nsw i32 %82, 1
store i32 %83, i32* %25
br label %46
84: ; preds = %46
br label %85
85: ; preds = %84
%86 = load i32, i32* %23
%87 = add nsw i32 %86, 1
store i32 %87, i32* %23
br label %41
88: ; preds = %41
br label %89
89: ; preds = %88
%90 = load i32, i32* %26
%91 = add nsw i32 %90, 1
store i32 %91, i32* %26
br label %31
92: ; preds = %31
%93 = load i32, i32* %28
%94 = load i32*, i32** %21
store i32 %93, i32* %94
br label %95
95: ; preds = %92, %77
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"%s/data_%d_%d_%d.txt\00"
define void @read_data_from_file(i8* %0, i32* nocapture %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, float* %7, i32* nocapture writeonly %8, i32* nocapture writeonly %9, i32 %10) {
%12 = alloca [301 x i8]
%13 = getelementptr inbounds [301 x i8], [301 x i8]* %12, i64 0, i64 0
%14 = icmp sgt i32 %2, 0
br i1 %14, label %15, label %56
15: ; preds = %11
%16 = icmp slt i32 %3, 1
%17 = icmp slt i32 %4, 1
%18 = sext i32 %6 to i64
%19 = zext i32 %2 to i64
br label %20
20: ; preds = %15, %50
%21 = phi i64 [ 0, %15 ], [ %52, %50 ]
%22 = phi i32 [ 0, %15 ], [ %51, %50 ]
%23 = getelementptr inbounds i32, i32* %1, i64 %21
%24 = load i32, i32* %23
br i1 %16, label %50, label %25
25: ; preds = %20, %46
%26 = phi i32 [ %48, %46 ], [ 1, %20 ]
%27 = phi i32 [ %47, %46 ], [ %22, %20 ]
br i1 %17, label %46, label %28
28: ; preds = %25
%29 = sext i32 %27 to i64
%30 = sub i32 %10, %27
br label %34
31: ; preds = %34
%32 = add nuw i32 %36, 1
%33 = icmp eq i32 %36, %4
br i1 %33, label %44, label %34
34: ; preds = %28, %31
%35 = phi i64 [ %29, %28 ], [ %42, %31 ]
%36 = phi i32 [ 1, %28 ], [ %32, %31 ]
%37 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %24, i32 %26, i32 %36)
%38 = mul nsw i64 %35, %18
%39 = getelementptr inbounds float, float* %7, i64 %38
%40 = call i32 @read_vector_from_file(i8* %13, i32 %6, i32 %6, float* %39)
%41 = getelementptr inbounds i32, i32* %8, i64 %35
store i32 %26, i32* %41
%42 = add nsw i64 %35, 1
%43 = icmp eq i32 %36, %30
br i1 %43, label %54, label %31
44: ; preds = %31
%45 = trunc i64 %42 to i32
br label %46
46: ; preds = %44, %25
%47 = phi i32 [ %27, %25 ], [ %45, %44 ]
%48 = add nuw i32 %26, 1
%49 = icmp eq i32 %26, %3
br i1 %49, label %50, label %25
50: ; preds = %46, %20
%51 = phi i32 [ %22, %20 ], [ %47, %46 ]
%52 = add nuw nsw i64 %21, 1
%53 = icmp eq i64 %52, %19
br i1 %53, label %56, label %20
54: ; preds = %34
%55 = trunc i64 %42 to i32
br label %56
56: ; preds = %50, %54, %11
%57 = phi i32 [ 0, %11 ], [ %55, %54 ], [ %51, %50 ]
store i32 %57, i32* %9
ret void
}