#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 uint16_t;

/* Variables and functions */
int BIT_BUILD(int, int, ...);
int get_pcoffset9(uint16_t i) {
  int offset = i & BIT_BUILD(9, 0, 1, 2, 3, 4, 5, 6, 7, 8);
  if (!(offset & BIT_BUILD(1, 8)))
    return offset;
  offset = ~offset;
  offset++;
  return offset;
}


x86 assembly (clang, -O0):
<get_pcoffset9>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x9,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
mov    $0x4,%r9d
movl   $0x5,(%rsp)
movl   $0x6,0x8(%rsp)
movl   $0x7,0x10(%rsp)
movl   $0x8,0x18(%rsp)
mov    $0x0,%al
call   1030 <BIT_BUILD@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1,%edi
mov    $0x8,%esi
mov    $0x0,%al
call   1030 <BIT_BUILD@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
and    %ecx,%eax
cmp    $0x0,%eax
jne    11a0 <get_pcoffset9+0x90>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b8 <get_pcoffset9+0xa8>
mov    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pcoffset9>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x9,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
mov    $0x4,%r9d
xor    %eax,%eax
push   $0x8
push   $0x7
push   $0x6
push   $0x5
call   1030 <BIT_BUILD@plt>
add    $0x20,%rsp
mov    %eax,%ebp
and    %ebx,%ebp
mov    $0x1,%edi
mov    $0x8,%esi
xor    %eax,%eax
call   1030 <BIT_BUILD@plt>
mov    %ebp,%ecx
neg    %ecx
test   %eax,%ebp
cmove  %ebp,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_pcoffset9(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 (i32, i32, ...) @BIT_BUILD(i32 9, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8)
%7 = and i32 %5, %6
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = call i32 (i32, i32, ...) @BIT_BUILD(i32 1, i32 8)
%10 = and i32 %8, %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = load i32, i32* %4
store i32 %13, i32* %2
br label %20
14: ; preds = %1
%15 = load i32, i32* %4
%16 = xor i32 %15, -1
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %20
20: ; preds = %14, %12
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
define i32 @get_pcoffset9(i32 %0) {
%2 = tail call i32 (i32, i32, ...) @BIT_BUILD(i32 9, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8)
%3 = and i32 %2, %0
%4 = tail call i32 (i32, i32, ...) @BIT_BUILD(i32 1, i32 8)
%5 = and i32 %3, %4
%6 = icmp eq i32 %5, 0
%7 = sub i32 0, %3
%8 = select i1 %6, i32 %3, i32 %7
ret i32 %8
}