#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 NESGetChrBankCount(int /*<<< orphan*/ *);
long NESGetFilesize(int /*<<< orphan*/ *);
int NESGetPrgBankCount(int /*<<< orphan*/ *);
int /*<<< orphan*/ NESGetTitle(char *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int strlen(char *);
int NESHasTitle(FILE *ifile) {
  if (!ifile)
    return 0;
  int PRG_count = NESGetPrgBankCount(ifile);
  int CHR_count = NESGetChrBankCount(ifile);
  long filesize = NESGetFilesize(ifile);
  if (filesize > (16 + PRG_count * 16384 + CHR_count * 8192)) {
    char *title = (char *)malloc(128);
    NESGetTitle(title, ifile, 0);
    int title_length = strlen(title);
    free(title);
    return title_length;
  }
  return 0;
}


x86 assembly (clang, -O0):
<NESHasTitle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <NESHasTitle+0x23>
movl   $0x0,-0x4(%rbp)
jmp    121d <NESHasTitle+0xad>
mov    -0x10(%rbp),%rdi
call   1080 <NESGetPrgBankCount@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <NESGetChrBankCount@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <NESGetFilesize@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0xe,%ecx
add    $0x10,%ecx
mov    -0x18(%rbp),%edx
shl    $0xd,%edx
add    %edx,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jle    1216 <NESHasTitle+0xa6>
mov    $0x80,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1060 <NESGetTitle@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121d <NESHasTitle+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NESHasTitle>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11df <NESHasTitle+0x6f>
mov    %rdi,%r15
call   1080 <NESGetPrgBankCount@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1070 <NESGetChrBankCount@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <NESGetFilesize@plt>
shl    $0xe,%r14d
shl    $0xd,%ebx
lea    (%rbx,%r14,1),%ecx
add    $0x10,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jle    11df <NESHasTitle+0x6f>
mov    $0x80,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1060 <NESGetTitle@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    11e1 <NESHasTitle+0x71>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @NESHasTitle(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i32 0, i32* %2
br label %40
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i32 @NESGetPrgBankCount(i32* %13)
store i32 %14, i32* %4
%15 = load i32*, i32** %3
%16 = call i32 @NESGetChrBankCount(i32* %15)
store i32 %16, i32* %5
%17 = load i32*, i32** %3
%18 = call i64 @NESGetFilesize(i32* %17)
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 16384
%22 = add nsw i32 16, %21
%23 = load i32, i32* %5
%24 = mul nsw i32 %23, 8192
%25 = add nsw i32 %22, %24
%26 = sext i32 %25 to i64
%27 = icmp sgt i64 %19, %26
br i1 %27, label %28, label %39
28: ; preds = %12
%29 = call i64 @malloc(i32 128)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = load i32*, i32** %3
%33 = call i32 @NESGetTitle(i8* %31, i32* %32, i32 0)
%34 = load i8*, i8** %7
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %8
%36 = load i8*, i8** %7
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* %8
store i32 %38, i32* %2
br label %40
39: ; preds = %12
store i32 0, i32* %2
br label %40
40: ; preds = %39, %28, %11
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @NESHasTitle(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = tail call i32 @NESGetPrgBankCount(i32* %0)
%5 = tail call i32 @NESGetChrBankCount(i32* %0)
%6 = tail call i64 @NESGetFilesize(i32* %0)
%7 = shl nsw i32 %4, 14
%8 = or i32 %7, 16
%9 = shl nsw i32 %5, 13
%10 = add nsw i32 %8, %9
%11 = sext i32 %10 to i64
%12 = icmp sgt i64 %6, %11
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = tail call i64 @malloc(i32 128)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @NESGetTitle(i8* %15, i32* %0, i32 0)
%17 = tail call i32 @strlen(i8* %15)
%18 = tail call i32 @free(i8* %15)
br label %19
19: ; preds = %13, %3, %1
%20 = phi i32 [ 0, %1 ], [ %17, %13 ], [ 0, %3 ]
ret i32 %20
}