#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 /*<<< orphan*/ assert(int);
int bit_cmp(int, int *, unsigned char *, unsigned char *);
int imp_bit(int n, int *perm, void *_a, void *_b) {
  unsigned char *a = (unsigned char *)_a;
  unsigned char *b = (unsigned char *)_b;
  int changed, major, minor;
  int msmb;
  changed = bit_cmp(n, perm, a, b);
  assert(changed >= 0);
  msmb = changed - 1;
  major = msmb / 8;
  minor = msmb % 8;
  return (a[perm[major]] >> minor) & 0x01 ? 0 : 1;
}


x86 assembly (clang, -O0):
<imp_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <bit_cmp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x38(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x3c(%rbp),%ecx
sar    %cl,%edx
and    $0x1,%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imp_bit>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
call   1040 <bit_cmp@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
lea    -0x1(%rbx),%ecx
add    $0x6,%ebx
test   %ecx,%ecx
cmovns %ecx,%ebx
sar    $0x3,%ebx
movslq %ebx,%rax
movslq (%r15,%rax,4),%rax
movzbl (%r14,%rax,1),%eax
not    %eax
and    $0x7,%cl
shr    %cl,%eax
and    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @imp_bit(i32 %0, i32* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%15 = load i8*, i8** %7
store i8* %15, i8** %9
%16 = load i8*, i8** %8
store i8* %16, i8** %10
%17 = load i32, i32* %5
%18 = load i32*, i32** %6
%19 = load i8*, i8** %9
%20 = load i8*, i8** %10
%21 = call i32 @bit_cmp(i32 %17, i32* %18, i8* %19, i8* %20)
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = icmp sge i32 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %11
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %14
%28 = load i32, i32* %14
%29 = sdiv i32 %28, 8
store i32 %29, i32* %12
%30 = load i32, i32* %14
%31 = srem i32 %30, 8
store i32 %31, i32* %13
%32 = load i8*, i8** %9
%33 = load i32*, i32** %6
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %32, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = load i32, i32* %13
%43 = ashr i32 %41, %42
%44 = and i32 %43, 1
%45 = icmp ne i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 0, i32 1
ret i32 %47
}

LLVM IR (-O2):
define i32 @imp_bit(i32 %0, i32* %1, i8* %2, i8* %3) {
%5 = tail call i32 @bit_cmp(i32 %0, i32* %1, i8* %2, i8* %3)
%6 = xor i32 %5, -1
%7 = lshr i32 %6, 31
%8 = tail call i32 @assert(i32 %7)
%9 = add nsw i32 %5, -1
%10 = sdiv i32 %9, 8
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %1, i64 %11
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = and i32 %9, 7
%19 = xor i32 %17, -1
%20 = lshr i32 %19, %18
%21 = and i32 %20, 1
ret i32 %21
}