#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*/ DSA;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int BN_num_bits(int /*<<< orphan*/ const *);
int /*<<< orphan*/ DSA_get0_key(int /*<<< orphan*/ *,
                                int /*<<< orphan*/ const **,
                                int /*<<< orphan*/ const **);
int /*<<< orphan*/ DSA_get0_pqg(int /*<<< orphan*/ *,
                                int /*<<< orphan*/ const **,
                                int /*<<< orphan*/ const **,
                                int /*<<< orphan*/ const **);
int /*<<< orphan*/ PEM_F_CHECK_BITLEN_DSA;
int /*<<< orphan*/ PEM_R_UNSUPPORTED_KEY_COMPONENTS;
int /*<<< orphan*/ PEMerr(int /*<<< orphan*/, int /*<<< orphan*/);
int check_bitlen_dsa(DSA *dsa, int ispub, unsigned int *pmagic) {
  int bitlen;
  const BIGNUM *p = NULL, *q = NULL, *g = NULL;
  const BIGNUM *pub_key = NULL, *priv_key = NULL;
  DSA_get0_pqg(dsa, &p, &q, &g);
  DSA_get0_key(dsa, &pub_key, &priv_key);
  bitlen = BN_num_bits(p);
  if ((bitlen & 7) || (BN_num_bits(q) != 160) || (BN_num_bits(g) > bitlen))
    goto badkey;
  if (ispub) {
    if (BN_num_bits(pub_key) > bitlen)
      goto badkey;
    *pmagic = 0x31535344L;
  } else {
    if (BN_num_bits(priv_key) > 160)
      goto badkey;
    *pmagic = 0x32535344L;
  }
  return bitlen;
badkey:
  PEMerr(PEM_F_CHECK_BITLEN_DSA, PEM_R_UNSUPPORTED_KEY_COMPONENTS);
  return 0;
}


