#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*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int);
scalar_t__ strncmp(char *, char *, int);
int chk_gmvend(FILE *fin) {
  int i, chkend;
  long int currpos;
  char rdend[21];
  currpos = 8;
  fseek(fin, -20L, 2);
  fread(rdend, sizeof(char), 20, fin);
  chkend = 0;
  for (i = 0; i < 15; i++)
    if (strncmp((rdend + i), "endgmv", 6) == 0)
      chkend = 1;
  fseek(fin, currpos, 0);
  return chkend;
}


x86 assembly (clang, -O0):
<chk_gmvend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x8,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xffffffffffffffec,%rsi
mov    $0x2,%edx
call   1050 <fseek@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x14,%edx
call   1040 <fread@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xf,-0xc(%rbp)
jge    11c8 <chk_gmvend+0x98>
lea    -0x30(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xe66(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b5 <chk_gmvend+0x85>
movl   $0x1,-0x10(%rbp)
jmp    11ba <chk_gmvend+0x8a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117e <chk_gmvend+0x4e>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1050 <fseek@plt>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chk_gmvend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
mov    %rdi,0x30(%rsp)
mov    $0xffffffffffffffec,%rsi
mov    $0x2,%edx
call   1050 <fseek@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x14,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0xe88(%rip),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0xf(%rsp)
lea    0x11(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0xe(%rsp)
lea    0x12(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0xd(%rsp)
lea    0x13(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   %bl
lea    0x14(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0xc(%rsp)
lea    0x15(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0xb(%rsp)
lea    0x16(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0xa(%rsp)
lea    0x17(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   %r12b
lea    0x18(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0x9(%rsp)
lea    0x19(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0x8(%rsp)
lea    0x1a(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   %r13b
lea    0x1b(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   0x7(%rsp)
lea    0x1c(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   %r14b
lea    0x1d(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   %r15b
lea    0x1e(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
sete   %al
or     %r15b,%al
or     0x7(%rsp),%r14b
or     %al,%r14b
or     0x8(%rsp),%r13b
or     0x9(%rsp),%r13b
or     %r14b,%r13b
or     0xa(%rsp),%r12b
or     0xb(%rsp),%r12b
or     0xc(%rsp),%r12b
or     %r13b,%r12b
or     0xd(%rsp),%bl
or     0xe(%rsp),%bl
or     0xf(%rsp),%bl
or     %r12b,%bl
movzbl %bl,%ebx
and    $0x1,%ebx
mov    $0x8,%esi
mov    0x30(%rsp),%rdi
xor    %edx,%edx
call   1050 <fseek@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"endgmv\00"
define i32 @chk_gmvend(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [21 x i8]
store i32* %0, i32** %2
store i64 8, i64* %5
%7 = load i32*, i32** %2
%8 = call i32 @fseek(i32* %7, i64 -20, i32 2)
%9 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i32 @fread(i8* %9, i32 1, i32 20, i32* %10)
store i32 0, i32* %4
store i32 0, i32* %3
br label %12
12: ; preds = %24, %1
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 15
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 1, i32* %4
br label %23
23: ; preds = %22, %15
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %12
27: ; preds = %12
%28 = load i32*, i32** %2
%29 = load i64, i64* %5
%30 = call i32 @fseek(i32* %28, i64 %29, i32 0)
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@.str = [7 x i8] c"endgmv\00"
define i32 @chk_gmvend(i32* nocapture %0) {
%2 = alloca [21 x i8]
%3 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @fseek(i32* %0, i64 -20, i32 2)
%5 = call i32 @fread(i8* %3, i32 1, i32 20, i32* %0)
%6 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%7 = icmp eq i64 %6, 0
%8 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 1
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%10 = icmp eq i64 %9, 0
%11 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 2
%12 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 3
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%16 = icmp eq i64 %15, 0
%17 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 4
%18 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%19 = icmp eq i64 %18, 0
%20 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 5
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%22 = icmp eq i64 %21, 0
%23 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 6
%24 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%25 = icmp eq i64 %24, 0
%26 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 7
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%28 = icmp eq i64 %27, 0
%29 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 8
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%31 = icmp eq i64 %30, 0
%32 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 9
%33 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%34 = icmp eq i64 %33, 0
%35 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 10
%36 = call i64 @strncmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%37 = icmp eq i64 %36, 0
%38 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 11
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%40 = icmp eq i64 %39, 0
%41 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 12
%42 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%43 = icmp eq i64 %42, 0
%44 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 13
%45 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%46 = icmp eq i64 %45, 0
%47 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 14
%48 = call i64 @strncmp(i8* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%49 = icmp eq i64 %48, 0
%50 = select i1 %49, i1 true, i1 %46
%51 = select i1 %50, i1 true, i1 %43
%52 = select i1 %51, i1 true, i1 %40
%53 = select i1 %52, i1 true, i1 %37
%54 = select i1 %53, i1 true, i1 %34
%55 = select i1 %54, i1 true, i1 %31
%56 = select i1 %55, i1 true, i1 %28
%57 = select i1 %56, i1 true, i1 %25
%58 = select i1 %57, i1 true, i1 %22
%59 = select i1 %58, i1 true, i1 %19
%60 = select i1 %59, i1 true, i1 %16
%61 = select i1 %60, i1 true, i1 %13
%62 = select i1 %61, i1 true, i1 %10
%63 = select i1 %62, i1 true, i1 %7
%64 = zext i1 %63 to i32
%65 = call i32 @fseek(i32* %0, i64 8, i32 0)
ret i32 %64
}