#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 fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int NESWriteTileAsNative(FILE *ofile, char *data, int data_size) {
  if (!ofile || !data || data_size == 0)
    return 0;
  int i = 0;
  for (i = 0; i < data_size; i++) {
    printf("%02X ", (unsigned char)data[i]);
  }
  printf("\n");
  return fwrite(data, data_size, 1, ofile);
}


x86 assembly (clang, -O0):
<NESWriteTileAsNative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1153 <NESWriteTileAsNative+0x33>
cmpq   $0x0,-0x18(%rbp)
je     1153 <NESWriteTileAsNative+0x33>
cmpl   $0x0,-0x1c(%rbp)
jne    115f <NESWriteTileAsNative+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <NESWriteTileAsNative+0xa7>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a1 <NESWriteTileAsNative+0x81>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116d <NESWriteTileAsNative+0x4d>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NESWriteTileAsNative>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a4 <NESWriteTileAsNative+0x74>
mov    %rsi,%r13
test   %rsi,%rsi
je     11a4 <NESWriteTileAsNative+0x74>
mov    %edx,%r15d
test   %edx,%edx
je     11a4 <NESWriteTileAsNative+0x74>
mov    %rdi,%r14
jle    1179 <NESWriteTileAsNative+0x49>
mov    %r15d,%ebp
lea    0xea2(%rip),%r12
xor    %ebx,%ebx
movzbl 0x0(%r13,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <NESWriteTileAsNative+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%02X \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @NESWriteTileAsNative(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %11, %3
store i32 0, i32* %4
br label %40
18: ; preds = %14
store i32 0, i32* %8
store i32 0, i32* %8
br label %19
19: ; preds = %31, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %19
34: ; preds = %19
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = load i32*, i32** %5
%39 = call i32 @fwrite(i8* %36, i32 %37, i32 1, i32* %38)
store i32 %39, i32* %4
br label %40
40: ; preds = %34, %17
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@.str = [6 x i8] c"%02X \00"
define i32 @NESWriteTileAsNative(i32* %0, i8* %1, i32 %2) {
%4 = icmp eq i32* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i32 %2, 0
%8 = or i1 %6, %7
br i1 %8, label %24, label %9
9: ; preds = %3
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %21
11: ; preds = %9
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %19, %13 ]
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %21, label %13
21: ; preds = %13, %9
%22 = tail call i32 @putchar(i32 10)
%23 = tail call i32 @fwrite(i8* %1, i32 %2, i32 1, i32* %0)
br label %24
24: ; preds = %3, %21
%25 = phi i32 [ %23, %21 ], [ 0, %3 ]
ret i32 %25
}