#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 scalar_t__ int64_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ shr_arith(scalar_t__, unsigned int);
scalar_t__ shr_logic(scalar_t__, unsigned int);
bool bitpack_fitss(int64_t n, unsigned width) {
  assert(width <= 64);
  assert(width > 0);
  if (n < 0) {
    return ((int64_t)shr_arith(n, width - 1)) == -1;
  } else {
    return shr_logic(n, width - 1) == 0;
  }
}


x86 assembly (clang, -O0):
<bitpack_fitss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x40,-0x14(%rbp)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
jge    118f <bitpack_fitss+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1050 <shr_arith@plt>
cmp    $0xffffffffffffffff,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <bitpack_fitss+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1040 <shr_logic@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitpack_fitss>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
xor    %edi,%edi
cmp    $0x41,%esi
setb   %dil
call   1030 <assert@plt>
xor    %edi,%edi
add    $0xffffffff,%ebx
setb   %dil
call   1030 <assert@plt>
mov    %r14,%rdi
mov    %ebx,%esi
test   %r14,%r14
js     1169 <bitpack_fitss+0x39>
call   1040 <shr_logic@plt>
test   %rax,%rax
jmp    1172 <bitpack_fitss+0x42>
call   1050 <shr_arith@plt>
cmp    $0xffffffffffffffff,%rax
sete   %al
movzbl %al,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @bitpack_fitss(i64 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i64 %0, i64* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp ule i32 %6, 64
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %5
%11 = icmp ugt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* %4
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i64, i64* %4
%18 = load i32, i32* %5
%19 = sub i32 %18, 1
%20 = call i64 @shr_arith(i64 %17, i32 %19)
%21 = icmp eq i64 %20, -1
%22 = zext i1 %21 to i32
store i32 %22, i32* %3
br label %30
23: ; preds = %2
%24 = load i64, i64* %4
%25 = load i32, i32* %5
%26 = sub i32 %25, 1
%27 = call i64 @shr_logic(i64 %24, i32 %26)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
store i32 %29, i32* %3
br label %30
30: ; preds = %23, %16
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @bitpack_fitss(i64 %0, i32 %1) {
%3 = icmp ult i32 %1, 65
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i32 %1, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp slt i64 %0, 0
%10 = add i32 %1, -1
br i1 %9, label %11, label %14
11: ; preds = %2
%12 = tail call i64 @shr_arith(i64 %0, i32 %10)
%13 = icmp eq i64 %12, -1
br label %17
14: ; preds = %2
%15 = tail call i64 @shr_logic(i64 %0, i32 %10)
%16 = icmp eq i64 %15, 0
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ %13, %11 ], [ %16, %14 ]
%19 = zext i1 %18 to i32
ret i32 %19
}