#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 */

/* Variables and functions */
int /*<<< orphan*/ NESCompositeRowToChannels(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int NESCompositeToTile(char *composite_data, char *buf) {
  if (!composite_data || !buf)
    return 0;
  char *new_tile = (char *)malloc(16);
  char channel[2];
  int i = 0;
  for (i = 0; i < 8; i++) {
    NESCompositeRowToChannels(composite_data, channel);
    new_tile[i] = channel[0];
    new_tile[i + 8] = channel[1];
    composite_data += 8;
  }
  memcpy(buf, new_tile, 16);
  free(new_tile);
  return 1;
}


x86 assembly (clang, -O0):
<NESCompositeToTile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <NESCompositeToTile+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1172 <NESCompositeToTile+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1202 <NESCompositeToTile+0xc2>
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x8,-0x28(%rbp)
jge    11e0 <NESCompositeToTile+0xa0>
mov    -0x10(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    -0x22(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x8,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118e <NESCompositeToTile+0x4e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NESCompositeToTile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     1262 <NESCompositeToTile+0x122>
mov    %rsi,%r14
test   %rsi,%rsi
je     1262 <NESCompositeToTile+0x122>
mov    %rdi,%r15
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0x6(%rsp),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    0x6(%rsp),%al
mov    %al,(%rbx)
mov    0x7(%rsp),%al
mov    %al,0x8(%rbx)
lea    0x8(%r15),%rdi
mov    %r12,%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    0x6(%rsp),%al
mov    %al,0x1(%rbx)
mov    0x7(%rsp),%al
mov    %al,0x9(%rbx)
lea    0x10(%r15),%rdi
mov    %r12,%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    0x6(%rsp),%al
mov    %al,0x2(%rbx)
mov    0x7(%rsp),%al
mov    %al,0xa(%rbx)
lea    0x18(%r15),%rdi
mov    %r12,%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    0x6(%rsp),%al
mov    %al,0x3(%rbx)
mov    0x7(%rsp),%al
mov    %al,0xb(%rbx)
lea    0x20(%r15),%rdi
mov    %r12,%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    0x6(%rsp),%al
mov    %al,0x4(%rbx)
mov    0x7(%rsp),%al
mov    %al,0xc(%rbx)
lea    0x28(%r15),%rdi
mov    %r12,%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    0x6(%rsp),%al
mov    %al,0x5(%rbx)
mov    0x7(%rsp),%al
mov    %al,0xd(%rbx)
lea    0x30(%r15),%rdi
mov    %r12,%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    0x6(%rsp),%al
mov    %al,0x6(%rbx)
mov    0x7(%rsp),%al
mov    %al,0xe(%rbx)
add    $0x38,%r15
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <NESCompositeRowToChannels@plt>
mov    0x6(%rsp),%al
mov    %al,0x7(%rbx)
mov    0x7(%rsp),%al
mov    %al,0xf(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @NESCompositeToTile(i8* %0, i8* %1) {
%3 = alloca [2 x i8]
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
br i1 %6, label %7, label %60
7: ; preds = %2
%8 = tail call i64 @malloc(i32 16)
%9 = inttoptr i64 %8 to i8*
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%12 = call i32 @NESCompositeRowToChannels(i8* %0, i8* %10)
%13 = load i8, i8* %10
store i8 %13, i8* %9
%14 = load i8, i8* %11
%15 = getelementptr inbounds i8, i8* %9, i64 8
store i8 %14, i8* %15
%16 = getelementptr inbounds i8, i8* %0, i64 8
%17 = call i32 @NESCompositeRowToChannels(i8* %16, i8* %10)
%18 = load i8, i8* %10
%19 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %18, i8* %19
%20 = load i8, i8* %11
%21 = getelementptr inbounds i8, i8* %9, i64 9
store i8 %20, i8* %21
%22 = getelementptr inbounds i8, i8* %0, i64 16
%23 = call i32 @NESCompositeRowToChannels(i8* %22, i8* %10)
%24 = load i8, i8* %10
%25 = getelementptr inbounds i8, i8* %9, i64 2
store i8 %24, i8* %25
%26 = load i8, i8* %11
%27 = getelementptr inbounds i8, i8* %9, i64 10
store i8 %26, i8* %27
%28 = getelementptr inbounds i8, i8* %0, i64 24
%29 = call i32 @NESCompositeRowToChannels(i8* %28, i8* %10)
%30 = load i8, i8* %10
%31 = getelementptr inbounds i8, i8* %9, i64 3
store i8 %30, i8* %31
%32 = load i8, i8* %11
%33 = getelementptr inbounds i8, i8* %9, i64 11
store i8 %32, i8* %33
%34 = getelementptr inbounds i8, i8* %0, i64 32
%35 = call i32 @NESCompositeRowToChannels(i8* %34, i8* %10)
%36 = load i8, i8* %10
%37 = getelementptr inbounds i8, i8* %9, i64 4
store i8 %36, i8* %37
%38 = load i8, i8* %11
%39 = getelementptr inbounds i8, i8* %9, i64 12
store i8 %38, i8* %39
%40 = getelementptr inbounds i8, i8* %0, i64 40
%41 = call i32 @NESCompositeRowToChannels(i8* %40, i8* %10)
%42 = load i8, i8* %10
%43 = getelementptr inbounds i8, i8* %9, i64 5
store i8 %42, i8* %43
%44 = load i8, i8* %11
%45 = getelementptr inbounds i8, i8* %9, i64 13
store i8 %44, i8* %45
%46 = getelementptr inbounds i8, i8* %0, i64 48
%47 = call i32 @NESCompositeRowToChannels(i8* %46, i8* %10)
%48 = load i8, i8* %10
%49 = getelementptr inbounds i8, i8* %9, i64 6
store i8 %48, i8* %49
%50 = load i8, i8* %11
%51 = getelementptr inbounds i8, i8* %9, i64 14
store i8 %50, i8* %51
%52 = getelementptr inbounds i8, i8* %0, i64 56
%53 = call i32 @NESCompositeRowToChannels(i8* %52, i8* %10)
%54 = load i8, i8* %10
%55 = getelementptr inbounds i8, i8* %9, i64 7
store i8 %54, i8* %55
%56 = load i8, i8* %11
%57 = getelementptr inbounds i8, i8* %9, i64 15
store i8 %56, i8* %57
%58 = call i32 @memcpy(i8* %1, i8* %9, i32 16)
%59 = call i32 @free(i8* %9)
br label %60
60: ; preds = %2, %7
%61 = phi i32 [ 1, %7 ], [ 0, %2 ]
ret i32 %61
}