#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 EOF;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(float *, int /*<<< orphan*/, int);
int sscanf(char *, char *, int *, ...);
char *strchr(char *, char);
int readExample(FILE *fp, int maxline, float *example, int nfeat, int *target) {
  int offset, feat, len;
  float val;
  char *line;
  char *comment;
  line = malloc(maxline * sizeof(char));
  memset(example, 0, nfeat * sizeof(float));
  while (fgets(line, maxline, fp) != NULL) {
    comment = strchr(line, '#');
    if (comment != NULL)
      *comment = '\0';
    if (sscanf(line, "%d%n", target, &len) == EOF)
      continue;
    *target = *target <= 0 ? 0 : 1;
    for (offset = len; sscanf(line + offset, "%d:%f%n", &feat, &val, &len) >= 2;
         offset += len) {
      if (feat < nfeat)
        example[feat] = val;
    }
    free(line);
    return 1;
  }
  free(line);
  return 0;
}


x86 assembly (clang, -O0):
<readExample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12a1 <readExample+0x141>
mov    -0x48(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     11e0 <readExample+0x80>
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe11(%rip),%rsi
lea    -0x3c(%rbp),%rcx
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%eax
jne    120e <readExample+0xae>
jmp    11a2 <readExample+0x42>
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    $0x1,%ecx
xor    %eax,%eax
cmp    $0x0,%edx
cmovle %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x48(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
lea    0xdc6(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x3c(%rbp),%r8
mov    $0x0,%al
call   1080 <sscanf@plt>
cmp    $0x2,%eax
jl     128c <readExample+0x12c>
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1279 <readExample+0x119>
movss  -0x40(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    127e <readExample+0x11e>
mov    -0x3c(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    122d <readExample+0xcd>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b1 <readExample+0x151>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readExample>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r13
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r12
mov    %esi,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %r14,0x20(%rsp)
lea    0x0(,%r14,4),%edx
mov    %r15,0x18(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xc(%rsp),%r14
mov    0x2e3a(%rip),%r15
jmp    11cc <readExample+0x6c>
mov    %rbx,%rdi
lea    0xe46(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <sscanf@plt>
cmp    (%r15),%eax
jne    11f9 <readExample+0x99>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1296 <readExample+0x136>
mov    %rbx,%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b0 <readExample+0x50>
movb   $0x0,(%rax)
jmp    11b0 <readExample+0x50>
xor    %eax,%eax
cmpl   $0x0,0x0(%r13)
setg   %al
mov    %eax,0x0(%r13)
movslq 0xc(%rsp),%rbp
lea    (%rbx,%rbp,1),%rdi
lea    0xdee(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
xor    %eax,%eax
call   1080 <sscanf@plt>
mov    $0x1,%r14d
cmp    $0x2,%eax
jl     12a1 <readExample+0x141>
lea    0xdc6(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
jmp    1279 <readExample+0x119>
movslq 0xc(%rsp),%rax
movslq %ebp,%rbp
add    %rax,%rbp
mov    %rbp,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jle    129b <readExample+0x13b>
movslq 0x14(%rsp),%rax
cmp    0x20(%rsp),%eax
jge    1250 <readExample+0xf0>
movss  0x10(%rsp),%xmm0
mov    0x18(%rsp),%rcx
movss  %xmm0,(%rcx,%rax,4)
jmp    1250 <readExample+0xf0>
xor    %r14d,%r14d
jmp    12a1 <readExample+0x141>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%n\00"
@EOF = global i32 0
@.str.1 = [8 x i8] c"%d:%f%n\00"
define i32 @readExample(i32* %0, i32 %1, float* %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca float*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca float
%16 = alloca i8*
%17 = alloca i8*
store i32* %0, i32** %7
store i32 %1, i32* %8
store float* %2, float** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %16
%23 = load float*, float** %9
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i32 @memset(float* %23, i32 0, i32 %27)
br label %29
29: ; preds = %48, %5
%30 = load i8*, i8** %16
%31 = load i32, i32* %8
%32 = load i32*, i32** %7
%33 = call i32* @fgets(i8* %30, i32 %31, i32* %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %82
35: ; preds = %29
%36 = load i8*, i8** %16
%37 = call i8* @strchr(i8* %36, i8 signext 35)
store i8* %37, i8** %17
%38 = load i8*, i8** %17
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = load i8*, i8** %17
store i8 0, i8* %41
br label %42
42: ; preds = %40, %35
%43 = load i8*, i8** %16
%44 = load i32*, i32** %11
%45 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %44, i32* %14)
%46 = load i32, i32* @EOF
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %42
br label %29
49: ; preds = %42
%50 = load i32*, i32** %11
%51 = load i32, i32* %50
%52 = icmp sle i32 %51, 0
%53 = zext i1 %52 to i64
%54 = select i1 %52, i32 0, i32 1
%55 = load i32*, i32** %11
store i32 %54, i32* %55
%56 = load i32, i32* %14
store i32 %56, i32* %12
br label %57
57: ; preds = %75, %49
%58 = load i8*, i8** %16
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %61, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %13, float* %15, i32* %14)
%63 = icmp sge i32 %62, 2
br i1 %63, label %64, label %79
64: ; preds = %57
%65 = load i32, i32* %13
%66 = load i32, i32* %10
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %74
68: ; preds = %64
%69 = load float, float* %15
%70 = load float*, float** %9
%71 = load i32, i32* %13
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds float, float* %70, i64 %72
store float %69, float* %73
br label %74
74: ; preds = %68, %64
br label %75
75: ; preds = %74
%76 = load i32, i32* %14
%77 = load i32, i32* %12
%78 = add nsw i32 %77, %76
store i32 %78, i32* %12
br label %57
79: ; preds = %57
%80 = load i8*, i8** %16
%81 = call i32 @free(i8* %80)
store i32 1, i32* %6
br label %85
82: ; preds = %29
%83 = load i8*, i8** %16
%84 = call i32 @free(i8* %83)
store i32 0, i32* %6
br label %85
85: ; preds = %82, %79
%86 = load i32, i32* %6
ret i32 %86
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%n\00"
@EOF = global i32 0
@.str.1 = [8 x i8] c"%d:%f%n\00"
define i32 @readExample(i32* nocapture %0, i32 %1, float* %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = bitcast float* %8 to i8*
%12 = tail call i8* @malloc(i32 %1)
%13 = shl i32 %3, 2
%14 = tail call i32 @memset(float* %2, i32 0, i32 %13)
br label %15
15: ; preds = %22, %5
%16 = call i32* @fgets(i8* %12, i32 %1, i32* %0)
%17 = icmp eq i32* %16, null
br i1 %17, label %50, label %18
18: ; preds = %15
%19 = call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 35)
%20 = icmp eq i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %18
store i8 0, i8* %19
br label %22
22: ; preds = %21, %18
%23 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %7)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %15, label %26
26: ; preds = %22
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 0
%29 = zext i1 %28 to i32
store i32 %29, i32* %4
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %12, i64 %31
%33 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %6, float* %8, i32* %7)
%34 = icmp sgt i32 %33, 1
br i1 %34, label %35, label %50
35: ; preds = %26, %43
%36 = phi i32 [ %45, %43 ], [ %30, %26 ]
%37 = load i32, i32* %6
%38 = icmp slt i32 %37, %3
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load float, float* %8
%41 = sext i32 %37 to i64
%42 = getelementptr inbounds float, float* %2, i64 %41
store float %40, float* %42
br label %43
43: ; preds = %35, %39
%44 = load i32, i32* %7
%45 = add nsw i32 %44, %36
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %12, i64 %46
%48 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %6, float* %8, i32* %7)
%49 = icmp sgt i32 %48, 1
br i1 %49, label %35, label %50
50: ; preds = %15, %43, %26
%51 = phi i32 [ 1, %26 ], [ 1, %43 ], [ 0, %15 ]
%52 = call i32 @free(i8* %12)
ret i32 %51
}