#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 /*<<< orphan*/ SEEK_SET;
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fileerror(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ openerror(char const *);
scalar_t__ strstr(char *, char *);
FILE *openandfindlastbeefens(const char *filename, char *buf) {
  FILE *f;
  unsigned long int u, lastu;
  f = fopen(filename, "r");
  if (!f)
    openerror(filename);
  u = 1;
  while (fgets(buf, 65536, f) && !strstr(buf, "BEEFens"))
    u++;
  if (!strstr(buf, "ensemble energies"))
    fileerror(filename, f);
  do {
    lastu = u;
    u++;
    while (fgets(buf, 65536, f) && !strstr(buf, "BEEFens"))
      u++;
  } while (strstr(buf, "ensemble energies"));
  if (fseek(f, 0, SEEK_SET))
    fileerror(filename, f);
  for (u = 0; u < lastu; u++)
    fgets(buf, 65536, f);
  return f;
}


x86 assembly (clang, -O0):
<openandfindlastbeefens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1198 <openandfindlastbeefens+0x38>
mov    -0x8(%rbp),%rdi
call   1030 <openerror@plt>
movq   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x10000,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     11e0 <openandfindlastbeefens+0x80>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11f0 <openandfindlastbeefens+0x90>
jmp    1201 <openandfindlastbeefens+0xa1>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a0 <openandfindlastbeefens+0x40>
mov    -0x10(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
jne    1228 <openandfindlastbeefens+0xc8>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <fileerror@plt>
jmp    122d <openandfindlastbeefens+0xcd>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x10000,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2a(%rbp)
je     1281 <openandfindlastbeefens+0x121>
mov    -0x10(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1291 <openandfindlastbeefens+0x131>
jmp    12a2 <openandfindlastbeefens+0x142>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1241 <openandfindlastbeefens+0xe1>
jmp    12a7 <openandfindlastbeefens+0x147>
mov    -0x10(%rbp),%rdi
lea    0xd58(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
jne    122d <openandfindlastbeefens+0xcd>
mov    -0x18(%rbp),%rdi
mov    0x2d14(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
cmp    $0x0,%rax
je     12ec <openandfindlastbeefens+0x18c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <fileerror@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1325 <openandfindlastbeefens+0x1c5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x10000,%esi
call   1040 <fgets@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12f4 <openandfindlastbeefens+0x194>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openandfindlastbeefens>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    118d <openandfindlastbeefens+0x2d>
mov    %r15,%rdi
call   1030 <openerror@plt>
mov    %rbx,%rdi
mov    $0x10000,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11d9 <openandfindlastbeefens+0x79>
lea    0xe54(%rip),%r12
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
jne    11d9 <openandfindlastbeefens+0x79>
add    $0x1,%rbp
mov    %rbx,%rdi
mov    $0x10000,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11b0 <openandfindlastbeefens+0x50>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
jne    11f8 <openandfindlastbeefens+0x98>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <fileerror@plt>
mov    %r15,(%rsp)
lea    0xe07(%rip),%r12
lea    0xdf8(%rip),%r13
jmp    1220 <openandfindlastbeefens+0xc0>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     125e <openandfindlastbeefens+0xfe>
mov    %rbp,%r15
lea    0x1(%rbp),%rcx
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rbp
mov    %rbx,%rdi
mov    $0x10000,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1210 <openandfindlastbeefens+0xb0>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strstr@plt>
lea    0x1(%rbp),%rcx
test   %rax,%rax
je     1230 <openandfindlastbeefens+0xd0>
jmp    1210 <openandfindlastbeefens+0xb0>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
test   %rax,%rax
je     1282 <openandfindlastbeefens+0x122>
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1070 <fileerror@plt>
test   %r15,%r15
je     12a6 <openandfindlastbeefens+0x146>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x10000,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0xffffffffffffffff,%r15
jne    1290 <openandfindlastbeefens+0x130>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"BEEFens\00"
@.str.2 = [18 x i8] c"ensemble energies\00"
@SEEK_SET = global i32 0
define i32* @openandfindlastbeefens(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @openerror(i8* %13)
br label %15
15: ; preds = %12, %2
store i64 1, i64* %6
br label %16
16: ; preds = %28, %15
%17 = load i8*, i8** %4
%18 = load i32*, i32** %5
%19 = call i64 @fgets(i8* %17, i32 65536, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i64 @strstr(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
%25 = xor i1 %24, true
br label %26
26: ; preds = %21, %16
%27 = phi i1 [ false, %16 ], [ %25, %21 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i64, i64* %6
%30 = add i64 %29, 1
store i64 %30, i64* %6
br label %16
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = call i64 @strstr(i8* %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = load i8*, i8** %3
%37 = load i32*, i32** %5
%38 = call i32 @fileerror(i8* %36, i32* %37)
br label %39
39: ; preds = %35, %31
br label %40
40: ; preds = %60, %39
%41 = load i64, i64* %6
store i64 %41, i64* %7
%42 = load i64, i64* %6
%43 = add i64 %42, 1
store i64 %43, i64* %6
br label %44
44: ; preds = %56, %40
%45 = load i8*, i8** %4
%46 = load i32*, i32** %5
%47 = call i64 @fgets(i8* %45, i32 65536, i32* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i8*, i8** %4
%51 = call i64 @strstr(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%52 = icmp ne i64 %51, 0
%53 = xor i1 %52, true
br label %54
54: ; preds = %49, %44
%55 = phi i1 [ false, %44 ], [ %53, %49 ]
br i1 %55, label %56, label %59
56: ; preds = %54
%57 = load i64, i64* %6
%58 = add i64 %57, 1
store i64 %58, i64* %6
br label %44
59: ; preds = %54
br label %60
60: ; preds = %59
%61 = load i8*, i8** %4
%62 = call i64 @strstr(i8* %61, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%63 = icmp ne i64 %62, 0
br i1 %63, label %40, label %64
64: ; preds = %60
%65 = load i32*, i32** %5
%66 = load i32, i32* @SEEK_SET
%67 = call i64 @fseek(i32* %65, i32 0, i32 %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %64
%70 = load i8*, i8** %3
%71 = load i32*, i32** %5
%72 = call i32 @fileerror(i8* %70, i32* %71)
br label %73
73: ; preds = %69, %64
store i64 0, i64* %6
br label %74
74: ; preds = %82, %73
%75 = load i64, i64* %6
%76 = load i64, i64* %7
%77 = icmp ult i64 %75, %76
br i1 %77, label %78, label %85
78: ; preds = %74
%79 = load i8*, i8** %4
%80 = load i32*, i32** %5
%81 = call i64 @fgets(i8* %79, i32 65536, i32* %80)
br label %82
82: ; preds = %78
%83 = load i64, i64* %6
%84 = add i64 %83, 1
store i64 %84, i64* %6
br label %74
85: ; preds = %74
%86 = load i32*, i32** %5
ret i32* %86
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"BEEFens\00"
@.str.2 = [18 x i8] c"ensemble energies\00"
@SEEK_SET = global i32 0
define i32* @openandfindlastbeefens(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @openerror(i8* %0)
br label %7
7: ; preds = %5, %2
%8 = tail call i64 @fgets(i8* %1, i32 65536, i32* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %7, %14
%11 = phi i64 [ %15, %14 ], [ 1, %7 ]
%12 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = add i64 %11, 1
%16 = tail call i64 @fgets(i8* %1, i32 65536, i32* %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %14, %7
%19 = phi i64 [ 1, %7 ], [ %15, %14 ], [ %11, %10 ]
%20 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @fileerror(i8* %0, i32* %3)
br label %24
24: ; preds = %22, %18
br label %25
25: ; preds = %24, %35
%26 = phi i64 [ %29, %35 ], [ %19, %24 ]
br label %27
27: ; preds = %32, %25
%28 = phi i64 [ %26, %25 ], [ %29, %32 ]
%29 = add i64 %28, 1
%30 = tail call i64 @fgets(i8* %1, i32 65536, i32* %3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %27, label %35
35: ; preds = %32, %27
%36 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %25
38: ; preds = %35
%39 = load i32, i32* @SEEK_SET
%40 = tail call i64 @fseek(i32* %3, i32 0, i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = tail call i32 @fileerror(i8* %0, i32* %3)
br label %44
44: ; preds = %42, %38
%45 = icmp eq i64 %26, 0
br i1 %45, label %51, label %46
46: ; preds = %44, %46
%47 = phi i64 [ %49, %46 ], [ 0, %44 ]
%48 = tail call i64 @fgets(i8* %1, i32 65536, i32* %3)
%49 = add nuw i64 %47, 1
%50 = icmp eq i64 %49, %26
br i1 %50, label %51, label %46
51: ; preds = %46, %44
ret i32* %3
}