#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*/ SEEK_SET;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int NESSetTitle(FILE *ofile, char *title) {
  if (!ofile || !title)
    return 0;
  fseek(ofile,
        16 + (16384 * NESGetPrgBankCount(ofile)) +
            (8192 * NESGetChrBankCount(ofile)),
        SEEK_SET);
  char *newTitle = (char *)malloc(128);
  int i = 0;
  for (i = 0; i < 128; i++) {
    newTitle[i] = 0;
  }
  strcpy(newTitle, title);
  if (fwrite(newTitle, 1, 128, ofile) != 128) {
    free(newTitle);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<NESSetTitle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1196 <NESSetTitle+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <NESSetTitle+0x32>
movl   $0x0,-0x4(%rbp)
jmp    126d <NESSetTitle+0xfd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <NESGetPrgBankCount@plt>
shl    $0xe,%eax
add    $0x10,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <NESGetChrBankCount@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdi
shl    $0xd,%eax
add    %eax,%esi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x80,-0x24(%rbp)
jge    1222 <NESSetTitle+0xb2>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fb <NESSetTitle+0x8b>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80,%edx
call   1090 <fwrite@plt>
cmp    $0x80,%eax
je     1266 <NESSetTitle+0xf6>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    126d <NESSetTitle+0xfd>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NESSetTitle>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     1222 <NESSetTitle+0xb2>
mov    %rsi,%r14
test   %rsi,%rsi
je     1222 <NESSetTitle+0xb2>
mov    %rdi,%r15
call   1060 <NESGetPrgBankCount@plt>
mov    %eax,%ebx
shl    $0xe,%ebx
mov    %r15,%rdi
call   1050 <NESGetChrBankCount@plt>
shl    $0xd,%eax
lea    (%rax,%rbx,1),%esi
add    $0x10,%esi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   1080 <fseek@plt>
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,(%rax)
movups %xmm0,0x10(%rax)
movups %xmm0,0x20(%rax)
movups %xmm0,0x30(%rax)
movups %xmm0,0x40(%rax)
movups %xmm0,0x50(%rax)
movups %xmm0,0x60(%rax)
movups %xmm0,0x70(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
cmp    $0x80,%eax
je     1222 <NESSetTitle+0xb2>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @NESSetTitle(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 0, i32* %3
br label %51
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = load i32*, i32** %4
%17 = call i32 @NESGetPrgBankCount(i32* %16)
%18 = mul nsw i32 16384, %17
%19 = add nsw i32 16, %18
%20 = load i32*, i32** %4
%21 = call i32 @NESGetChrBankCount(i32* %20)
%22 = mul nsw i32 8192, %21
%23 = add nsw i32 %19, %22
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %15, i32 %23, i32 %24)
%26 = call i64 @malloc(i32 128)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %6
store i32 0, i32* %7
store i32 0, i32* %7
br label %28
28: ; preds = %36, %14
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 128
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %31
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %28
39: ; preds = %28
%40 = load i8*, i8** %6
%41 = load i8*, i8** %5
%42 = call i32 @strcpy(i8* %40, i8* %41)
%43 = load i8*, i8** %6
%44 = load i32*, i32** %4
%45 = call i32 @fwrite(i8* %43, i32 1, i32 128, i32* %44)
%46 = icmp ne i32 %45, 128
br i1 %46, label %47, label %50
47: ; preds = %39
%48 = load i8*, i8** %6
%49 = call i32 @free(i8* %48)
store i32 0, i32* %3
br label %51
50: ; preds = %39
store i32 1, i32* %3
br label %51
51: ; preds = %50, %47, %13
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @NESSetTitle(i32* %0, i8* %1) {
%3 = icmp ne i32* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = tail call i32 @NESGetPrgBankCount(i32* %0)
%8 = shl nsw i32 %7, 14
%9 = or i32 %8, 16
%10 = tail call i32 @NESGetChrBankCount(i32* %0)
%11 = shl nsw i32 %10, 13
%12 = add nsw i32 %9, %11
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %0, i32 %12, i32 %13)
%15 = tail call i64 @malloc(i32 128)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @strcpy(i8* %16, i8* %1)
%18 = tail call i32 @fwrite(i8* %16, i32 1, i32 128, i32* %0)
%19 = icmp eq i32 %18, 128
br i1 %19, label %22, label %20
20: ; preds = %6
%21 = tail call i32 @free(i8* %16)
br label %22
22: ; preds = %20, %6, %2
%23 = phi i32 [ 0, %2 ], [ 0, %20 ], [ 1, %6 ]
ret i32 %23
}