#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*/ *);
int NESGetPrgBankCount(int /*<<< orphan*/ *);
int /*<<< orphan*/ NESHasTitle(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
scalar_t__ ftruncate(int /*<<< orphan*/, int);
int NESRemoveTitle(FILE *ofile) {
  if (!ofile)
    return 0;
  if (!NESHasTitle(ofile))
    return 1;
  if (ftruncate(fileno(ofile), 16 + (NESGetPrgBankCount(ofile) * 16384) +
                                   (NESGetChrBankCount(ofile) * 8192)) != 0) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<NESRemoveTitle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <NESRemoveTitle+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <NESRemoveTitle+0x95>
mov    -0x10(%rbp),%rdi
call   1070 <NESHasTitle@plt>
cmp    $0x0,%eax
jne    1191 <NESRemoveTitle+0x41>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <NESRemoveTitle+0x95>
mov    -0x10(%rbp),%rdi
call   1060 <fileno@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <NESGetPrgBankCount@plt>
shl    $0xe,%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <NESGetChrBankCount@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edi
shl    $0xd,%eax
add    %eax,%esi
call   1030 <ftruncate@plt>
cmp    $0x0,%rax
je     11de <NESRemoveTitle+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <NESRemoveTitle+0x95>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NESRemoveTitle>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     11a3 <NESRemoveTitle+0x53>
mov    %rdi,%rbx
call   1070 <NESHasTitle@plt>
test   %eax,%eax
je     11a7 <NESRemoveTitle+0x57>
mov    %rbx,%rdi
call   1060 <fileno@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <NESGetPrgBankCount@plt>
mov    %eax,%ebp
shl    $0xe,%ebp
mov    %rbx,%rdi
call   1040 <NESGetChrBankCount@plt>
shl    $0xd,%eax
lea    (%rax,%rbp,1),%esi
add    $0x10,%esi
mov    %r14d,%edi
call   1030 <ftruncate@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    11ac <NESRemoveTitle+0x5c>
xor    %eax,%eax
jmp    11ac <NESRemoveTitle+0x5c>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @NESRemoveTitle(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
store i32* %0, i32** %3
%4 = load i32*, i32** %3
%5 = icmp ne i32* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i32 0, i32* %2
br label %27
7: ; preds = %1
%8 = load i32*, i32** %3
%9 = call i32 @NESHasTitle(i32* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %7
store i32 1, i32* %2
br label %27
12: ; preds = %7
%13 = load i32*, i32** %3
%14 = call i32 @fileno(i32* %13)
%15 = load i32*, i32** %3
%16 = call i32 @NESGetPrgBankCount(i32* %15)
%17 = mul nsw i32 %16, 16384
%18 = add nsw i32 16, %17
%19 = load i32*, i32** %3
%20 = call i32 @NESGetChrBankCount(i32* %19)
%21 = mul nsw i32 %20, 8192
%22 = add nsw i32 %18, %21
%23 = call i64 @ftruncate(i32 %14, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %12
store i32 0, i32* %2
br label %27
26: ; preds = %12
store i32 1, i32* %2
br label %27
27: ; preds = %26, %25, %11, %6
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @NESRemoveTitle(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = tail call i32 @NESHasTitle(i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = tail call i32 @fileno(i32* %0)
%8 = tail call i32 @NESGetPrgBankCount(i32* %0)
%9 = shl nsw i32 %8, 14
%10 = or i32 %9, 16
%11 = tail call i32 @NESGetChrBankCount(i32* %0)
%12 = shl nsw i32 %11, 13
%13 = add nsw i32 %10, %12
%14 = tail call i64 @ftruncate(i32 %7, i32 %13)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %6, %3, %1
%18 = phi i32 [ 0, %1 ], [ 1, %3 ], [ %16, %6 ]
ret i32 %18
}