#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 /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, unsigned int);
int /*<<< orphan*/ mpz_mul_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_mul_si(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_tdiv_q_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int);
void bits_to_target(unsigned int bits, mpz_t v) {
  unsigned int r = bits & 0x007FFFFF;
  unsigned int mant = (bits >> 24) & 0xFF;
  int neg = ((bits & 0x00800000) != 0) ? -1 : 1;
  if (mant <= 3) {
    mpz_init_set_ui(v, r);
    mpz_tdiv_q_2exp(v, v, 8 * (3 - mant));
    mpz_mul_si(v, v, neg);
  } else {
    mpz_init_set_ui(v, r);
    mpz_mul_2exp(v, v, 8 * (mant - 3));
    mpz_mul_si(v, v, neg);
  }
}


x86 assembly (clang, -O0):
<bits_to_target>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7fffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edx
and    $0x800000,%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x10(%rbp)
ja     11c1 <bits_to_target+0x81>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <mpz_init_set_ui@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x3,%edx
sub    -0x10(%rbp),%edx
shl    $0x3,%edx
call   1050 <mpz_tdiv_q_2exp@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <mpz_mul_si@plt>
jmp    11ee <bits_to_target+0xae>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <mpz_init_set_ui@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
sub    $0x3,%edx
shl    $0x3,%edx
call   1040 <mpz_mul_2exp@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <mpz_mul_si@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bits_to_target>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    %edi,%esi
and    $0x7fffff,%esi
mov    %edi,%ebx
shr    $0x18,%ebx
mov    %r14d,%edi
call   1060 <mpz_init_set_ui@plt>
cmp    $0x3ffffff,%ebp
ja     117d <bits_to_target+0x3d>
shl    $0x3,%ebx
mov    $0x18,%edx
sub    %ebx,%edx
mov    %r14d,%edi
mov    %r14d,%esi
call   1050 <mpz_tdiv_q_2exp@plt>
jmp    118f <bits_to_target+0x4f>
lea    -0x18(,%rbx,8),%edx
mov    %r14d,%edi
mov    %r14d,%esi
call   1040 <mpz_mul_2exp@plt>
and    $0x800000,%ebp
neg    %ebp
sbb    %edx,%edx
or     $0x1,%edx
mov    %r14d,%edi
mov    %r14d,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <mpz_mul_si@plt>

LLVM IR (-O0):
define void @bits_to_target(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = and i32 %8, 8388607
store i32 %9, i32* %5
%10 = load i32, i32* %3
%11 = lshr i32 %10, 24
%12 = and i32 %11, 255
store i32 %12, i32* %6
%13 = load i32, i32* %3
%14 = and i32 %13, 8388608
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 -1, i32 1
store i32 %17, i32* %7
%18 = load i32, i32* %6
%19 = icmp ule i32 %18, 3
br i1 %19, label %20, label %34
20: ; preds = %2
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @mpz_init_set_ui(i32 %21, i32 %22)
%24 = load i32, i32* %4
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = sub i32 3, %26
%28 = mul i32 8, %27
%29 = call i32 @mpz_tdiv_q_2exp(i32 %24, i32 %25, i32 %28)
%30 = load i32, i32* %4
%31 = load i32, i32* %4
%32 = load i32, i32* %7
%33 = call i32 @mpz_mul_si(i32 %30, i32 %31, i32 %32)
br label %48
34: ; preds = %2
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i32 @mpz_init_set_ui(i32 %35, i32 %36)
%38 = load i32, i32* %4
%39 = load i32, i32* %4
%40 = load i32, i32* %6
%41 = sub i32 %40, 3
%42 = mul i32 8, %41
%43 = call i32 @mpz_mul_2exp(i32 %38, i32 %39, i32 %42)
%44 = load i32, i32* %4
%45 = load i32, i32* %4
%46 = load i32, i32* %7
%47 = call i32 @mpz_mul_si(i32 %44, i32 %45, i32 %46)
br label %48
48: ; preds = %34, %20
ret void
}

LLVM IR (-O2):
define void @bits_to_target(i32 %0, i32 %1) {
%3 = and i32 %0, 8388607
%4 = lshr i32 %0, 24
%5 = icmp ult i32 %0, 67108864
%6 = tail call i32 @mpz_init_set_ui(i32 %1, i32 %3)
br i1 %5, label %7, label %11
7: ; preds = %2
%8 = mul nsw i32 %4, -8
%9 = add nsw i32 %8, 24
%10 = tail call i32 @mpz_tdiv_q_2exp(i32 %1, i32 %1, i32 %9)
br label %15
11: ; preds = %2
%12 = shl nuw nsw i32 %4, 3
%13 = add nsw i32 %12, -24
%14 = tail call i32 @mpz_mul_2exp(i32 %1, i32 %1, i32 %13)
br label %15
15: ; preds = %11, %7
%16 = and i32 %0, 8388608
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i32 1, i32 -1
%19 = tail call i32 @mpz_mul_si(i32 %1, i32 %1, i32 %18)
ret void
}