#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int *malloc(int);
char *next_line(char **, size_t *, int /*<<< orphan*/ *);
char *strtok(char *, char *);
void load_folds(char *fold_file, int fold, int n_instances,
                int **train_instances, int *n_train, int **test_instances,
                int *n_test) {
  int i, j;
  FILE *input;
  char *buffer, *line, *tok;
  size_t bufsz;
  int *train, *test;
  bool in_test;
  train = malloc(n_instances * sizeof(int));
  test = malloc(n_instances * sizeof(int));
  input = fopen(fold_file, "r");
  buffer = NULL;
  bufsz = 0;
  for (line = NULL, i = 0; i < fold; ++i)
    line = next_line(&buffer, &bufsz, input);
  fclose(input);
  *n_train = *n_test = 0;
  for (tok = strtok(line, "\t"); tok; tok = strtok(NULL, "\t")) {
    test[(*n_test)++] = atoi(tok) - 1;
  }
  free(buffer);
  buffer = line = tok = NULL;
  bufsz = 0;
  for (i = 0; i < n_instances; ++i) {
    for (in_test = false, j = 0; j < *n_test && !in_test; ++j)
      in_test = (i == test[j]);
    if (!in_test)
      train[(*n_train)++] = i;
  }
  *train_instances = train;
  *test_instances = test;
}


