#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 curTile;

/* Variables and functions */
char NESCombineBits(unsigned char, unsigned char, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ v_printf(int, char *, ...);
int NESConvertTileDataToComposite(char *buf, char *tileData, int size) {
  v_printf(3, "Start NESConvertTileDataToComposite()");
  if (!tileData || !size || !buf)
    return 0;
  if (size % 16)
    return 0;
  int tileCount = size / 16;
  unsigned char channel_a[8], channel_b[8];
  int i = 0;
  int j = 0;
  int curTile = 0;
  char *composite = (char *)malloc(64 * tileCount);
  for (curTile = 0; curTile < tileCount; curTile++) {
    v_printf(3, "curTile: %d/%d", curTile + 1, tileCount);
    for (i = 0; i < 8; i++) {
      channel_a[i] = tileData[16 * (curTile) + i];
      channel_b[i] = tileData[16 * (curTile) + i + 8];
      v_printf(4, "Channels A/B: %d/%d", channel_a[i], channel_b[i]);
    }
    for (i = 0; i < 8; i++) {
      for (j = 7; j >= 0; j--) {
        int pixel_offset = (i * 8) + (8 - j);
        composite[(pixel_offset + curTile * 64) - 1] =
            NESCombineBits(channel_a[i], channel_b[i], j);
        v_printf(4, "Composite (%d,%d:%d): %d", i, j,
                 (pixel_offset + curTile * 64),
                 composite[pixel_offset + curTile * 64]);
      }
    }
  }
  memcpy(buf, composite, 64 * tileCount);
  return 1;
}


x86 assembly (clang, -O0):
<NESConvertTileDataToComposite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    $0x3,%edi
lea    0xea1(%rip),%rsi
mov    $0x0,%al
call   1060 <v_printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     1186 <NESConvertTileDataToComposite+0x46>
cmpl   $0x0,-0x1c(%rbp)
je     1186 <NESConvertTileDataToComposite+0x46>
cmpq   $0x0,-0x10(%rbp)
jne    1192 <NESConvertTileDataToComposite+0x52>
movl   $0x0,-0x4(%rbp)
jmp    1388 <NESConvertTileDataToComposite+0x248>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11b2 <NESConvertTileDataToComposite+0x72>
movl   $0x0,-0x4(%rbp)
jmp    1388 <NESConvertTileDataToComposite+0x248>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x20(%rbp),%edi
shl    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    136e <NESConvertTileDataToComposite+0x22e>
mov    -0x3c(%rbp),%edx
add    $0x1,%edx
mov    -0x20(%rbp),%ecx
mov    $0x3,%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1060 <v_printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    1290 <NESConvertTileDataToComposite+0x150>
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
shl    $0x4,%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x28(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
shl    $0x4,%ecx
add    -0x34(%rbp),%ecx
add    $0x8,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
movslq -0x34(%rbp),%rax
movzbl -0x28(%rbp,%rax,1),%edx
movslq -0x34(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%ecx
mov    $0x4,%edi
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1060 <v_printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    121a <NESConvertTileDataToComposite+0xda>
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jge    135b <NESConvertTileDataToComposite+0x21b>
movl   $0x7,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jl     1348 <NESConvertTileDataToComposite+0x208>
mov    -0x34(%rbp),%eax
shl    $0x3,%eax
mov    $0x8,%ecx
sub    -0x38(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x4c(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x28(%rbp,%rax,1),%cl
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%al
mov    -0x38(%rbp),%edx
movzbl %cl,%edi
movzbl %al,%esi
call   1030 <NESCombineBits@plt>
mov    %al,%dl
mov    -0x48(%rbp),%rax
mov    -0x4c(%rbp),%ecx
mov    -0x3c(%rbp),%esi
shl    $0x6,%esi
add    %esi,%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
mov    -0x3c(%rbp),%eax
shl    $0x6,%eax
add    %eax,%r8d
mov    -0x48(%rbp),%rax
mov    -0x4c(%rbp),%esi
mov    -0x3c(%rbp),%edi
shl    $0x6,%edi
add    %edi,%esi
movslq %esi,%rsi
movsbl (%rax,%rsi,1),%r9d
mov    $0x4,%edi
lea    0xd16(%rip),%rsi
mov    $0x0,%al
call   1060 <v_printf@plt>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    12a8 <NESConvertTileDataToComposite+0x168>
jmp    134d <NESConvertTileDataToComposite+0x20d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1297 <NESConvertTileDataToComposite+0x157>
jmp    1360 <NESConvertTileDataToComposite+0x220>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11eb <NESConvertTileDataToComposite+0xab>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%edx
shl    $0x6,%edx
call   1040 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NESConvertTileDataToComposite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edx,%r12d
mov    %rsi,0x28(%rsp)
mov    %rdi,%r14
lea    0xea0(%rip),%rsi
xor    %ebp,%ebp
mov    $0x3,%edi
xor    %eax,%eax
call   1060 <v_printf@plt>
test   $0xf,%r12b
jne    15b1 <NESConvertTileDataToComposite+0x471>
test   %r14,%r14
je     15b1 <NESConvertTileDataToComposite+0x471>
cmpq   $0x0,0x28(%rsp)
je     15b1 <NESConvertTileDataToComposite+0x471>
test   %r12d,%r12d
je     15b1 <NESConvertTileDataToComposite+0x471>
lea    0xf(%r12),%r15d
test   %r12d,%r12d
cmovns %r12d,%r15d
sar    $0x4,%r15d
mov    %r15d,%ebp
shl    $0x6,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
cmp    $0x10,%r12d
jl     159f <NESConvertTileDataToComposite+0x45f>
mov    %ebp,0x20(%rsp)
mov    %r14,0x38(%rsp)
mov    %r15d,%eax
mov    %rax,0x48(%rsp)
mov    %rbx,%rax
add    $0x7,%rax
mov    %rax,0x40(%rsp)
xor    %r13d,%r13d
xor    %eax,%eax
mov    %r15d,0x24(%rsp)
mov    %rbx,0x58(%rsp)
jmp    120e <NESConvertTileDataToComposite+0xce>
xchg   %ax,%ax
mov    0x30(%rsp),%r13
add    $0x40,%r13
mov    0x50(%rsp),%rax
cmp    0x48(%rsp),%rax
mov    0x24(%rsp),%r15d
je     158e <NESConvertTileDataToComposite+0x44e>
mov    %rax,%rbx
movslq %r13d,%rbp
add    0x40(%rsp),%rbp
lea    0x1(%rax),%rdx
mov    $0x3,%edi
lea    0xdfd(%rip),%rsi
mov    %rdx,0x50(%rsp)
mov    %r15d,%ecx
xor    %eax,%eax
call   1060 <v_printf@plt>
shl    $0x4,%rbx
mov    0x28(%rsp),%r14
movzbl (%r14,%rbx,1),%edx
mov    %dl,0x18(%rsp)
mov    0x8(%r14,%rbx,1),%r12b
movzbl %r12b,%ecx
mov    $0x4,%edi
lea    0xdd6(%rip),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <v_printf@plt>
movzbl 0x1(%r14,%rbx,1),%edx
mov    %dl,0x19(%rsp)
movzbl 0x9(%r14,%rbx,1),%ecx
mov    %cl,0x11(%rsp)
mov    $0x4,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <v_printf@plt>
movzbl 0x2(%r14,%rbx,1),%edx
mov    %dl,0x1a(%rsp)
movzbl 0xa(%r14,%rbx,1),%ecx
mov    %cl,0x12(%rsp)
mov    $0x4,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <v_printf@plt>
movzbl 0x3(%r14,%rbx,1),%edx
mov    %dl,0x1b(%rsp)
movzbl 0xb(%r14,%rbx,1),%ecx
mov    %cl,0x13(%rsp)
mov    $0x4,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <v_printf@plt>
movzbl 0x4(%r14,%rbx,1),%edx
mov    %dl,0x1c(%rsp)
movzbl 0xc(%r14,%rbx,1),%ecx
mov    %cl,0x14(%rsp)
mov    $0x4,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <v_printf@plt>
movzbl 0x5(%r14,%rbx,1),%edx
mov    %dl,0x1d(%rsp)
movzbl 0xd(%r14,%rbx,1),%ecx
mov    %cl,0x15(%rsp)
mov    $0x4,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <v_printf@plt>
movzbl 0x6(%r14,%rbx,1),%edx
mov    %dl,0x1e(%rsp)
movzbl 0xe(%r14,%rbx,1),%ecx
mov    %cl,0x16(%rsp)
mov    $0x4,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <v_printf@plt>
movzbl 0x7(%r14,%rbx,1),%edx
mov    %dl,0x1f(%rsp)
movzbl 0xf(%r14,%rbx,1),%ecx
mov    %cl,0x17(%rsp)
mov    $0x4,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <v_printf@plt>
xor    %r15d,%r15d
mov    %r12b,0xf(%rsp)
mov    %r12d,%eax
xor    %r12d,%r12d
mov    %r13,0x30(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x18(%rsp,%r12,1),%r14d
lea    (%r15,%r13,1),%rbx
lea    (%r15,%r13,1),%rcx
add    $0x8,%rcx
mov    %rcx,0x60(%rsp)
movzbl %al,%r13d
mov    %r14d,%edi
mov    %r13d,%esi
mov    $0x7,%edx
call   1030 <NESCombineBits@plt>
lea    0x1(%rbx),%r8d
mov    %al,-0x7(%rbp,%r15,1)
movsbl -0x6(%rbp,%r15,1),%r9d
mov    $0x4,%edi
lea    0xc83(%rip),%rsi
mov    %r12d,%edx
mov    $0x7,%ecx
xor    %eax,%eax
call   1060 <v_printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
mov    $0x6,%edx
call   1030 <NESCombineBits@plt>
lea    0x2(%rbx),%r8d
mov    %al,-0x6(%rbp,%r15,1)
movsbl -0x5(%rbp,%r15,1),%r9d
mov    $0x4,%edi
lea    0xc49(%rip),%rsi
mov    %r12d,%edx
mov    $0x6,%ecx
xor    %eax,%eax
call   1060 <v_printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
mov    $0x5,%edx
call   1030 <NESCombineBits@plt>
lea    0x3(%rbx),%r8d
mov    %al,-0x5(%rbp,%r15,1)
movsbl -0x4(%rbp,%r15,1),%r9d
mov    $0x4,%edi
lea    0xc0f(%rip),%rsi
mov    %r12d,%edx
mov    $0x5,%ecx
xor    %eax,%eax
call   1060 <v_printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
mov    $0x4,%edx
call   1030 <NESCombineBits@plt>
lea    0x4(%rbx),%r8d
mov    %al,-0x4(%rbp,%r15,1)
movsbl -0x3(%rbp,%r15,1),%r9d
mov    $0x4,%edi
lea    0xbd5(%rip),%rsi
mov    %r12d,%edx
mov    $0x4,%ecx
xor    %eax,%eax
call   1060 <v_printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
mov    $0x3,%edx
call   1030 <NESCombineBits@plt>
lea    0x5(%rbx),%r8d
mov    %al,-0x3(%rbp,%r15,1)
movsbl -0x2(%rbp,%r15,1),%r9d
mov    $0x4,%edi
lea    0xb9b(%rip),%rsi
mov    %r12d,%edx
mov    $0x3,%ecx
xor    %eax,%eax
call   1060 <v_printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
mov    $0x2,%edx
call   1030 <NESCombineBits@plt>
lea    0x6(%rbx),%r8d
mov    %al,-0x2(%rbp,%r15,1)
movsbl -0x1(%rbp,%r15,1),%r9d
mov    $0x4,%edi
lea    0xb61(%rip),%rsi
mov    %r12d,%edx
mov    $0x2,%ecx
xor    %eax,%eax
call   1060 <v_printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
mov    $0x1,%edx
call   1030 <NESCombineBits@plt>
add    $0x7,%ebx
mov    %al,-0x1(%rbp,%r15,1)
movsbl 0x0(%rbp,%r15,1),%r9d
mov    $0x4,%edi
lea    0xb28(%rip),%rsi
mov    %r12d,%edx
mov    $0x1,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1060 <v_printf@plt>
mov    %r14d,%edi
mov    %r13d,%esi
xor    %edx,%edx
call   1030 <NESCombineBits@plt>
mov    %al,0x0(%rbp,%r15,1)
movslq 0x60(%rsp),%r8
mov    0x58(%rsp),%rbx
movsbl (%rbx,%r8,1),%r9d
mov    $0x4,%edi
lea    0xae9(%rip),%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <v_printf@plt>
cmp    $0x38,%r15
je     11f0 <NESConvertTileDataToComposite+0xb0>
movzbl 0x11(%rsp,%r12,1),%eax
add    $0x8,%r15
add    $0x1,%r12
mov    0x30(%rsp),%r13
jmp    1380 <NESConvertTileDataToComposite+0x240>
mov    0xf(%rsp),%al
mov    %al,0x10(%rsp)
mov    0x38(%rsp),%r14
mov    0x20(%rsp),%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Start NESConvertTileDataToComposite()\00"
@.str.1 = [15 x i8] c"curTile: %d/%d\00"
@.str.2 = [20 x i8] c"Channels A/B: %d/%d\00"
@.str.3 = [25 x i8] c"Composite (%d,%d:%d): %d\00"
define i32 @NESConvertTileDataToComposite(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [8 x i8]
%10 = alloca [8 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%16 = call i32 (i32, i8*, ...) @v_printf(i32 3, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %3
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %22, %19, %3
store i32 0, i32* %4
br label %153
26: ; preds = %22
%27 = load i32, i32* %7
%28 = srem i32 %27, 16
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %4
br label %153
31: ; preds = %26
%32 = load i32, i32* %7
%33 = sdiv i32 %32, 16
store i32 %33, i32* %8
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%34 = load i32, i32* %8
%35 = mul nsw i32 64, %34
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %14
store i32 0, i32* %13
br label %38
38: ; preds = %144, %31
%39 = load i32, i32* %13
%40 = load i32, i32* %8
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %147
42: ; preds = %38
%43 = load i32, i32* %13
%44 = add nsw i32 %43, 1
%45 = load i32, i32* %8
%46 = call i32 (i32, i8*, ...) @v_printf(i32 3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %45)
store i32 0, i32* %11
br label %47
47: ; preds = %85, %42
%48 = load i32, i32* %11
%49 = icmp slt i32 %48, 8
br i1 %49, label %50, label %88
50: ; preds = %47
%51 = load i8*, i8** %6
%52 = load i32, i32* %13
%53 = mul nsw i32 16, %52
%54 = load i32, i32* %11
%55 = add nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %51, i64 %56
%58 = load i8, i8* %57
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 %60
store i8 %58, i8* %61
%62 = load i8*, i8** %6
%63 = load i32, i32* %13
%64 = mul nsw i32 16, %63
%65 = load i32, i32* %11
%66 = add nsw i32 %64, %65
%67 = add nsw i32 %66, 8
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %62, i64 %68
%70 = load i8, i8* %69
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %72
store i8 %70, i8* %73
%74 = load i32, i32* %11
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = load i32, i32* %11
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %80
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %78, i32 %83)
br label %85
85: ; preds = %50
%86 = load i32, i32* %11
%87 = add nsw i32 %86, 1
store i32 %87, i32* %11
br label %47
88: ; preds = %47
store i32 0, i32* %11
br label %89
89: ; preds = %140, %88
%90 = load i32, i32* %11
%91 = icmp slt i32 %90, 8
br i1 %91, label %92, label %143
92: ; preds = %89
store i32 7, i32* %12
br label %93
93: ; preds = %136, %92
%94 = load i32, i32* %12
%95 = icmp sge i32 %94, 0
br i1 %95, label %96, label %139
96: ; preds = %93
%97 = load i32, i32* %11
%98 = mul nsw i32 %97, 8
%99 = load i32, i32* %12
%100 = sub nsw i32 8, %99
%101 = add nsw i32 %98, %100
store i32 %101, i32* %15
%102 = load i32, i32* %11
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 %103
%105 = load i8, i8* %104
%106 = load i32, i32* %11
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 %107
%109 = load i8, i8* %108
%110 = load i32, i32* %12
%111 = call signext i8 @NESCombineBits(i8 zeroext %105, i8 zeroext %109, i32 %110)
%112 = load i8*, i8** %14
%113 = load i32, i32* %15
%114 = load i32, i32* %13
%115 = mul nsw i32 %114, 64
%116 = add nsw i32 %113, %115
%117 = sub nsw i32 %116, 1
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8, i8* %112, i64 %118
store i8 %111, i8* %119
%120 = load i32, i32* %11
%121 = load i32, i32* %12
%122 = load i32, i32* %15
%123 = load i32, i32* %13
%124 = mul nsw i32 %123, 64
%125 = add nsw i32 %122, %124
%126 = load i8*, i8** %14
%127 = load i32, i32* %15
%128 = load i32, i32* %13
%129 = mul nsw i32 %128, 64
%130 = add nsw i32 %127, %129
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i8, i8* %126, i64 %131
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %120, i32 %121, i32 %125, i32 %134)
br label %136
136: ; preds = %96
%137 = load i32, i32* %12
%138 = add nsw i32 %137, -1
store i32 %138, i32* %12
br label %93
139: ; preds = %93
br label %140
140: ; preds = %139
%141 = load i32, i32* %11
%142 = add nsw i32 %141, 1
store i32 %142, i32* %11
br label %89
143: ; preds = %89
br label %144
144: ; preds = %143
%145 = load i32, i32* %13
%146 = add nsw i32 %145, 1
store i32 %146, i32* %13
br label %38
147: ; preds = %38
%148 = load i8*, i8** %5
%149 = load i8*, i8** %14
%150 = load i32, i32* %8
%151 = mul nsw i32 64, %150
%152 = call i32 @memcpy(i8* %148, i8* %149, i32 %151)
store i32 1, i32* %4
br label %153
153: ; preds = %147, %30, %25
%154 = load i32, i32* %4
ret i32 %154
}

LLVM IR (-O2):
@.str = [38 x i8] c"Start NESConvertTileDataToComposite()\00"
@.str.1 = [15 x i8] c"curTile: %d/%d\00"
@.str.2 = [20 x i8] c"Channels A/B: %d/%d\00"
@.str.3 = [25 x i8] c"Composite (%d,%d:%d): %d\00"
define i32 @NESConvertTileDataToComposite(i8* %0, i8* %1, i32 %2) {
%4 = alloca [8 x i8]
%5 = alloca [8 x i8]
%6 = tail call i32 (i32, i8*, ...) @v_printf(i32 3, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i8* %1, null
%8 = icmp ne i32 %2, 0
%9 = and i1 %7, %8
%10 = icmp ne i8* %0, null
%11 = and i1 %10, %9
%12 = and i32 %2, 15
%13 = icmp eq i32 %12, 0
%14 = and i1 %13, %11
br i1 %14, label %15, label %217
15: ; preds = %3
%16 = sdiv i32 %2, 16
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%19 = shl nsw i32 %16, 6
%20 = tail call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
%22 = icmp sgt i32 %2, 15
br i1 %22, label %23, label %215
23: ; preds = %15
%24 = zext i32 %16 to i64
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 1
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 1
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 2
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 2
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 3
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 3
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 4
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 4
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 5
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 5
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 6
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 6
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 7
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 7
br label %41
39: ; preds = %121
%40 = icmp eq i64 %43, %24
br i1 %40, label %214, label %41
41: ; preds = %23, %39
%42 = phi i64 [ 0, %23 ], [ %43, %39 ]
%43 = add nuw nsw i64 %42, 1
%44 = trunc i64 %43 to i32
%45 = tail call i32 (i32, i8*, ...) @v_printf(i32 3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %16)
%46 = shl nsw i64 %42, 4
%47 = getelementptr inbounds i8, i8* %1, i64 %46
%48 = load i8, i8* %47
store i8 %48, i8* %17
%49 = or i64 %46, 8
%50 = getelementptr inbounds i8, i8* %1, i64 %49
%51 = load i8, i8* %50
%52 = zext i8 %48 to i32
%53 = zext i8 %51 to i32
%54 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %52, i32 %53)
%55 = or i64 %46, 1
%56 = getelementptr inbounds i8, i8* %1, i64 %55
%57 = load i8, i8* %56
store i8 %57, i8* %25
%58 = or i64 %46, 9
%59 = getelementptr inbounds i8, i8* %1, i64 %58
%60 = load i8, i8* %59
store i8 %60, i8* %26
%61 = zext i8 %57 to i32
%62 = zext i8 %60 to i32
%63 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %61, i32 %62)
%64 = or i64 %46, 2
%65 = getelementptr inbounds i8, i8* %1, i64 %64
%66 = load i8, i8* %65
store i8 %66, i8* %27
%67 = or i64 %46, 10
%68 = getelementptr inbounds i8, i8* %1, i64 %67
%69 = load i8, i8* %68
store i8 %69, i8* %28
%70 = zext i8 %66 to i32
%71 = zext i8 %69 to i32
%72 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %70, i32 %71)
%73 = or i64 %46, 3
%74 = getelementptr inbounds i8, i8* %1, i64 %73
%75 = load i8, i8* %74
store i8 %75, i8* %29
%76 = or i64 %46, 11
%77 = getelementptr inbounds i8, i8* %1, i64 %76
%78 = load i8, i8* %77
store i8 %78, i8* %30
%79 = zext i8 %75 to i32
%80 = zext i8 %78 to i32
%81 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %79, i32 %80)
%82 = or i64 %46, 4
%83 = getelementptr inbounds i8, i8* %1, i64 %82
%84 = load i8, i8* %83
store i8 %84, i8* %31
%85 = or i64 %46, 12
%86 = getelementptr inbounds i8, i8* %1, i64 %85
%87 = load i8, i8* %86
store i8 %87, i8* %32
%88 = zext i8 %84 to i32
%89 = zext i8 %87 to i32
%90 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %88, i32 %89)
%91 = or i64 %46, 5
%92 = getelementptr inbounds i8, i8* %1, i64 %91
%93 = load i8, i8* %92
store i8 %93, i8* %33
%94 = or i64 %46, 13
%95 = getelementptr inbounds i8, i8* %1, i64 %94
%96 = load i8, i8* %95
store i8 %96, i8* %34
%97 = zext i8 %93 to i32
%98 = zext i8 %96 to i32
%99 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %97, i32 %98)
%100 = or i64 %46, 6
%101 = getelementptr inbounds i8, i8* %1, i64 %100
%102 = load i8, i8* %101
store i8 %102, i8* %35
%103 = or i64 %46, 14
%104 = getelementptr inbounds i8, i8* %1, i64 %103
%105 = load i8, i8* %104
store i8 %105, i8* %36
%106 = zext i8 %102 to i32
%107 = zext i8 %105 to i32
%108 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %106, i32 %107)
%109 = or i64 %46, 7
%110 = getelementptr inbounds i8, i8* %1, i64 %109
%111 = load i8, i8* %110
store i8 %111, i8* %37
%112 = or i64 %46, 15
%113 = getelementptr inbounds i8, i8* %1, i64 %112
%114 = load i8, i8* %113
store i8 %114, i8* %38
%115 = zext i8 %111 to i32
%116 = zext i8 %114 to i32
%117 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %115, i32 %116)
%118 = trunc i64 %42 to i32
%119 = shl nsw i32 %118, 6
%120 = or i32 %119, 8
br label %121
121: ; preds = %211, %41
%122 = phi i8 [ %51, %41 ], [ %213, %211 ]
%123 = phi i64 [ 0, %41 ], [ %209, %211 ]
%124 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 %123
%125 = load i8, i8* %124
%126 = trunc i64 %123 to i32
%127 = shl i32 %126, 3
%128 = add nuw i32 %120, %127
%129 = tail call signext i8 @NESCombineBits(i8 zeroext %125, i8 zeroext %122, i32 7)
%130 = add i32 %128, -7
%131 = add i32 %128, -8
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i8, i8* %21, i64 %132
store i8 %129, i8* %133
%134 = sext i32 %130 to i64
%135 = getelementptr inbounds i8, i8* %21, i64 %134
%136 = load i8, i8* %135
%137 = sext i8 %136 to i32
%138 = trunc i64 %123 to i32
%139 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %138, i32 7, i32 %130, i32 %137)
%140 = tail call signext i8 @NESCombineBits(i8 zeroext %125, i8 zeroext %122, i32 6)
%141 = add i32 %128, -6
%142 = add i32 %128, -7
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds i8, i8* %21, i64 %143
store i8 %140, i8* %144
%145 = sext i32 %141 to i64
%146 = getelementptr inbounds i8, i8* %21, i64 %145
%147 = load i8, i8* %146
%148 = sext i8 %147 to i32
%149 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %138, i32 6, i32 %141, i32 %148)
%150 = tail call signext i8 @NESCombineBits(i8 zeroext %125, i8 zeroext %122, i32 5)
%151 = add i32 %128, -5
%152 = add i32 %128, -6
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i8, i8* %21, i64 %153
store i8 %150, i8* %154
%155 = sext i32 %151 to i64
%156 = getelementptr inbounds i8, i8* %21, i64 %155
%157 = load i8, i8* %156
%158 = sext i8 %157 to i32
%159 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %138, i32 5, i32 %151, i32 %158)
%160 = tail call signext i8 @NESCombineBits(i8 zeroext %125, i8 zeroext %122, i32 4)
%161 = add i32 %128, -4
%162 = add i32 %128, -5
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds i8, i8* %21, i64 %163
store i8 %160, i8* %164
%165 = sext i32 %161 to i64
%166 = getelementptr inbounds i8, i8* %21, i64 %165
%167 = load i8, i8* %166
%168 = sext i8 %167 to i32
%169 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %138, i32 4, i32 %161, i32 %168)
%170 = tail call signext i8 @NESCombineBits(i8 zeroext %125, i8 zeroext %122, i32 3)
%171 = add i32 %128, -3
%172 = add i32 %128, -4
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds i8, i8* %21, i64 %173
store i8 %170, i8* %174
%175 = sext i32 %171 to i64
%176 = getelementptr inbounds i8, i8* %21, i64 %175
%177 = load i8, i8* %176
%178 = sext i8 %177 to i32
%179 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %138, i32 3, i32 %171, i32 %178)
%180 = tail call signext i8 @NESCombineBits(i8 zeroext %125, i8 zeroext %122, i32 2)
%181 = add i32 %128, -2
%182 = add i32 %128, -3
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds i8, i8* %21, i64 %183
store i8 %180, i8* %184
%185 = sext i32 %181 to i64
%186 = getelementptr inbounds i8, i8* %21, i64 %185
%187 = load i8, i8* %186
%188 = sext i8 %187 to i32
%189 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %138, i32 2, i32 %181, i32 %188)
%190 = tail call signext i8 @NESCombineBits(i8 zeroext %125, i8 zeroext %122, i32 1)
%191 = add i32 %128, -1
%192 = add i32 %128, -2
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds i8, i8* %21, i64 %193
store i8 %190, i8* %194
%195 = sext i32 %191 to i64
%196 = getelementptr inbounds i8, i8* %21, i64 %195
%197 = load i8, i8* %196
%198 = sext i8 %197 to i32
%199 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %138, i32 1, i32 %191, i32 %198)
%200 = tail call signext i8 @NESCombineBits(i8 zeroext %125, i8 zeroext %122, i32 0)
%201 = add nsw i32 %128, -1
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds i8, i8* %21, i64 %202
store i8 %200, i8* %203
%204 = sext i32 %128 to i64
%205 = getelementptr inbounds i8, i8* %21, i64 %204
%206 = load i8, i8* %205
%207 = sext i8 %206 to i32
%208 = tail call i32 (i32, i8*, ...) @v_printf(i32 4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %138, i32 0, i32 %128, i32 %207)
%209 = add nuw nsw i64 %123, 1
%210 = icmp eq i64 %209, 8
br i1 %210, label %39, label %211
211: ; preds = %121
%212 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %209
%213 = load i8, i8* %212
br label %121
214: ; preds = %39
store i8 %51, i8* %18
br label %215
215: ; preds = %214, %15
%216 = tail call i32 @memcpy(i8* %0, i8* %21, i32 %19)
br label %217
217: ; preds = %3, %215
%218 = phi i32 [ 1, %215 ], [ 0, %3 ]
ret i32 %218
}