#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 */
scalar_t__ IO_Read_BE_ULONG(unsigned long *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int msc_format_check(const char *filename) {
  FILE *fp;
  unsigned long id;
  int ret;
  fp = fopen(filename, "rb");
  if (!fp) {
    ;
    return -1;
  }
  ret = (IO_Read_BE_ULONG(&id, fp) &&
         (id == ((('S' << 24) & 0xff000000) | (('M' << 16) & 0xff0000) |
                 (('S' << 8) & 0xff00) | ('C' & 0xff))));
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<msc_format_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1167 <msc_format_check+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <msc_format_check+0x7e>
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1040 <IO_Read_BE_ULONG@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
je     1194 <msc_format_check+0x64>
cmpq   $0x534d5343,-0x20(%rbp)
53
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msc_format_check>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1172 <msc_format_check+0x42>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %rax,%rsi
call   1040 <IO_Read_BE_ULONG@plt>
test   %rax,%rax
setne  %al
cmpq   $0x534d5343,(%rsp)
53
sete   %cl
and    %al,%cl
movzbl %cl,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1177 <msc_format_check+0x47>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @msc_format_check(i8* nocapture %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = call i64 @IO_Read_BE_ULONG(i64* %2, i32* %4)
%8 = icmp ne i64 %7, 0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 1397576515
%11 = select i1 %8, i1 %10, i1 false
%12 = zext i1 %11 to i32
%13 = call i32 @fclose(i32* %4)
br label %14
14: ; preds = %1, %6
%15 = phi i32 [ %12, %6 ], [ -1, %1 ]
ret i32 %15
}