#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*/ wchar_t;
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *rom_fopen(int /*<<< orphan*/ *, char *);
int rom_load_interleaved(wchar_t *fnl, wchar_t *fnh, uint32_t addr, int sz,
                         int off, uint8_t *ptr) {
  FILE *fl = rom_fopen(fnl, L"rb");
  FILE *fh = rom_fopen(fnh, L"rb");
  int c;
  if (fl == NULL || fh == NULL) {
    if (fl == NULL)
      ;
    else
      (void)fclose(fl);
    if (fh == NULL)
      ;
    else
      (void)fclose(fh);
    return (0);
  }
  if (addr >= 0x40000) {
    addr = 0;
  } else {
    addr &= 0x03ffff;
  }
  if (ptr != NULL) {
    (void)fseek(fl, off, SEEK_SET);
    (void)fseek(fh, off, SEEK_SET);
    for (c = 0; c < sz; c += 2) {
      ptr[addr + c] = fgetc(fl);
      ptr[addr + c + 1] = fgetc(fh);
    }
  }
  (void)fclose(fh);
  (void)fclose(fl);
  return (1);
}


x86 assembly (clang, -O0):
<rom_load_interleaved>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1050 <rom_fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1050 <rom_fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     119c <rom_load_interleaved+0x5c>
cmpq   $0x0,-0x40(%rbp)
jne    11da <rom_load_interleaved+0x9a>
cmpq   $0x0,-0x38(%rbp)
jne    11ac <rom_load_interleaved+0x6c>
jmp    11b5 <rom_load_interleaved+0x75>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x40(%rbp)
jne    11c5 <rom_load_interleaved+0x85>
jmp    11ce <rom_load_interleaved+0x8e>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ab <rom_load_interleaved+0x16b>
cmpl   $0x40000,-0x1c(%rbp)
jl     11f3 <rom_load_interleaved+0xb3>
movl   $0x0,-0x1c(%rbp)
jmp    11fe <rom_load_interleaved+0xbe>
mov    -0x1c(%rbp),%eax
and    $0x3ffff,%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1292 <rom_load_interleaved+0x152>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    128d <rom_load_interleaved+0x14d>
mov    -0x38(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x44(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x40(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x44(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x44(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x44(%rbp)
jmp    123a <rom_load_interleaved+0xfa>
jmp    1292 <rom_load_interleaved+0x152>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rom_load_interleaved>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8d,%ebp
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %rsi,%r14
lea    0xe9f(%rip),%r15
mov    %r15,%rsi
call   1050 <rom_fopen@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <rom_fopen@plt>
mov    %rax,%r14
test   %r13,%r13
je     1218 <rom_load_interleaved+0xd8>
test   %r14,%r14
je     1218 <rom_load_interleaved+0xd8>
mov    %ebx,%eax
and    $0x3ffff,%eax
xor    %r15d,%r15d
cmp    $0x40000,%ebx
cmovl  %eax,%r15d
cmpq   $0x0,(%rsp)
je     1201 <rom_load_interleaved+0xc1>
mov    0x2e32(%rip),%rbx
mov    (%rbx),%edx
mov    %r13,%rdi
mov    %ebp,%esi
call   1060 <fseek@plt>
mov    (%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <fseek@plt>
test   %r12d,%r12d
jle    1201 <rom_load_interleaved+0xc1>
mov    %r15d,%eax
mov    (%rsp),%rcx
lea    (%rcx,%rax,4),%rbp
add    $0x4,%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r13,%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x4(%rbp,%rbx,4)
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,0x0(%rbp,%rbx,4)
add    $0x2,%rbx
cmp    %r12d,%ebx
jl     11e0 <rom_load_interleaved+0xa0>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebx
jmp    1234 <rom_load_interleaved+0xf4>
test   %r13,%r13
je     1225 <rom_load_interleaved+0xe5>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
test   %r14,%r14
je     1234 <rom_load_interleaved+0xf4>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i32] [i32 114, i32 98, i32 0]
@SEEK_SET = global i32 0
define i32 @rom_load_interleaved(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32* %5, i32** %13
%17 = load i32*, i32** %8
%18 = call i32* @rom_fopen(i32* %17, i8* bitcast ([3 x i32]* @.str to i8*))
store i32* %18, i32** %14
%19 = load i32*, i32** %9
%20 = call i32* @rom_fopen(i32* %19, i8* bitcast ([3 x i32]* @.str to i8*))
store i32* %20, i32** %15
%21 = load i32*, i32** %14
%22 = icmp eq i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %6
%24 = load i32*, i32** %15
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %41
26: ; preds = %23, %6
%27 = load i32*, i32** %14
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %26
br label %33
30: ; preds = %26
%31 = load i32*, i32** %14
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %30, %29
%34 = load i32*, i32** %15
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %37
36: ; preds = %33
br label %40
37: ; preds = %33
%38 = load i32*, i32** %15
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %36
store i32 0, i32* %7
br label %91
41: ; preds = %23
%42 = load i32, i32* %10
%43 = icmp sge i32 %42, 262144
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 0, i32* %10
br label %48
45: ; preds = %41
%46 = load i32, i32* %10
%47 = and i32 %46, 262143
store i32 %47, i32* %10
br label %48
48: ; preds = %45, %44
%49 = load i32*, i32** %13
%50 = icmp ne i32* %49, null
br i1 %50, label %51, label %86
51: ; preds = %48
%52 = load i32*, i32** %14
%53 = load i32, i32* %12
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @fseek(i32* %52, i32 %53, i32 %54)
%56 = load i32*, i32** %15
%57 = load i32, i32* %12
%58 = load i32, i32* @SEEK_SET
%59 = call i32 @fseek(i32* %56, i32 %57, i32 %58)
store i32 0, i32* %16
br label %60
60: ; preds = %82, %51
%61 = load i32, i32* %16
%62 = load i32, i32* %11
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %85
64: ; preds = %60
%65 = load i32*, i32** %14
%66 = call i32 @fgetc(i32* %65)
%67 = load i32*, i32** %13
%68 = load i32, i32* %10
%69 = load i32, i32* %16
%70 = add nsw i32 %68, %69
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %67, i64 %71
store i32 %66, i32* %72
%73 = load i32*, i32** %15
%74 = call i32 @fgetc(i32* %73)
%75 = load i32*, i32** %13
%76 = load i32, i32* %10
%77 = load i32, i32* %16
%78 = add nsw i32 %76, %77
%79 = add nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %75, i64 %80
store i32 %74, i32* %81
br label %82
82: ; preds = %64
%83 = load i32, i32* %16
%84 = add nsw i32 %83, 2
store i32 %84, i32* %16
br label %60
85: ; preds = %60
br label %86
86: ; preds = %85, %48
%87 = load i32*, i32** %15
%88 = call i32 @fclose(i32* %87)
%89 = load i32*, i32** %14
%90 = call i32 @fclose(i32* %89)
store i32 1, i32* %7
br label %91
91: ; preds = %86, %40
%92 = load i32, i32* %7
ret i32 %92
}

LLVM IR (-O2):
@.str = [3 x i32] [i32 114, i32 98, i32 0]
@SEEK_SET = global i32 0
define i32 @rom_load_interleaved(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4, i32* writeonly %5) {
%7 = tail call i32* @rom_fopen(i32* %0, i8* bitcast ([3 x i32]* @.str to i8*))
%8 = tail call i32* @rom_fopen(i32* %1, i8* bitcast ([3 x i32]* @.str to i8*))
%9 = icmp eq i32* %7, null
%10 = icmp eq i32* %8, null
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %12, label %18
12: ; preds = %6
br i1 %9, label %15, label %13
13: ; preds = %12
%14 = tail call i32 @fclose(i32* %7)
br label %15
15: ; preds = %12, %13
br i1 %10, label %45, label %16
16: ; preds = %15
%17 = tail call i32 @fclose(i32* %8)
br label %45
18: ; preds = %6
%19 = icmp sgt i32 %2, 262143
%20 = and i32 %2, 262143
%21 = select i1 %19, i32 0, i32 %20
%22 = icmp eq i32* %5, null
br i1 %22, label %42, label %23
23: ; preds = %18
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @fseek(i32* %7, i32 %4, i32 %24)
%26 = load i32, i32* @SEEK_SET
%27 = tail call i32 @fseek(i32* %8, i32 %4, i32 %26)
%28 = icmp sgt i32 %3, 0
br i1 %28, label %29, label %42
29: ; preds = %23
%30 = zext i32 %21 to i64
br label %31
31: ; preds = %29, %31
%32 = phi i64 [ 0, %29 ], [ %39, %31 ]
%33 = tail call i32 @fgetc(i32* %7)
%34 = add nuw nsw i64 %32, %30
%35 = getelementptr inbounds i32, i32* %5, i64 %34
store i32 %33, i32* %35
%36 = tail call i32 @fgetc(i32* %8)
%37 = add nuw nsw i64 %34, 1
%38 = getelementptr inbounds i32, i32* %5, i64 %37
store i32 %36, i32* %38
%39 = add nuw i64 %32, 2
%40 = trunc i64 %39 to i32
%41 = icmp slt i32 %40, %3
br i1 %41, label %31, label %42
42: ; preds = %31, %23, %18
%43 = tail call i32 @fclose(i32* %8)
%44 = tail call i32 @fclose(i32* %7)
br label %45
45: ; preds = %16, %15, %42
%46 = phi i32 [ 1, %42 ], [ 0, %15 ], [ 0, %16 ]
ret i32 %46
}