x86 assembly (clang, -O0):
<load_folds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x60(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121a <load_folds+0xaa>
mov    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1050 <next_line@plt>
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11eb <load_folds+0x7b>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x48(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1294 <load_folds+0x124>
mov    -0x50(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%edx
sub    $0x1,%edx
mov    -0x68(%rbp),%rax
mov    0x10(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd7c(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x50(%rbp)
jmp    124b <load_folds+0xdb>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x58(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    136c <load_folds+0x1fc>
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%ecx
mov    0x10(%rbp),%rdx
xor    %eax,%eax
cmp    (%rdx),%ecx
mov    %al,-0x6d(%rbp)
jge    12fe <load_folds+0x18e>
cmpl   $0x0,-0x6c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x6d(%rbp)
mov    -0x6d(%rbp),%al
test   $0x1,%al
jne    130e <load_folds+0x19e>
jmp    1335 <load_folds+0x1c5>
mov    -0x2c(%rbp),%eax
mov    -0x68(%rbp),%rcx
movslq -0x30(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12de <load_folds+0x16e>
cmpl   $0x0,-0x6c(%rbp)
jne    1359 <load_folds+0x1e9>
mov    -0x2c(%rbp),%edx
mov    -0x60(%rbp),%rax
mov    -0x20(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    135e <load_folds+0x1ee>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12c4 <load_folds+0x154>
mov    -0x60(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x68(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_folds>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r12
mov    %r8,0x28(%rsp)
mov    %rcx,%r13
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rdx,0x20(%rsp)
lea    0x0(,%rdx,4),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
movq   $0x0,(%rsp)
movq   $0x0,0x30(%rsp)
test   %r14d,%r14d
jle    1213 <load_folds+0xa3>
mov    %r13,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %rsp,%r12
lea    0x30(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <next_line@plt>
add    $0xffffffff,%r14d
jne    11f0 <load_folds+0x80>
mov    %rax,%rbx
mov    0x10(%rsp),%r12
mov    0x8(%rsp),%r13
jmp    1215 <load_folds+0xa5>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x70(%rsp),%r15
movl   $0x0,(%r15)
mov    0x28(%rsp),%r14
movl   $0x0,(%r14)
lea    0xdc6(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     1277 <load_folds+0x107>
lea    0xdb2(%rip),%rbx
mov    %rax,%rdi
call   1090 <atoi@plt>
add    $0xffffffff,%eax
movslq (%r15),%rcx
lea    0x1(%rcx),%edx
mov    %edx,(%r15)
mov    %eax,0x0(%rbp,%rcx,4)
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
jne    1250 <load_folds+0xe0>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
test   %edi,%edi
mov    0x18(%rsp),%rbx
jle    12d7 <load_folds+0x167>
xor    %eax,%eax
jmp    12b3 <load_folds+0x143>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq (%r14),%rcx
lea    0x1(%rcx),%edx
mov    %edx,(%r14)
mov    %eax,(%rbx,%rcx,4)
add    $0x1,%eax
cmp    %edi,%eax
je     12d7 <load_folds+0x167>
mov    (%r15),%ecx
test   %ecx,%ecx
jle    12a0 <load_folds+0x130>
mov    $0x1,%edx
nop
mov    -0x4(%rbp,%rdx,4),%esi
cmp    %rcx,%rdx
jae    12d1 <load_folds+0x161>
add    $0x1,%rdx
cmp    %esi,%eax
jne    12c0 <load_folds+0x150>
cmp    %esi,%eax
jne    12a0 <load_folds+0x130>
jmp    12ac <load_folds+0x13c>
mov    %rbx,0x0(%r13)
mov    %rbp,(%r12)
add    $0x38,%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 = [2 x i8] c"\09\00"
define void @load_folds(i8* %0, i32 %1, i32 %2, i32** %3, i32* %4, i32** %5, i32* %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32**
%12 = alloca i32*
%13 = alloca i32**
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i64
%22 = alloca i32*
%23 = alloca i32*
%24 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32** %3, i32*** %11
store i32* %4, i32** %12
store i32** %5, i32*** %13
store i32* %6, i32** %14
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i32* @malloc(i32 %28)
store i32* %29, i32** %22
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call i32* @malloc(i32 %33)
store i32* %34, i32** %23
%35 = load i8*, i8** %8
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %36, i32** %17
store i8* null, i8** %18
store i64 0, i64* %21
store i8* null, i8** %19
store i32 0, i32* %15
br label %37
37: ; preds = %44, %7
%38 = load i32, i32* %15
%39 = load i32, i32* %9
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i32*, i32** %17
%43 = call i8* @next_line(i8** %18, i64* %21, i32* %42)
store i8* %43, i8** %19
br label %44
44: ; preds = %41
%45 = load i32, i32* %15
%46 = add nsw i32 %45, 1
store i32 %46, i32* %15
br label %37
47: ; preds = %37
%48 = load i32*, i32** %17
%49 = call i32 @fclose(i32* %48)
%50 = load i32*, i32** %14
store i32 0, i32* %50
%51 = load i32*, i32** %12
store i32 0, i32* %51
%52 = load i8*, i8** %19
%53 = call i8* @strtok(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %53, i8** %20
br label %54
54: ; preds = %67, %47
%55 = load i8*, i8** %20
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %69
57: ; preds = %54
%58 = load i8*, i8** %20
%59 = call i32 @atoi(i8* %58)
%60 = sub nsw i32 %59, 1
%61 = load i32*, i32** %23
%62 = load i32*, i32** %14
%63 = load i32, i32* %62
%64 = add nsw i32 %63, 1
store i32 %64, i32* %62
%65 = sext i32 %63 to i64
%66 = getelementptr inbounds i32, i32* %61, i64 %65
store i32 %60, i32* %66
br label %67
67: ; preds = %57
%68 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %68, i8** %20
br label %54
69: ; preds = %54
%70 = load i8*, i8** %18
%71 = call i32 @free(i8* %70)
store i8* null, i8** %20
store i8* null, i8** %19
store i8* null, i8** %18
store i64 0, i64* %21
store i32 0, i32* %15
br label %72
72: ; preds = %112, %69
%73 = load i32, i32* %15
%74 = load i32, i32* %10
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %115
76: ; preds = %72
store i32 0, i32* %24
store i32 0, i32* %16
br label %77
77: ; preds = %97, %76
%78 = load i32, i32* %16
%79 = load i32*, i32** %14
%80 = load i32, i32* %79
%81 = icmp slt i32 %78, %80
br i1 %81, label %82, label %86
82: ; preds = %77
%83 = load i32, i32* %24
%84 = icmp ne i32 %83, 0
%85 = xor i1 %84, true
br label %86
86: ; preds = %82, %77
%87 = phi i1 [ false, %77 ], [ %85, %82 ]
br i1 %87, label %88, label %100
88: ; preds = %86
%89 = load i32, i32* %15
%90 = load i32*, i32** %23
%91 = load i32, i32* %16
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i32, i32* %90, i64 %92
%94 = load i32, i32* %93
%95 = icmp eq i32 %89, %94
%96 = zext i1 %95 to i32
store i32 %96, i32* %24
br label %97
97: ; preds = %88
%98 = load i32, i32* %16
%99 = add nsw i32 %98, 1
store i32 %99, i32* %16
br label %77
100: ; preds = %86
%101 = load i32, i32* %24
%102 = icmp ne i32 %101, 0
br i1 %102, label %111, label %103
103: ; preds = %100
%104 = load i32, i32* %15
%105 = load i32*, i32** %22
%106 = load i32*, i32** %12
%107 = load i32, i32* %106
%108 = add nsw i32 %107, 1
store i32 %108, i32* %106
%109 = sext i32 %107 to i64
%110 = getelementptr inbounds i32, i32* %105, i64 %109
store i32 %104, i32* %110
br label %111
111: ; preds = %103, %100
br label %112
112: ; preds = %111
%113 = load i32, i32* %15
%114 = add nsw i32 %113, 1
store i32 %114, i32* %15
br label %72
115: ; preds = %72
%116 = load i32*, i32** %22
%117 = load i32**, i32*** %11
store i32* %116, i32** %117
%118 = load i32*, i32** %23
%119 = load i32**, i32*** %13
store i32* %118, i32** %119
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"\09\00"
define void @load_folds(i8* nocapture %0, i32 %1, i32 %2, i32** nocapture writeonly %3, i32* nocapture %4, i32** nocapture writeonly %5, i32* nocapture %6) {
%8 = alloca i8*
%9 = alloca i64
%10 = bitcast i8** %8 to i8*
%11 = bitcast i64* %9 to i8*
%12 = shl i32 %2, 2
%13 = tail call i32* @malloc(i32 %12)
%14 = tail call i32* @malloc(i32 %12)
%15 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %8
store i64 0, i64* %9
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %22
17: ; preds = %7, %17
%18 = phi i32 [ %20, %17 ], [ 0, %7 ]
%19 = call i8* @next_line(i8** %8, i64* %9, i32* %15)
%20 = add nuw nsw i32 %18, 1
%21 = icmp eq i32 %20, %1
br i1 %21, label %22, label %17
22: ; preds = %17, %7
%23 = phi i8* [ null, %7 ], [ %19, %17 ]
%24 = call i32 @fclose(i32* %15)
store i32 0, i32* %6
store i32 0, i32* %4
%25 = call i8* @strtok(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %37, label %27
27: ; preds = %22, %27
%28 = phi i8* [ %35, %27 ], [ %25, %22 ]
%29 = call i32 @atoi(i8* %28)
%30 = add nsw i32 %29, -1
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i32, i32* %14, i64 %33
store i32 %30, i32* %34
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %27
37: ; preds = %27, %22
%38 = load i8*, i8** %8
%39 = call i32 @free(i8* %38)
%40 = icmp sgt i32 %2, 0
br i1 %40, label %41, label %64
41: ; preds = %37, %61
%42 = phi i32 [ %62, %61 ], [ 0, %37 ]
%43 = load i32, i32* %6
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %41
%46 = zext i32 %43 to i64
br label %47
47: ; preds = %45, %47
%48 = phi i64 [ 0, %45 ], [ %52, %47 ]
%49 = getelementptr inbounds i32, i32* %14, i64 %48
%50 = load i32, i32* %49
%51 = icmp ne i32 %42, %50
%52 = add nuw nsw i64 %48, 1
%53 = icmp ult i64 %52, %46
%54 = select i1 %53, i1 %51, i1 false
br i1 %54, label %47, label %55
55: ; preds = %47
br i1 %51, label %56, label %61
56: ; preds = %41, %55
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds i32, i32* %13, i64 %59
store i32 %42, i32* %60
br label %61
61: ; preds = %55, %56
%62 = add nuw nsw i32 %42, 1
%63 = icmp eq i32 %62, %2
br i1 %63, label %64, label %41
64: ; preds = %61, %37
store i32* %13, i32** %3
store i32* %14, i32** %5
ret void
}