#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 */
struct bitmap {
  int dummy;
};

/* Variables and functions */
int getbit(struct bitmap *, int, int);
int jb2_shift_direct_context(struct bitmap *bm, int x, int y, int ctx, int v) {
  return ((ctx << 1) & 0x37a) | getbit(bm, x + 2, y - 1) << 2 |
         getbit(bm, x + 1, y - 2) << 7 | v;
}


x86 assembly (clang, -O0):
<jb2_shift_direct_context>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
and    $0x37a,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x2,%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1030 <getbit@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
shl    $0x2,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
sub    $0x2,%edx
call   1030 <getbit@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
shl    $0x7,%ecx
or     %ecx,%eax
or     -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jb2_shift_direct_context>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,%r15
lea    (%rcx,%rcx,1),%ebx
and    $0x37a,%ebx
lea    0x2(%rbp),%esi
lea    -0x1(%r13),%edx
call   1030 <getbit@plt>
mov    %eax,%r12d
shl    $0x2,%r12d
add    $0x1,%ebp
add    $0xfffffffe,%r13d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
call   1030 <getbit@plt>
shl    $0x7,%eax
or     %r14d,%ebx
or     %r12d,%ebx
or     %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitmap = type { i32 }
define i32 @jb2_shift_direct_context(%struct.bitmap* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.bitmap*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.bitmap* %0, %struct.bitmap** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%11 = load i32, i32* %9
%12 = shl i32 %11, 1
%13 = and i32 %12, 890
%14 = load %struct.bitmap*, %struct.bitmap** %6
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 2
%17 = load i32, i32* %8
%18 = sub nsw i32 %17, 1
%19 = call i32 @getbit(%struct.bitmap* %14, i32 %16, i32 %18)
%20 = shl i32 %19, 2
%21 = or i32 %13, %20
%22 = load %struct.bitmap*, %struct.bitmap** %6
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %8
%26 = sub nsw i32 %25, 2
%27 = call i32 @getbit(%struct.bitmap* %22, i32 %24, i32 %26)
%28 = shl i32 %27, 7
%29 = or i32 %21, %28
%30 = load i32, i32* %10
%31 = or i32 %29, %30
ret i32 %31
}

LLVM IR (-O2):
%struct.bitmap = type { i32 }
define i32 @jb2_shift_direct_context(%struct.bitmap* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = shl i32 %3, 1
%7 = and i32 %6, 890
%8 = add nsw i32 %1, 2
%9 = add nsw i32 %2, -1
%10 = tail call i32 @getbit(%struct.bitmap* %0, i32 %8, i32 %9)
%11 = shl i32 %10, 2
%12 = add nsw i32 %1, 1
%13 = add nsw i32 %2, -2
%14 = tail call i32 @getbit(%struct.bitmap* %0, i32 %12, i32 %13)
%15 = shl i32 %14, 7
%16 = or i32 %7, %4
%17 = or i32 %16, %11
%18 = or i32 %17, %15
ret i32 %18
}