#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 */
void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign, unsigned char *digit,
                                     unsigned char in) {
  unsigned char s, d;
  s = ~((in >> 5) - 1);
  d = (1 << 6) - in - 1;
  d = (d & s) | (in & ~s);
  d = (d >> 1) + (d & 1);
  *sign = s & 1;
  *digit = d;
}


x86 assembly (clang, -O0):
<ec_GFp_nistp_recode_scalar_bits>:
push   %rbp
mov    %rsp,%rbp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
sar    $0x5,%eax
sub    $0x1,%eax
xor    $0xffffffff,%eax
mov    %al,-0x12(%rbp)
movzbl -0x11(%rbp),%ecx
mov    $0x40,%eax
sub    %ecx,%eax
sub    $0x1,%eax
mov    %al,-0x13(%rbp)
movzbl -0x13(%rbp),%eax
movzbl -0x12(%rbp),%ecx
and    %ecx,%eax
movzbl -0x11(%rbp),%ecx
movzbl -0x12(%rbp),%edx
xor    $0xffffffff,%edx
and    %edx,%ecx
or     %ecx,%eax
mov    %al,-0x13(%rbp)
movzbl -0x13(%rbp),%eax
sar    $0x1,%eax
movzbl -0x13(%rbp),%ecx
and    $0x1,%ecx
add    %ecx,%eax
mov    %al,-0x13(%rbp)
movzbl -0x12(%rbp),%eax
and    $0x1,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x13(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<ec_GFp_nistp_recode_scalar_bits>:
mov    %edx,%eax
shr    $0x5,%al
mov    %eax,%r8d
neg    %r8b
mov    $0x3f,%cl
sub    %dl,%cl
and    %r8b,%cl
add    $0xff,%al
and    %dl,%al
or     %cl,%al
mov    %eax,%ecx
shr    %cl
and    $0x1,%al
add    %cl,%al
and    $0x1,%r8b
mov    %r8b,(%rdi)
mov    %al,(%rsi)
ret

LLVM IR (-O0):
define void @ec_GFp_nistp_recode_scalar_bits(i8* %0, i8* %1, i8 zeroext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%9 = load i8, i8* %6
%10 = zext i8 %9 to i32
%11 = ashr i32 %10, 5
%12 = sub nsw i32 %11, 1
%13 = xor i32 %12, -1
%14 = trunc i32 %13 to i8
store i8 %14, i8* %7
%15 = load i8, i8* %6
%16 = zext i8 %15 to i32
%17 = sub nsw i32 64, %16
%18 = sub nsw i32 %17, 1
%19 = trunc i32 %18 to i8
store i8 %19, i8* %8
%20 = load i8, i8* %8
%21 = zext i8 %20 to i32
%22 = load i8, i8* %7
%23 = zext i8 %22 to i32
%24 = and i32 %21, %23
%25 = load i8, i8* %6
%26 = zext i8 %25 to i32
%27 = load i8, i8* %7
%28 = zext i8 %27 to i32
%29 = xor i32 %28, -1
%30 = and i32 %26, %29
%31 = or i32 %24, %30
%32 = trunc i32 %31 to i8
store i8 %32, i8* %8
%33 = load i8, i8* %8
%34 = zext i8 %33 to i32
%35 = ashr i32 %34, 1
%36 = load i8, i8* %8
%37 = zext i8 %36 to i32
%38 = and i32 %37, 1
%39 = add nsw i32 %35, %38
%40 = trunc i32 %39 to i8
store i8 %40, i8* %8
%41 = load i8, i8* %7
%42 = zext i8 %41 to i32
%43 = and i32 %42, 1
%44 = trunc i32 %43 to i8
%45 = load i8*, i8** %4
store i8 %44, i8* %45
%46 = load i8, i8* %8
%47 = load i8*, i8** %5
store i8 %46, i8* %47
ret void
}

LLVM IR (-O2):
define void @ec_GFp_nistp_recode_scalar_bits(i8* nocapture writeonly %0, i8* nocapture writeonly %1, i8 zeroext %2) {
%4 = lshr i8 %2, 5
%5 = sub nsw i8 0, %4
%6 = sub i8 63, %2
%7 = and i8 %6, %5
%8 = add nsw i8 %4, -1
%9 = and i8 %8, %2
%10 = or i8 %9, %7
%11 = lshr i8 %10, 1
%12 = and i8 %10, 1
%13 = add nuw i8 %11, %12
%14 = and i8 %5, 1
store i8 %14, i8* %0
store i8 %13, i8* %1
ret void
}