x86 assembly (clang, -O0):
<check_bitlen_dsa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1060 <DSA_get0_pqg@plt>
mov    -0x10(%rbp),%rdi
lea    -0x48(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1050 <DSA_get0_key@plt>
mov    -0x30(%rbp),%rdi
call   1030 <BN_num_bits@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    11e2 <check_bitlen_dsa+0xa2>
mov    -0x38(%rbp),%rdi
call   1030 <BN_num_bits@plt>
cmp    $0xa0,%eax
jne    11e2 <check_bitlen_dsa+0xa2>
mov    -0x40(%rbp),%rdi
call   1030 <BN_num_bits@plt>
cmp    -0x24(%rbp),%eax
jle    11e7 <check_bitlen_dsa+0xa7>
jmp    1245 <check_bitlen_dsa+0x105>
cmpl   $0x0,-0x14(%rbp)
je     1217 <check_bitlen_dsa+0xd7>
mov    -0x48(%rbp),%rdi
call   1030 <BN_num_bits@plt>
cmp    -0x24(%rbp),%eax
jle    1208 <check_bitlen_dsa+0xc8>
jmp    1245 <check_bitlen_dsa+0x105>
mov    -0x20(%rbp),%rax
movl   $0x31535344,(%rax)
jmp    123a <check_bitlen_dsa+0xfa>
mov    -0x50(%rbp),%rdi
call   1030 <BN_num_bits@plt>
cmp    $0xa0,%eax
jle    1230 <check_bitlen_dsa+0xf0>
jmp    1245 <check_bitlen_dsa+0x105>
mov    -0x20(%rbp),%rax
movl   $0x32535344,(%rax)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1263 <check_bitlen_dsa+0x123>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_bitlen_dsa>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%rbp
movq   $0x0,0x28(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x28(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   1060 <DSA_get0_pqg@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
call   1050 <DSA_get0_key@plt>
mov    0x28(%rsp),%rdi
call   1030 <BN_num_bits@plt>
mov    %eax,%ebp
test   $0x7,%bpl
jne    11eb <check_bitlen_dsa+0xab>
mov    0x20(%rsp),%rdi
call   1030 <BN_num_bits@plt>
cmp    $0xa0,%eax
jne    11eb <check_bitlen_dsa+0xab>
mov    0x18(%rsp),%rdi
call   1030 <BN_num_bits@plt>
cmp    %ebp,%eax
jg     11eb <check_bitlen_dsa+0xab>
test   %ebx,%ebx
je     120f <check_bitlen_dsa+0xcf>
mov    0x10(%rsp),%rdi
call   1030 <BN_num_bits@plt>
mov    $0x31535344,%ecx
cmp    %ebp,%eax
jle    1225 <check_bitlen_dsa+0xe5>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x8(%rsp),%rdi
call   1030 <BN_num_bits@plt>
mov    $0x32535344,%ecx
cmp    $0xa0,%eax
jg     11eb <check_bitlen_dsa+0xab>
mov    %ecx,(%r14)
jmp    1204 <check_bitlen_dsa+0xc4>

LLVM IR (-O0):
@PEM_F_CHECK_BITLEN_DSA = global i32 0
@PEM_R_UNSUPPORTED_KEY_COMPONENTS = global i32 0
define i32 @check_bitlen_dsa(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* null, i32** %9
store i32* null, i32** %10
store i32* null, i32** %11
store i32* null, i32** %12
store i32* null, i32** %13
%14 = load i32*, i32** %5
%15 = call i32 @DSA_get0_pqg(i32* %14, i32** %9, i32** %10, i32** %11)
%16 = load i32*, i32** %5
%17 = call i32 @DSA_get0_key(i32* %16, i32** %12, i32** %13)
%18 = load i32*, i32** %9
%19 = call i32 @BN_num_bits(i32* %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = and i32 %20, 7
%22 = icmp ne i32 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %3
%24 = load i32*, i32** %10
%25 = call i32 @BN_num_bits(i32* %24)
%26 = icmp ne i32 %25, 160
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = load i32*, i32** %11
%29 = call i32 @BN_num_bits(i32* %28)
%30 = load i32, i32* %8
%31 = icmp sgt i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %27, %23, %3
br label %53
33: ; preds = %27
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %33
%37 = load i32*, i32** %12
%38 = call i32 @BN_num_bits(i32* %37)
%39 = load i32, i32* %8
%40 = icmp sgt i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %36
br label %53
42: ; preds = %36
%43 = load i32*, i32** %7
store i32 827544388, i32* %43
br label %51
44: ; preds = %33
%45 = load i32*, i32** %13
%46 = call i32 @BN_num_bits(i32* %45)
%47 = icmp sgt i32 %46, 160
br i1 %47, label %48, label %49
48: ; preds = %44
br label %53
49: ; preds = %44
%50 = load i32*, i32** %7
store i32 844321604, i32* %50
br label %51
51: ; preds = %49, %42
%52 = load i32, i32* %8
store i32 %52, i32* %4
br label %57
53: ; preds = %48, %41, %32
%54 = load i32, i32* @PEM_F_CHECK_BITLEN_DSA
%55 = load i32, i32* @PEM_R_UNSUPPORTED_KEY_COMPONENTS
%56 = call i32 @PEMerr(i32 %54, i32 %55)
store i32 0, i32* %4
br label %57
57: ; preds = %53, %51
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@PEM_F_CHECK_BITLEN_DSA = global i32 0
@PEM_R_UNSUPPORTED_KEY_COMPONENTS = global i32 0
define i32 @check_bitlen_dsa(i32* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = bitcast i32** %4 to i8*
store i32* null, i32** %4
%10 = bitcast i32** %5 to i8*
store i32* null, i32** %5
%11 = bitcast i32** %6 to i8*
store i32* null, i32** %6
%12 = bitcast i32** %7 to i8*
store i32* null, i32** %7
%13 = bitcast i32** %8 to i8*
store i32* null, i32** %8
%14 = call i32 @DSA_get0_pqg(i32* %0, i32** %4, i32** %5, i32** %6)
%15 = call i32 @DSA_get0_key(i32* %0, i32** %7, i32** %8)
%16 = load i32*, i32** %4
%17 = call i32 @BN_num_bits(i32* %16)
%18 = and i32 %17, 7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %40
20: ; preds = %3
%21 = load i32*, i32** %5
%22 = call i32 @BN_num_bits(i32* %21)
%23 = icmp eq i32 %22, 160
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i32*, i32** %6
%26 = call i32 @BN_num_bits(i32* %25)
%27 = icmp sgt i32 %26, %17
br i1 %27, label %40, label %28
28: ; preds = %24
%29 = icmp eq i32 %1, 0
br i1 %29, label %34, label %30
30: ; preds = %28
%31 = load i32*, i32** %7
%32 = call i32 @BN_num_bits(i32* %31)
%33 = icmp sgt i32 %32, %17
br i1 %33, label %40, label %38
34: ; preds = %28
%35 = load i32*, i32** %8
%36 = call i32 @BN_num_bits(i32* %35)
%37 = icmp sgt i32 %36, 160
br i1 %37, label %40, label %38
38: ; preds = %34, %30
%39 = phi i32 [ 827544388, %30 ], [ 844321604, %34 ]
store i32 %39, i32* %2
br label %44
40: ; preds = %34, %30, %3, %20, %24
%41 = load i32, i32* @PEM_F_CHECK_BITLEN_DSA
%42 = load i32, i32* @PEM_R_UNSUPPORTED_KEY_COMPONENTS
%43 = call i32 @PEMerr(i32 %41, i32 %42)
br label %44
44: ; preds = %40, %38
%45 = phi i32 [ 0, %40 ], [ %17, %38 ]
ret i32 %45
}