#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 getBW(unsigned short);
void nio_pixel_set_4bpp(void *screen, int x, int y, unsigned short c) {
  unsigned char *p =
      (unsigned char *)(screen + ((x >> 1) + (y << 7) + (y << 5)));
  *p = (x & 1) ? ((*p & 0xF0) | getBW(c)) : ((*p & 0x0F) | (getBW(c) << 4));
}


x86 assembly (clang, -O0):
<nio_pixel_set_4bpp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cx,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sar    $0x1,%ecx
mov    -0x10(%rbp),%edx
shl    $0x7,%edx
add    %edx,%ecx
mov    -0x10(%rbp),%edx
shl    $0x5,%edx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1183 <nio_pixel_set_4bpp+0x73>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
and    $0xf0,%eax
mov    %eax,-0x28(%rbp)
movzwl -0x12(%rbp),%edi
call   1030 <getBW@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <nio_pixel_set_4bpp+0x96>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
and    $0xf,%eax
mov    %eax,-0x2c(%rbp)
movzwl -0x12(%rbp),%edi
call   1030 <getBW@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
shl    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nio_pixel_set_4bpp>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %esi,%eax
sar    %eax
lea    (%rdx,%rdx,4),%edx
shl    $0x5,%edx
add    %eax,%edx
movslq %edx,%rbx
movzbl (%rdi,%rbx,1),%ebp
test   $0x1,%sil
jne    1140 <nio_pixel_set_4bpp+0x30>
and    $0xf,%ebp
movzwl %cx,%edi
call   1030 <getBW@plt>
shl    $0x4,%eax
jmp    114b <nio_pixel_set_4bpp+0x3b>
and    $0xfffffff0,%ebp
movzwl %cx,%edi
call   1030 <getBW@plt>
or     %ebp,%eax
mov    %al,(%r14,%rbx,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @nio_pixel_set_4bpp(i8* %0, i32 %1, i32 %2, i16 zeroext %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i16 %3, i16* %8
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = ashr i32 %11, 1
%13 = load i32, i32* %7
%14 = shl i32 %13, 7
%15 = add nsw i32 %12, %14
%16 = load i32, i32* %7
%17 = shl i32 %16, 5
%18 = add nsw i32 %15, %17
%19 = sext i32 %18 to i64
%20 = getelementptr i8, i8* %10, i64 %19
store i8* %20, i8** %9
%21 = load i32, i32* %6
%22 = and i32 %21, 1
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %4
%25 = load i8*, i8** %9
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = and i32 %27, 240
%29 = load i16, i16* %8
%30 = call i32 @getBW(i16 zeroext %29)
%31 = or i32 %28, %30
br label %41
32: ; preds = %4
%33 = load i8*, i8** %9
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = and i32 %35, 15
%37 = load i16, i16* %8
%38 = call i32 @getBW(i16 zeroext %37)
%39 = shl i32 %38, 4
%40 = or i32 %36, %39
br label %41
41: ; preds = %32, %24
%42 = phi i32 [ %31, %24 ], [ %40, %32 ]
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %9
store i8 %43, i8* %44
ret void
}

LLVM IR (-O2):
define void @nio_pixel_set_4bpp(i8* nocapture %0, i32 %1, i32 %2, i16 zeroext %3) {
%5 = ashr i32 %1, 1
%6 = mul i32 %2, 160
%7 = add i32 %6, %5
%8 = sext i32 %7 to i64
%9 = getelementptr i8, i8* %0, i64 %8
%10 = and i32 %1, 1
%11 = icmp eq i32 %10, 0
%12 = load i8, i8* %9
br i1 %11, label %18, label %13
13: ; preds = %4
%14 = and i8 %12, -16
%15 = zext i8 %14 to i32
%16 = tail call i32 @getBW(i16 zeroext %3)
%17 = or i32 %16, %15
br label %24
18: ; preds = %4
%19 = and i8 %12, 15
%20 = zext i8 %19 to i32
%21 = tail call i32 @getBW(i16 zeroext %3)
%22 = shl i32 %21, 4
%23 = or i32 %22, %20
br label %24
24: ; preds = %18, %13
%25 = phi i32 [ %17, %13 ], [ %23, %18 ]
%26 = trunc i32 %25 to i8
store i8 %26, i8* %9
ret void
}