#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*/ memcpy(unsigned char *, unsigned char *, unsigned char);
void PutSpriteMode0(unsigned char *pSprite, unsigned char nX, unsigned char nY,
                    unsigned char nWidth, unsigned char nHeight) {
  unsigned char nYPos = 0;
  unsigned char *pAddress = 0;
  for (nYPos = 0; nYPos < nHeight; nYPos++) {
    pAddress = (unsigned char *)(0xC000 + ((nY / 8u) * 80u) +
                                 ((nY % 8u) * 2048u) + nX);
    memcpy(pAddress, pSprite, nWidth);
    pSprite += nWidth;
    nY++;
  }
}


x86 assembly (clang, -O0):
<PutSpriteMode0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %sil,-0x9(%rbp)
mov    %dl,-0xa(%rbp)
mov    %cl,-0xb(%rbp)
mov    %al,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x0,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
movzbl -0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    11ad <PutSpriteMode0+0x9d>
movzbl -0xa(%rbp),%eax
shr    $0x3,%eax
imul   $0x50,%eax,%eax
add    $0xc000,%eax
movzbl -0xa(%rbp),%ecx
and    $0x7,%ecx
shl    $0xb,%ecx
add    %ecx,%eax
movzbl -0x9(%rbp),%ecx
add    %ecx,%eax
mov    %eax,%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xb(%rbp),%al
movzbl %al,%edx
call   1030 <memcpy@plt>
movzbl -0xb(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
mov    -0xd(%rbp),%al
add    $0x1,%al
mov    %al,-0xd(%rbp)
jmp    113c <PutSpriteMode0+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PutSpriteMode0>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %r8d,%r8d
je     1174 <PutSpriteMode0+0x64>
mov    %r8d,%r14d
mov    %edx,%ebp
mov    %rdi,%rbx
movzbl %sil,%r12d
or     $0xc000,%r12d
movzbl %cl,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl %bpl,%ebp
mov    %ebp,%eax
shr    $0x3,%eax
lea    (%rax,%rax,4),%eax
shl    $0x4,%eax
add    %r12d,%eax
mov    %ebp,%edi
and    $0x7,%edi
shl    $0xb,%edi
add    %eax,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
add    %r15,%rbx
add    $0x1,%bpl
add    $0xff,%r14b
jne    1140 <PutSpriteMode0+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @PutSpriteMode0(i8* %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8 zeroext %4) {
%6 = icmp eq i8 %4, 0
br i1 %6, label %29, label %7
7: ; preds = %5
%8 = zext i8 %1 to i32
%9 = or i32 %8, 49152
%10 = zext i8 %3 to i64
br label %11
11: ; preds = %7, %11
%12 = phi i8 [ 0, %7 ], [ %27, %11 ]
%13 = phi i8* [ %0, %7 ], [ %25, %11 ]
%14 = phi i8 [ %2, %7 ], [ %26, %11 ]
%15 = zext i8 %14 to i32
%16 = lshr i32 %15, 3
%17 = mul nuw nsw i32 %16, 80
%18 = shl nuw nsw i32 %15, 11
%19 = and i32 %18, 14336
%20 = add nuw nsw i32 %9, %17
%21 = add nuw nsw i32 %20, %19
%22 = zext i32 %21 to i64
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @memcpy(i8* %23, i8* %13, i8 zeroext %3)
%25 = getelementptr inbounds i8, i8* %13, i64 %10
%26 = add i8 %14, 1
%27 = add nuw i8 %12, 1
%28 = icmp eq i8 %27, %4
br i1 %28, label %29, label %11
29: ; preds = %11, %5
ret void
}