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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ my_getline(char *, int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ namecmp(char *, char const *, int);
int strlen(char const *);
FILE *open_index(const char *indexname, const char *name) {
  char line[1024];
  FILE *f;
  int len = strlen(name);
  f = fopen(indexname, "r");
  if (f != NULL) {
    while (my_getline(line, sizeof(line), f, 1)) {
      if (*line == '[' && line[1 + len] == ']' &&
          !namecmp(line + 1, name, len)) {
        return f;
      }
    }
    fclose(f);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<open_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     1233 <open_index+0xe3>
jmp    119c <open_index+0x4c>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
mov    $0x1,%ecx
call   1070 <my_getline@plt>
cmp    $0x0,%rax
je     1227 <open_index+0xd7>
movsbl -0x420(%rbp),%eax
cmp    $0x5b,%eax
jne    1222 <open_index+0xd2>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x5d,%eax
jne    1222 <open_index+0xd2>
lea    -0x420(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x42c(%rbp),%edx
call   1050 <namecmp@plt>
cmp    $0x0,%eax
jne    1222 <open_index+0xd2>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123b <open_index+0xeb>
jmp    119c <open_index+0x4c>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_index>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f4 <open_index+0xa4>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
mov    $0x1,%ecx
call   1070 <my_getline@plt>
test   %rax,%rax
je     11ec <open_index+0x9c>
movslq %r12d,%r13
lea    0x1(%rsp),%r15
mov    %rsp,%rbp
jmp    11ca <open_index+0x7a>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1070 <my_getline@plt>
test   %rax,%rax
je     11ec <open_index+0x9c>
cmpb   $0x5b,(%rsp)
jne    11b0 <open_index+0x60>
cmpb   $0x5d,0x1(%rsp,%r13,1)
jne    11b0 <open_index+0x60>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <namecmp@plt>
test   %eax,%eax
jne    11b0 <open_index+0x60>
jmp    11f6 <open_index+0xa6>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32* @open_index(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %47
15: ; preds = %2
br label %16
16: ; preds = %43, %15
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %7
%19 = call i64 @my_getline(i8* %17, i32 1024, i32* %18, i32 1)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %44
21: ; preds = %16
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 91
br i1 %25, label %26, label %43
26: ; preds = %21
%27 = load i32, i32* %8
%28 = add nsw i32 1, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 93
br i1 %33, label %34, label %43
34: ; preds = %26
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8*, i8** %5
%38 = load i32, i32* %8
%39 = call i32 @namecmp(i8* %36, i8* %37, i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %34
%42 = load i32*, i32** %7
store i32* %42, i32** %3
br label %48
43: ; preds = %34, %26, %21
br label %16
44: ; preds = %16
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %44, %2
store i32* null, i32** %3
br label %48
48: ; preds = %47, %41
%49 = load i32*, i32** %3
ret i32* %49
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32* @open_index(i8* nocapture %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %30, label %8
8: ; preds = %2
%9 = call i64 @my_getline(i8* %4, i32 1024, i32* %6, i32 1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %8
%12 = add nsw i32 %5, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %13
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
br label %16
16: ; preds = %11, %25
%17 = load i8, i8* %4
%18 = icmp eq i8 %17, 91
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8, i8* %14
%21 = icmp eq i8 %20, 93
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 @namecmp(i8* %15, i8* %1, i32 %5)
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22, %19, %16
%26 = call i64 @my_getline(i8* %4, i32 1024, i32* %6, i32 1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %16
28: ; preds = %25, %8
%29 = call i32 @fclose(i32* %6)
br label %30
30: ; preds = %22, %2, %28
%31 = phi i32* [ null, %28 ], [ null, %2 ], [ %6, %22 ]
ret i32* %31
}