#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
char *strtok_r(char *, char *, char **);
int VerifyFileFormat(const char *filename, int *d, int *n) {
  FILE *fp = NULL;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    printf("VerifyFileFormat. Error: Cannot open file %s. Function call takes "
           "no effect.\n",
           filename);
    return -1;
  }
  (*n) = 0;
  (*d) = 0;
  char *line = NULL, *str = NULL, *saveptr = NULL, *subtoken = NULL;
  ssize_t read = 0;
  size_t len = 0;
  while ((read = getline(&line, &len, fp)) != -1) {
    (*n)++;
    int cnt = 0, maxdim = 0;
    for (str = line;; str = NULL) {
      subtoken = strtok_r(str, ": ", &saveptr);
      if (subtoken == NULL || !strcmp(subtoken, "\n")) {
        break;
      } else {
        cnt++;
      }
      if (cnt % 2 == 0) {
        int num = atoi(subtoken);
        if (maxdim > num) {
          printf("VerifyFileFormat. Error: Indices in line %d are not in the "
                 "ascending order. Stop reading data. Function call takes no "
                 "effect.\n",
                 (*n));
          fclose(fp);
          return -1;
        } else {
          maxdim = num;
          *d = maxdim;
        }
      }
    }
    if (cnt % 2 != 1) {
      printf("VerifyFileFormat. Error: Line %d does not conform with a LibSVM "
             "format. Stop reading data. Function call takes no effect.\n",
             (*n));
      fclose(fp);
      return -1;
    }
  }
  if (line) {
    free(line);
  }
  fclose(fp);
  if ((*n) == 0) {
    printf("VerifyFileFormat. Error: Empty file!\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<VerifyFileFormat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d9 <VerifyFileFormat+0x59>
mov    -0x10(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <VerifyFileFormat+0x22c>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   10a0 <getline@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0xffffffff,%eax
je     1361 <VerifyFileFormat+0x1e1>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdeb(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1296 <VerifyFileFormat+0x116>
mov    -0x48(%rbp),%rdi
lea    0xee9(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    129b <VerifyFileFormat+0x11b>
jmp    131f <VerifyFileFormat+0x19f>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    130d <VerifyFileFormat+0x18d>
mov    -0x48(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x64(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x64(%rbp),%eax
jle    12f9 <VerifyFileFormat+0x179>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <VerifyFileFormat+0x22c>
mov    -0x64(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    130d <VerifyFileFormat+0x18d>
jmp    1312 <VerifyFileFormat+0x192>
movq   $0x0,-0x38(%rbp)
jmp    125a <VerifyFileFormat+0xda>
mov    -0x5c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
je     135c <VerifyFileFormat+0x1dc>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <VerifyFileFormat+0x22c>
jmp    121c <VerifyFileFormat+0x9c>
cmpq   $0x0,-0x30(%rbp)
je     1375 <VerifyFileFormat+0x1f5>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    13a5 <VerifyFileFormat+0x225>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <VerifyFileFormat+0x22c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VerifyFileFormat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe52(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12b7 <VerifyFileFormat+0x127>
movl   $0x0,(%rbx)
mov    %r14,0x20(%rsp)
movl   $0x0,(%r14)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
movq   $0x0,0x28(%rsp)
lea    0xe5b(%rip),%rbp
lea    0x30(%rsp),%r12
lea    0xecf(%rip),%r13
mov    %rbx,0x18(%rsp)
jmp    121f <VerifyFileFormat+0x8f>
nopl   0x0(%rax,%rax,1)
test   $0x1,%r15b
mov    0x18(%rsp),%rbx
je     12ca <VerifyFileFormat+0x13a>
lea    0x10(%rsp),%rdi
lea    0x28(%rsp),%rsi
mov    0x8(%rsp),%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     12f8 <VerifyFileFormat+0x168>
addl   $0x1,(%rbx)
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1070 <strtok_r@plt>
test   %rax,%rax
je     12ca <VerifyFileFormat+0x13a>
mov    %rax,%r14
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    1279 <VerifyFileFormat+0xe9>
xchg   %ax,%ax
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1070 <strtok_r@plt>
mov    %rax,%r14
add    $0x1,%r15d
test   %rax,%rax
je     1210 <VerifyFileFormat+0x80>
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1210 <VerifyFileFormat+0x80>
lea    0x1(%r15),%eax
test   $0x1,%al
jne    1260 <VerifyFileFormat+0xd0>
mov    %r14,%rdi
call   10a0 <atoi@plt>
cmp    %eax,%ebx
jg     12a7 <VerifyFileFormat+0x117>
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
mov    %eax,%ebx
jmp    1260 <VerifyFileFormat+0xd0>
mov    0x18(%rsp),%rax
mov    (%rax),%esi
lea    0xd9e(%rip),%rdi
jmp    12d3 <VerifyFileFormat+0x143>
lea    0xd44(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12e4 <VerifyFileFormat+0x154>
mov    (%rbx),%esi
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1307 <VerifyFileFormat+0x177>
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
cmpl   $0x0,(%rbx)
jne    12e9 <VerifyFileFormat+0x159>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
jmp    12e4 <VerifyFileFormat+0x154>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [78 x i8] c"VerifyFileFormat. Error: Cannot open file %s. Function call takes no effect.\0A\00"
@.str.2 = [3 x i8] c": \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [127 x i8] c"VerifyFileFormat. Error: Indices in line %d are not in the ascending order. Stop reading data. Function call takes no effect.\0A\00"
@.str.5 = [123 x i8] c"VerifyFileFormat. Error: Line %d does not conform with a LibSVM format. Stop reading data. Function call takes no effect.\0A\00"
@.str.6 = [38 x i8] c"VerifyFileFormat. Error: Empty file!\0A\00"
define i32 @VerifyFileFormat(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* null, i32** %8
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = load i8*, i8** %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 -1, i32* %4
br label %99
25: ; preds = %3
%26 = load i32*, i32** %7
store i32 0, i32* %26
%27 = load i32*, i32** %6
store i32 0, i32* %27
store i8* null, i8** %9
store i8* null, i8** %10
store i8* null, i8** %11
store i8* null, i8** %12
store i32 0, i32* %13
store i64 0, i64* %14
br label %28
28: ; preds = %83, %25
%29 = load i32*, i32** %8
%30 = call i32 @getline(i8** %9, i64* %14, i32* %29)
store i32 %30, i32* %13
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %84
32: ; preds = %28
%33 = load i32*, i32** %7
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
store i32 0, i32* %15
store i32 0, i32* %16
%36 = load i8*, i8** %9
store i8* %36, i8** %10
br label %37
37: ; preds = %72, %32
%38 = load i8*, i8** %10
%39 = call i8* @strtok_r(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %11)
store i8* %39, i8** %12
%40 = load i8*, i8** %12
%41 = icmp eq i8* %40, null
br i1 %41, label %46, label %42
42: ; preds = %37
%43 = load i8*, i8** %12
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %42, %37
br label %73
47: ; preds = %42
%48 = load i32, i32* %15
%49 = add nsw i32 %48, 1
store i32 %49, i32* %15
br label %50
50: ; preds = %47
%51 = load i32, i32* %15
%52 = srem i32 %51, 2
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %71
54: ; preds = %50
%55 = load i8*, i8** %12
%56 = call i32 @atoi(i8* %55)
store i32 %56, i32* %17
%57 = load i32, i32* %16
%58 = load i32, i32* %17
%59 = icmp sgt i32 %57, %58
br i1 %59, label %60, label %66
60: ; preds = %54
%61 = load i32*, i32** %7
%62 = load i32, i32* %61
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str.4, i64 0, i64 0), i32 %62)
%64 = load i32*, i32** %8
%65 = call i32 @fclose(i32* %64)
store i32 -1, i32* %4
br label %99
66: ; preds = %54
%67 = load i32, i32* %17
store i32 %67, i32* %16
%68 = load i32, i32* %16
%69 = load i32*, i32** %6
store i32 %68, i32* %69
br label %70
70: ; preds = %66
br label %71
71: ; preds = %70, %50
br label %72
72: ; preds = %71
store i8* null, i8** %10
br label %37
73: ; preds = %46
%74 = load i32, i32* %15
%75 = srem i32 %74, 2
%76 = icmp ne i32 %75, 1
br i1 %76, label %77, label %83
77: ; preds = %73
%78 = load i32*, i32** %7
%79 = load i32, i32* %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str.5, i64 0, i64 0), i32 %79)
%81 = load i32*, i32** %8
%82 = call i32 @fclose(i32* %81)
store i32 -1, i32* %4
br label %99
83: ; preds = %73
br label %28
84: ; preds = %28
%85 = load i8*, i8** %9
%86 = icmp ne i8* %85, null
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i8*, i8** %9
%89 = call i32 @free(i8* %88)
br label %90
90: ; preds = %87, %84
%91 = load i32*, i32** %8
%92 = call i32 @fclose(i32* %91)
%93 = load i32*, i32** %7
%94 = load i32, i32* %93
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %90
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %4
br label %99
98: ; preds = %90
store i32 0, i32* %4
br label %99
99: ; preds = %98, %96, %77, %60, %22
%100 = load i32, i32* %4
ret i32 %100
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [78 x i8] c"VerifyFileFormat. Error: Cannot open file %s. Function call takes no effect.\0A\00"
@.str.2 = [3 x i8] c": \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [127 x i8] c"VerifyFileFormat. Error: Indices in line %d are not in the ascending order. Stop reading data. Function call takes no effect.\0A\00"
@.str.5 = [123 x i8] c"VerifyFileFormat. Error: Line %d does not conform with a LibSVM format. Stop reading data. Function call takes no effect.\0A\00"
@str = [37 x i8] c"VerifyFileFormat. Error: Empty file!\00"
define i32 @VerifyFileFormat(i8* %0, i32* nocapture writeonly %1, i32* nocapture %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %67
11: ; preds = %3
store i32 0, i32* %2
store i32 0, i32* %1
%12 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%13 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%14 = bitcast i64* %6 to i8*
store i64 0, i64* %6
br label %15
15: ; preds = %46, %11
%16 = call i32 @getline(i8** %4, i64* %6, i32* %7)
%17 = icmp eq i32 %16, -1
br i1 %17, label %54, label %18
18: ; preds = %15
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
%21 = load i8*, i8** %4
%22 = call i8* @strtok_r(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%23 = icmp eq i8* %22, null
br i1 %23, label %50, label %24
24: ; preds = %18, %42
%25 = phi i8* [ %44, %42 ], [ %22, %18 ]
%26 = phi i32 [ %43, %42 ], [ 0, %18 ]
%27 = phi i32 [ %31, %42 ], [ 0, %18 ]
%28 = call i32 @strcmp(i8* %25, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %46, label %30
30: ; preds = %24
%31 = add nuw nsw i32 %27, 1
%32 = and i32 %31, 1
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = call i32 @atoi(i8* %25)
%36 = icmp sgt i32 %26, %35
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i32, i32* %2
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([127 x i8], [127 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = call i32 @fclose(i32* %7)
br label %65
41: ; preds = %34
store i32 %35, i32* %1
br label %42
42: ; preds = %41, %30
%43 = phi i32 [ %35, %41 ], [ %26, %30 ]
%44 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %24
46: ; preds = %24, %42
%47 = phi i32 [ %27, %24 ], [ %31, %42 ]
%48 = and i32 %47, 1
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %15
50: ; preds = %18, %46
%51 = load i32, i32* %2
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([123 x i8], [123 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = call i32 @fclose(i32* %7)
br label %65
54: ; preds = %15
%55 = load i8*, i8** %4
%56 = icmp eq i8* %55, null
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 @free(i8* %55)
br label %59
59: ; preds = %57, %54
%60 = call i32 @fclose(i32* %7)
%61 = load i32, i32* %2
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %65
65: ; preds = %37, %59, %50, %63
%66 = phi i32 [ -1, %63 ], [ -1, %50 ], [ 0, %59 ], [ -1, %37 ]
br label %67
67: ; preds = %65, %9
%68 = phi i32 [ -1, %9 ], [ %66, %65 ]
ret i32 %68
}