#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_refine_context(struct bitmap *dm, int dx, int dy,
                             struct bitmap *sm, int sx, int sy, int ctx,
                             int v) {
  return ((ctx << 1) & 0x636) | getbit(dm, dx + 1, dy - 1) << 8 |
         getbit(sm, sx, sy - 1) << 6 | getbit(sm, sx + 1, sy) << 3 |
         getbit(sm, sx + 1, sy + 1) | v << 7;
}


x86 assembly (clang, -O0):
<jb2_shift_refine_context>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    0x10(%rbp),%eax
shl    $0x1,%eax
and    $0x636,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1030 <getbit@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
call   1030 <getbit@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
shl    $0x6,%ecx
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%edx
call   1030 <getbit@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
shl    $0x3,%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1030 <getbit@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    0x18(%rbp),%ecx
shl    $0x7,%ecx
or     %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jb2_shift_refine_context>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
mov    %r8d,%r13d
mov    %rcx,%rbp
mov    %rcx,0x10(%rsp)
mov    0x58(%rsp),%r14d
mov    0x50(%rsp),%r15d
add    %r15d,%r15d
and    $0x636,%r15d
add    $0x1,%esi
add    $0xffffffff,%edx
call   1030 <getbit@plt>
shl    $0x8,%eax
mov    %eax,0xc(%rsp)
lea    -0x1(%r12),%edx
mov    %rbp,%rdi
mov    %r13d,%esi
call   1030 <getbit@plt>
mov    %eax,%ebx
shl    $0x6,%ebx
add    $0x1,%r13d
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
call   1030 <getbit@plt>
mov    %eax,%ebp
shl    $0x3,%ebp
or     %ebx,%ebp
add    $0x1,%r12d
mov    0x10(%rsp),%rdi
mov    %r13d,%esi
mov    %r12d,%edx
call   1030 <getbit@plt>
shl    $0x7,%r14d
or     0xc(%rsp),%r14d
or     %r15d,%r14d
or     %ebp,%eax
or     %r14d,%eax
add    $0x18,%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_refine_context(%struct.bitmap* %0, i32 %1, i32 %2, %struct.bitmap* %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca %struct.bitmap*
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.bitmap*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store %struct.bitmap* %0, %struct.bitmap** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store %struct.bitmap* %3, %struct.bitmap** %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%17 = load i32, i32* %15
%18 = shl i32 %17, 1
%19 = and i32 %18, 1590
%20 = load %struct.bitmap*, %struct.bitmap** %9
%21 = load i32, i32* %10
%22 = add nsw i32 %21, 1
%23 = load i32, i32* %11
%24 = sub nsw i32 %23, 1
%25 = call i32 @getbit(%struct.bitmap* %20, i32 %22, i32 %24)
%26 = shl i32 %25, 8
%27 = or i32 %19, %26
%28 = load %struct.bitmap*, %struct.bitmap** %12
%29 = load i32, i32* %13
%30 = load i32, i32* %14
%31 = sub nsw i32 %30, 1
%32 = call i32 @getbit(%struct.bitmap* %28, i32 %29, i32 %31)
%33 = shl i32 %32, 6
%34 = or i32 %27, %33
%35 = load %struct.bitmap*, %struct.bitmap** %12
%36 = load i32, i32* %13
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %14
%39 = call i32 @getbit(%struct.bitmap* %35, i32 %37, i32 %38)
%40 = shl i32 %39, 3
%41 = or i32 %34, %40
%42 = load %struct.bitmap*, %struct.bitmap** %12
%43 = load i32, i32* %13
%44 = add nsw i32 %43, 1
%45 = load i32, i32* %14
%46 = add nsw i32 %45, 1
%47 = call i32 @getbit(%struct.bitmap* %42, i32 %44, i32 %46)
%48 = or i32 %41, %47
%49 = load i32, i32* %16
%50 = shl i32 %49, 7
%51 = or i32 %48, %50
ret i32 %51
}

LLVM IR (-O2):
%struct.bitmap = type { i32 }
define i32 @jb2_shift_refine_context(%struct.bitmap* %0, i32 %1, i32 %2, %struct.bitmap* %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = shl i32 %6, 1
%10 = and i32 %9, 1590
%11 = add nsw i32 %1, 1
%12 = add nsw i32 %2, -1
%13 = tail call i32 @getbit(%struct.bitmap* %0, i32 %11, i32 %12)
%14 = shl i32 %13, 8
%15 = add nsw i32 %5, -1
%16 = tail call i32 @getbit(%struct.bitmap* %3, i32 %4, i32 %15)
%17 = shl i32 %16, 6
%18 = add nsw i32 %4, 1
%19 = tail call i32 @getbit(%struct.bitmap* %3, i32 %18, i32 %5)
%20 = shl i32 %19, 3
%21 = add nsw i32 %5, 1
%22 = tail call i32 @getbit(%struct.bitmap* %3, i32 %18, i32 %21)
%23 = shl i32 %7, 7
%24 = or i32 %23, %10
%25 = or i32 %24, %14
%26 = or i32 %25, %17
%27 = or i32 %26, %20
%28 = or i32 %27, %22
ret i32 %28
}