#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 FILENAME_MAX;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long *);
long ftell(int /*<<< orphan*/ *);
scalar_t__ iscomment(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ query_for_token(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ read_comment(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                                short);
int /*<<< orphan*/ skip_whitespaces(int /*<<< orphan*/ *);
int /*<<< orphan*/ t_error(char *);
long read_index(FILE *inputfile, short print) {
  char buffer[FILENAME_MAX], curl, ocurl = '{', ccurl = '}';
  long buffer_index = 0, pos = 0;
  long blocks;
  if (inputfile == NULL) {
    t_error("You tried to read from a closed file ");
  }
  while (iscomment(buffer, inputfile)) {
    read_comment(inputfile, 0, 50000, print);
  }
  pos = ftell(inputfile);
  skip_whitespaces(inputfile);
  if (query_for_token(inputfile, "index")) {
    skip_whitespaces(inputfile);
    curl = fgetc(inputfile);
    if (curl != ocurl) {
      t_error("A non expected character found");
    }
    fscanf(inputfile, "%ld", &blocks);
    skip_whitespaces(inputfile);
    buffer_index = 0;
    buffer[buffer_index] = fgetc(inputfile);
    buffer_index++;
    if (buffer[buffer_index - 1] == ',') {
      buffer_index--;
      do {
        buffer[buffer_index] = fgetc(inputfile);
        buffer_index++;
      } while (buffer_index < FILENAME_MAX &&
               buffer[buffer_index - 1] != ccurl);
    }
    if (buffer[buffer_index - 1] != ccurl) {
      t_error("Missing closing curl");
    } else {
      buffer[buffer_index - 1] = '\0';
      if (print)
        printf("\nTHIS FILE TYPE %s\n\n", buffer);
    }
  } else {
    printf("No blocks specified. One asci block assumed. \n");
    blocks = 1;
  }
  return blocks;
}


x86 assembly (clang, -O0):
<read_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movb   $0x7b,-0x22(%rbp)
movb   $0x7d,-0x23(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11fe <read_index+0x6e>
lea    0xe07(%rip),%rdi
call   1090 <t_error@plt>
jmp    1203 <read_index+0x73>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10b0 <iscomment@plt>
cmp    $0x0,%rax
je     1233 <read_index+0xa3>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xc350,%edx
movswl -0xa(%rbp),%ecx
call   1080 <read_comment@plt>
jmp    1203 <read_index+0x73>
mov    -0x8(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <skip_whitespaces@plt>
mov    -0x8(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   10a0 <query_for_token@plt>
cmp    $0x0,%rax
je     13ca <read_index+0x23a>
mov    -0x8(%rbp),%rdi
call   1030 <skip_whitespaces@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
movsbl -0x22(%rbp),%ecx
cmp    %ecx,%eax
je     1294 <read_index+0x104>
lea    0xd9d(%rip),%rdi
call   1090 <t_error@plt>
mov    -0x8(%rbp),%rdi
lea    0xdac(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <skip_whitespaces@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,%dl
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    1366 <read_index+0x1d6>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,%dl
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    0x2cbf(%rip),%rax
movslq (%rax),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x49(%rbp)
jge    1356 <read_index+0x1c6>
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x23(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    12fc <read_index+0x16c>
jmp    1366 <read_index+0x1d6>
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x23(%rbp),%ecx
cmp    %ecx,%eax
je     1393 <read_index+0x203>
lea    0xcc6(%rip),%rdi
call   1090 <t_error@plt>
jmp    13c5 <read_index+0x235>
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpw   $0x0,-0xa(%rbp)
je     13c0 <read_index+0x230>
mov    -0x48(%rbp),%rsi
lea    0xcab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13c5 <read_index+0x235>
jmp    13e0 <read_index+0x250>
lea    0xca8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_index>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r12
mov    0x2e2d(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
test   %rdi,%rdi
jne    11e1 <read_index+0x41>
lea    0xe24(%rip),%rdi
call   10a0 <t_error@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   10c0 <iscomment@plt>
test   %rax,%rax
je     1221 <read_index+0x81>
movswl %r14w,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xc350,%edx
mov    %ebx,%ecx
call   1090 <read_comment@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   10c0 <iscomment@plt>
test   %rax,%rax
jne    1200 <read_index+0x60>
mov    %r12,%rdi
call   1080 <ftell@plt>
mov    %r12,%rdi
call   1040 <skip_whitespaces@plt>
lea    0xdee(%rip),%rsi
mov    %r12,%rdi
call   10b0 <query_for_token@plt>
test   %rax,%rax
je     12d7 <read_index+0x137>
mov    %r12,%rdi
call   1040 <skip_whitespaces@plt>
mov    %r12,%rdi
call   1070 <fgetc@plt>
cmp    $0x7b,%al
je     1269 <read_index+0xc9>
lea    0xdc8(%rip),%rdi
call   10a0 <t_error@plt>
lea    0xddb(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    %r12,%rdi
call   1060 <fscanf@plt>
mov    %r12,%rdi
call   1040 <skip_whitespaces@plt>
mov    %r12,%rdi
call   1070 <fgetc@plt>
mov    %al,(%r15)
cmp    $0x2c,%al
jne    12ed <read_index+0x14d>
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <fgetc@plt>
mov    %al,-0x1(%r15,%rbx,1)
lea    0x1(%rbx),%rcx
cmp    $0x7d,%al
je     12c1 <read_index+0x121>
movslq 0x0(%r13),%rdx
cmp    %rdx,%rbx
mov    %rcx,%rbx
jl     12a0 <read_index+0x100>
add    $0xfffffffffffffffe,%rcx
cmp    $0x7d,%al
je     12f3 <read_index+0x153>
lea    0xd7f(%rip),%rdi
call   10a0 <t_error@plt>
jmp    130f <read_index+0x16f>
lea    0xd9b(%rip),%rdi
call   1030 <puts@plt>
movq   $0x1,-0x30(%rbp)
jmp    130f <read_index+0x16f>
xor    %ecx,%ecx
cmp    $0x7d,%al
jne    12c9 <read_index+0x129>
movb   $0x0,(%r15,%rcx,1)
test   %r14w,%r14w
je     130f <read_index+0x16f>
lea    0xd5f(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@.str = [38 x i8] c"You tried to read from a closed file \00"
@.str.1 = [6 x i8] c"index\00"
@.str.2 = [31 x i8] c"A non expected character found\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [21 x i8] c"Missing closing curl\00"
@.str.5 = [21 x i8] c"\0ATHIS FILE TYPE %s\0A\0A\00"
@.str.6 = [47 x i8] c"No blocks specified. One asci block assumed. \0A\00"
define i64 @read_index(i32* %0, i16 signext %1) {
%3 = alloca i32*
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i32* %0, i32** %3
store i16 %1, i16* %4
%13 = load i32, i32* @FILENAME_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %5
%16 = alloca i8, i64 %14
store i64 %14, i64* %6
store i8 123, i8* %8
store i8 125, i8* %9
store i64 0, i64* %10
store i64 0, i64* %11
%17 = load i32*, i32** %3
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @t_error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
br label %22
22: ; preds = %26, %21
%23 = load i32*, i32** %3
%24 = call i64 @iscomment(i8* %16, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32*, i32** %3
%28 = load i16, i16* %4
%29 = call i32 @read_comment(i32* %27, i32 0, i32 50000, i16 signext %28)
br label %22
30: ; preds = %22
%31 = load i32*, i32** %3
%32 = call i64 @ftell(i32* %31)
store i64 %32, i64* %11
%33 = load i32*, i32** %3
%34 = call i32 @skip_whitespaces(i32* %33)
%35 = load i32*, i32** %3
%36 = call i64 @query_for_token(i32* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %115
38: ; preds = %30
%39 = load i32*, i32** %3
%40 = call i32 @skip_whitespaces(i32* %39)
%41 = load i32*, i32** %3
%42 = call signext i8 @fgetc(i32* %41)
store i8 %42, i8* %7
%43 = load i8, i8* %7
%44 = sext i8 %43 to i32
%45 = load i8, i8* %8
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %44, %46
br i1 %47, label %48, label %50
48: ; preds = %38
%49 = call i32 @t_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %38
%51 = load i32*, i32** %3
%52 = call i32 @fscanf(i32* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %12)
%53 = load i32*, i32** %3
%54 = call i32 @skip_whitespaces(i32* %53)
store i64 0, i64* %10
%55 = load i32*, i32** %3
%56 = call signext i8 @fgetc(i32* %55)
%57 = load i64, i64* %10
%58 = getelementptr inbounds i8, i8* %16, i64 %57
store i8 %56, i8* %58
%59 = load i64, i64* %10
%60 = add nsw i64 %59, 1
store i64 %60, i64* %10
%61 = load i64, i64* %10
%62 = sub nsw i64 %61, 1
%63 = getelementptr inbounds i8, i8* %16, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 44
br i1 %66, label %67, label %94
67: ; preds = %50
%68 = load i64, i64* %10
%69 = add nsw i64 %68, -1
store i64 %69, i64* %10
br label %70
70: ; preds = %91, %67
%71 = load i32*, i32** %3
%72 = call signext i8 @fgetc(i32* %71)
%73 = load i64, i64* %10
%74 = getelementptr inbounds i8, i8* %16, i64 %73
store i8 %72, i8* %74
%75 = load i64, i64* %10
%76 = add nsw i64 %75, 1
store i64 %76, i64* %10
br label %77
77: ; preds = %70
%78 = load i64, i64* %10
%79 = load i32, i32* @FILENAME_MAX
%80 = sext i32 %79 to i64
%81 = icmp slt i64 %78, %80
br i1 %81, label %82, label %91
82: ; preds = %77
%83 = load i64, i64* %10
%84 = sub nsw i64 %83, 1
%85 = getelementptr inbounds i8, i8* %16, i64 %84
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = load i8, i8* %9
%89 = sext i8 %88 to i32
%90 = icmp ne i32 %87, %89
br label %91
91: ; preds = %82, %77
%92 = phi i1 [ false, %77 ], [ %90, %82 ]
br i1 %92, label %70, label %93
93: ; preds = %91
br label %94
94: ; preds = %93, %50
%95 = load i64, i64* %10
%96 = sub nsw i64 %95, 1
%97 = getelementptr inbounds i8, i8* %16, i64 %96
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = load i8, i8* %9
%101 = sext i8 %100 to i32
%102 = icmp ne i32 %99, %101
br i1 %102, label %103, label %105
103: ; preds = %94
%104 = call i32 @t_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %114
105: ; preds = %94
%106 = load i64, i64* %10
%107 = sub nsw i64 %106, 1
%108 = getelementptr inbounds i8, i8* %16, i64 %107
store i8 0, i8* %108
%109 = load i16, i16* %4
%110 = icmp ne i16 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %105
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %16)
br label %113
113: ; preds = %111, %105
br label %114
114: ; preds = %113, %103
br label %117
115: ; preds = %30
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0))
store i64 1, i64* %12
br label %117
117: ; preds = %115, %114
%118 = load i64, i64* %12
%119 = load i8*, i8** %5
ret i64 %118
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [38 x i8] c"You tried to read from a closed file \00"
@.str.1 = [6 x i8] c"index\00"
@.str.2 = [31 x i8] c"A non expected character found\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [21 x i8] c"Missing closing curl\00"
@.str.5 = [21 x i8] c"\0ATHIS FILE TYPE %s\0A\0A\00"
@str = [46 x i8] c"No blocks specified. One asci block assumed. \00"
define i64 @read_index(i32* %0, i16 signext %1) {
%3 = alloca i64
%4 = load i32, i32* @FILENAME_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast i64* %3 to i8*
%8 = icmp eq i32* %0, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @t_error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = call i64 @iscomment(i8* %6, i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11, %14
%15 = call i32 @read_comment(i32* %0, i32 0, i32 50000, i16 signext %1)
%16 = call i64 @iscomment(i8* %6, i32* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %14
18: ; preds = %14, %11
%19 = call i64 @ftell(i32* %0)
%20 = call i32 @skip_whitespaces(i32* %0)
%21 = call i64 @query_for_token(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %55, label %23
23: ; preds = %18
%24 = call i32 @skip_whitespaces(i32* %0)
%25 = call signext i8 @fgetc(i32* %0)
%26 = icmp eq i8 %25, 123
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @t_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %3)
%31 = call i32 @skip_whitespaces(i32* %0)
%32 = call signext i8 @fgetc(i32* %0)
store i8 %32, i8* %6
%33 = icmp eq i8 %32, 44
br i1 %33, label %34, label %44
34: ; preds = %29, %34
%35 = phi i64 [ %38, %34 ], [ 0, %29 ]
%36 = call signext i8 @fgetc(i32* %0)
%37 = getelementptr inbounds i8, i8* %6, i64 %35
store i8 %36, i8* %37
%38 = add nuw nsw i64 %35, 1
%39 = load i32, i32* @FILENAME_MAX
%40 = sext i32 %39 to i64
%41 = icmp sge i64 %38, %40
%42 = icmp eq i8 %36, 125
%43 = or i1 %42, %41
br i1 %43, label %44, label %34
44: ; preds = %34, %29
%45 = phi i8 [ %32, %29 ], [ %36, %34 ]
%46 = phi i64 [ 0, %29 ], [ %35, %34 ]
%47 = icmp eq i8 %45, 125
br i1 %47, label %50, label %48
48: ; preds = %44
%49 = call i32 @t_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %57
50: ; preds = %44
%51 = getelementptr inbounds i8, i8* %6, i64 %46
store i8 0, i8* %51
%52 = icmp eq i16 %1, 0
br i1 %52, label %57, label %53
53: ; preds = %50
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %6)
br label %57
55: ; preds = %18
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
store i64 1, i64* %3
br label %57
57: ; preds = %48, %53, %50, %55
%58 = load i64, i64* %3
ret i64 %58
}