#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
char *strstr(char *, char *);
int gamess_get_nmodes_nbas(int *nmodes, int *nbas) {
  char line[82], *pos;
  FILE *fp;
  if ((fp = fopen("output", "r")) != NULL) {
    while (fgets(line, 80, fp) != NULL)
      if ((pos = strstr(line, "NZVAR =")) != NULL) {
        *nmodes = atoi(pos + 8);
      } else if ((pos = strstr(line, "NGRID=")) != NULL) {
        *nbas = atoi(pos + 8);
      }
  } else {
    printf("Can not open \'output\' GAMESS output file, exiting \n");
    exit(1);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<gamess_get_nmodes_nbas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe76(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x80(%rbp)
cmp    $0x0,%rax
je     123f <gamess_get_nmodes_nbas+0xcf>
jmp    11a9 <gamess_get_nmodes_nbas+0x39>
lea    -0x70(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     123a <gamess_get_nmodes_nbas+0xca>
lea    -0x70(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
je     11fd <gamess_get_nmodes_nbas+0x8d>
mov    -0x78(%rbp),%rdi
add    $0x8,%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1235 <gamess_get_nmodes_nbas+0xc5>
lea    -0x70(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
je     1230 <gamess_get_nmodes_nbas+0xc0>
mov    -0x78(%rbp),%rdi
add    $0x8,%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1235 <gamess_get_nmodes_nbas+0xc5>
jmp    11a9 <gamess_get_nmodes_nbas+0x39>
jmp    1255 <gamess_get_nmodes_nbas+0xe5>
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x80(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gamess_get_nmodes_nbas>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe75(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1239 <gamess_get_nmodes_nbas+0xc9>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1220 <gamess_get_nmodes_nbas+0xb0>
lea    0xe4a(%rip),%r12
mov    %rsp,%rbx
jmp    11f4 <gamess_get_nmodes_nbas+0x84>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x8,%rax
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,(%r15)
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1220 <gamess_get_nmodes_nbas+0xb0>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
mov    %rbp,%r15
test   %rax,%rax
jne    11d0 <gamess_get_nmodes_nbas+0x60>
mov    %rbx,%rdi
lea    0xe00(%rip),%rsi
call   1090 <strstr@plt>
mov    %r14,%r15
test   %rax,%rax
jne    11d0 <gamess_get_nmodes_nbas+0x60>
jmp    11df <gamess_get_nmodes_nbas+0x6f>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"output\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"NZVAR =\00"
@.str.3 = [7 x i8] c"NGRID=\00"
@.str.4 = [52 x i8] c"Can not open 'output' GAMESS output file, exiting \0A\00"
define i32 @gamess_get_nmodes_nbas(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [82 x i8]
%6 = alloca i8*
%7 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%8 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %37
10: ; preds = %2
br label %11
11: ; preds = %35, %10
%12 = getelementptr inbounds [82 x i8], [82 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %7
%14 = call i32* @fgets(i8* %12, i32 80, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %36
16: ; preds = %11
%17 = getelementptr inbounds [82 x i8], [82 x i8]* %5, i64 0, i64 0
%18 = call i8* @strstr(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 8
%23 = call i32 @atoi(i8* %22)
%24 = load i32*, i32** %3
store i32 %23, i32* %24
br label %35
25: ; preds = %16
%26 = getelementptr inbounds [82 x i8], [82 x i8]* %5, i64 0, i64 0
%27 = call i8* @strstr(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i8* %27, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 8
%32 = call i32 @atoi(i8* %31)
%33 = load i32*, i32** %4
store i32 %32, i32* %33
br label %34
34: ; preds = %29, %25
br label %35
35: ; preds = %34, %20
br label %11
36: ; preds = %11
br label %40
37: ; preds = %2
%38 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %36
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"output\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"NZVAR =\00"
@.str.3 = [7 x i8] c"NGRID=\00"
@str = [51 x i8] c"Can not open 'output' GAMESS output file, exiting \00"
define i32 @gamess_get_nmodes_nbas(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca [82 x i8]
%4 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %24, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 80, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %27, label %10
10: ; preds = %7, %21
%11 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %13, %10
%17 = phi i8* [ %11, %10 ], [ %14, %13 ]
%18 = phi i32* [ %0, %10 ], [ %1, %13 ]
%19 = getelementptr inbounds i8, i8* %17, i64 8
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %18
br label %21
21: ; preds = %16, %13
%22 = call i32* @fgets(i8* %4, i32 80, i32* %5)
%23 = icmp eq i32* %22, null
br i1 %23, label %27, label %10
24: ; preds = %2
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %21, %7
%28 = call i32 @fclose(i32* %5)
ret i32 0
}