#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int mvf_check_format(char *path) {
  FILE *f;
  char buf[5];
  f = fopen(path, "r");
  if (!f)
    return 0;
  if (fread(buf, 1, 5, f) != 5) {
    fclose(f);
    return 0;
  }
  fclose(f);
  buf[4] = 0;
  return (strcmp(buf, "MVF\n") == 0);
}


x86 assembly (clang, -O0):
<mvf_check_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <mvf_check_format+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <mvf_check_format+0x98>
lea    -0x1d(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1030 <fread@plt>
cmp    $0x5,%eax
je     11ac <mvf_check_format+0x6c>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <mvf_check_format+0x98>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movb   $0x0,-0x19(%rbp)
lea    -0x1d(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvf_check_format>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11a5 <mvf_check_format+0x65>
mov    %rax,%rbx
lea    0xb(%rsp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmp    $0x5,%r14d
jne    11a5 <mvf_check_format+0x65>
movb   $0x0,0xf(%rsp)
lea    0xe70(%rip),%rsi
lea    0xb(%rsp),%rdi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"MVF\0A\00"
define i32 @mvf_check_format(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [5 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %27
11: ; preds = %1
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32 @fread(i8* %12, i32 1, i32 5, i32* %13)
%15 = icmp ne i32 %14, 5
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32*, i32** %4
%18 = call i32 @fclose(i32* %17)
store i32 0, i32* %2
br label %27
19: ; preds = %11
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 4
store i8 0, i8* %22
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
store i32 %26, i32* %2
br label %27
27: ; preds = %19, %16, %10
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"MVF\0A\00"
define i32 @mvf_check_format(i8* nocapture %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = call i32 @fread(i8* %3, i32 1, i32 5, i32* %4)
%8 = icmp eq i32 %7, 5
%9 = tail call i32 @fclose(i32* %4)
br i1 %8, label %10, label %15
10: ; preds = %6
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
store i8 0, i8* %11
%12 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %6, %1, %10
%16 = phi i32 [ %14, %10 ], [ 0, %1 ], [ 0, %6 ]
ret i32 %16
}