#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 uint8_t;
typedef int uint32_t;
typedef int uint16_t;
typedef int int32_t;

/* Variables and functions */
void GrOffScreen4BPPPixelDraw(void *pvDisplayData, int32_t i32X, int32_t i32Y,
                              uint32_t ui32Value) {
  uint8_t *pui8Data;
  int32_t i32BytesPerRow;
  ;
  pui8Data = (uint8_t *)pvDisplayData;
  i32BytesPerRow = (*(uint16_t *)(pui8Data + 1) + 1) / 2;
  pui8Data += (i32BytesPerRow * i32Y) + (i32X / 2) + 6 + (16 * 3);
  i32X = (1 - (i32X & 1)) * 4;
  *pui8Data = (*pui8Data & ~(0xf << i32X)) | (ui32Value << i32X);
}


x86 assembly (clang, -O0):
<GrOffScreen4BPPPixelDraw>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
imul   -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
add    %eax,%ecx
add    $0x6,%ecx
add    $0x30,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%ecx
and    $0x1,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
shl    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
mov    $0xf,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    %cl,%eax
mov    -0x28(%rbp),%ecx
or     %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<GrOffScreen4BPPPixelDraw>:
mov    %ecx,%r8d
mov    0x4(%rdi),%eax
mov    %eax,%ecx
add    $0x1,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
add    $0x1,%eax
sar    %eax
imul   %edx,%eax
mov    %esi,%ecx
shr    $0x1f,%ecx
add    %esi,%ecx
sar    %ecx
add    %ecx,%eax
add    $0x36,%eax
cltq
lea    0x0(,%rsi,4),%ecx
not    %cl
and    $0x4,%cl
mov    $0xf,%edx
shl    %cl,%edx
not    %edx
shl    %cl,%r8d
and    (%rdi,%rax,4),%edx
or     %edx,%r8d
mov    %r8d,(%rdi,%rax,4)
ret

LLVM IR (-O0):
define void @GrOffScreen4BPPPixelDraw(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = sdiv i32 %16, 2
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = load i32, i32* %7
%20 = mul nsw i32 %18, %19
%21 = load i32, i32* %6
%22 = sdiv i32 %21, 2
%23 = add nsw i32 %20, %22
%24 = add nsw i32 %23, 6
%25 = add nsw i32 %24, 48
%26 = load i32*, i32** %9
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i32, i32* %26, i64 %27
store i32* %28, i32** %9
%29 = load i32, i32* %6
%30 = and i32 %29, 1
%31 = sub nsw i32 1, %30
%32 = mul nsw i32 %31, 4
store i32 %32, i32* %6
%33 = load i32*, i32** %9
%34 = load i32, i32* %33
%35 = load i32, i32* %6
%36 = shl i32 15, %35
%37 = xor i32 %36, -1
%38 = and i32 %34, %37
%39 = load i32, i32* %8
%40 = load i32, i32* %6
%41 = shl i32 %39, %40
%42 = or i32 %38, %41
%43 = load i32*, i32** %9
store i32 %42, i32* %43
ret void
}

LLVM IR (-O2):
define void @GrOffScreen4BPPPixelDraw(i8* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = bitcast i8* %0 to i32*
%6 = getelementptr inbounds i8, i8* %0, i64 4
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1
%10 = sdiv i32 %9, 2
%11 = mul nsw i32 %10, %2
%12 = sdiv i32 %1, 2
%13 = add nsw i32 %12, 54
%14 = add i32 %13, %11
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %5, i64 %15
%17 = shl i32 %1, 2
%18 = and i32 %17, 4
%19 = xor i32 %18, 4
%20 = load i32, i32* %16
%21 = shl i32 15, %19
%22 = xor i32 %21, -1
%23 = and i32 %20, %22
%24 = shl i32 %3, %19
%25 = or i32 %23, %24
store i32 %25, i32* %16
ret void
}