#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*/ GetHash(unsigned char *, unsigned char **, int, char **);
int /*<<< orphan*/ GetHexHash(unsigned char *, unsigned char **, char **);
int /*<<< orphan*/ GetJnHash(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ GetSquareRootsModulo(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/, int /*<<< orphan*/,
                                        int /*<<< orphan*/, int /*<<< orphan*/,
                                        char **);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int mpz_legendre(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_str(int /*<<< orphan*/, unsigned char *, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void KeyGen(unsigned char *identity, mpz_t *rj, mpz_t n, mpz_t u, mpz_t p,
            mpz_t q, int l, char **error) {
  int i, w;
  mpz_t uRj, z[4];
  unsigned char *hash, *hex_hash;
  mpz_init(uRj);
  srand(time(NULL));
  for (i = 0; i < 4; i++)
    mpz_init(z[i]);
  for (i = 0; i < l; i++) {
    GetHash(identity, &hash, i, error);
    if (strcmp(*error, "success") != 0)
      return;
    GetHexHash(hash, &hex_hash, error);
    if (strcmp(*error, "success") != 0)
      return;
    mpz_set_str(uRj, hex_hash, 16);
    mpz_mod(uRj, uRj, n);
    GetJnHash(n, uRj);
    w = rand() % 4;
    if (mpz_legendre(uRj, p) == -1 || mpz_legendre(uRj, q) == -1) {
      mpz_mul(uRj, u, uRj);
      mpz_mod(uRj, uRj, n);
    }
    GetSquareRootsModulo(z, uRj, p, q, n, error);
    if (strcmp(*error, "success") != 0)
      return;
    mpz_set(rj[i], z[w]);
    free(hash);
    free(hex_hash);
  }
  for (i = 0; i < 4; i++)
    mpz_clear(z[i]);
  mpz_clear(uRj);
}


x86 assembly (clang, -O0):
<KeyGen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x2c(%rbp),%edi
call   1080 <mpz_init@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1269 <KeyGen+0x69>
movslq -0x24(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edi
call   1080 <mpz_init@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1244 <KeyGen+0x44>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    13d9 <KeyGen+0x1d9>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    0x18(%rbp),%rcx
lea    -0x48(%rbp),%rsi
call   1110 <GetHash@plt>
mov    0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xd62(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     12b2 <KeyGen+0xb2>
jmp    140d <KeyGen+0x20d>
mov    -0x48(%rbp),%rdi
mov    0x18(%rbp),%rdx
lea    -0x50(%rbp),%rsi
call   1060 <GetHexHash@plt>
mov    0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xd2f(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     12e5 <KeyGen+0xe5>
jmp    140d <KeyGen+0x20d>
mov    -0x2c(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   10d0 <mpz_set_str@plt>
mov    -0x2c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10e0 <mpz_mod@plt>
mov    -0x14(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1100 <GetJnHash@plt>
mov    $0x0,%al
call   1120 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <mpz_legendre@plt>
cmp    $0xffffffff,%eax
je     1349 <KeyGen+0x149>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1050 <mpz_legendre@plt>
cmp    $0xffffffff,%eax
jne    1365 <KeyGen+0x165>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   10b0 <mpz_mul@plt>
mov    -0x2c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10e0 <mpz_mod@plt>
lea    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    0x18(%rbp),%r9
call   10a0 <GetSquareRootsModulo@plt>
mov    0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xc73(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     13a1 <KeyGen+0x1a1>
jmp    140d <KeyGen+0x20d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
movslq -0x28(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
call   1040 <mpz_set@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1270 <KeyGen+0x70>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1405 <KeyGen+0x205>
movslq -0x24(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edi
call   10f0 <mpz_clear@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    13e0 <KeyGen+0x1e0>
mov    -0x2c(%rbp),%edi
call   10f0 <mpz_clear@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KeyGen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9d,0x4(%rsp)
mov    %r8d,0x8(%rsp)
mov    %ecx,0xc(%rsp)
mov    %edx,%ebx
mov    %rsi,0x38(%rsp)
mov    %rdi,0x40(%rsp)
mov    0x88(%rsp),%r14
call   1080 <mpz_init@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
call   1080 <mpz_init@plt>
call   1080 <mpz_init@plt>
call   1080 <mpz_init@plt>
call   1080 <mpz_init@plt>
lea    0xda2(%rip),%rbp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x40(%rsp),%rdi
lea    0x30(%rsp),%rsi
mov    %r13d,%edx
mov    %r14,%rcx
call   1110 <GetHash@plt>
mov    (%r14),%rdi
mov    %rbp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    13b1 <KeyGen+0x1b1>
mov    0x30(%rsp),%rdi
lea    0x28(%rsp),%rsi
mov    %r14,%rdx
call   1060 <GetHexHash@plt>
mov    (%r14),%rdi
mov    %rbp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    13b1 <KeyGen+0x1b1>
mov    0x28(%rsp),%rsi
mov    $0x10,%edx
call   10d0 <mpz_set_str@plt>
mov    %ebx,%edx
call   10e0 <mpz_mod@plt>
mov    %ebx,%edi
call   1100 <GetJnHash@plt>
xor    %eax,%eax
call   1120 <rand@plt>
mov    %eax,%r15d
lea    0x3(%r15),%r12d
test   %eax,%eax
cmovns %eax,%r12d
mov    0x8(%rsp),%esi
call   1050 <mpz_legendre@plt>
cmp    $0xffffffff,%eax
je     130c <KeyGen+0x10c>
mov    0x4(%rsp),%esi
call   1050 <mpz_legendre@plt>
cmp    $0xffffffff,%eax
jne    131c <KeyGen+0x11c>
mov    0xc(%rsp),%esi
call   10b0 <mpz_mul@plt>
mov    %ebx,%edx
call   10e0 <mpz_mod@plt>
lea    0x10(%rsp),%rdi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %ebx,%r8d
mov    %r14,%r9
call   10a0 <GetSquareRootsModulo@plt>
mov    (%r14),%rdi
mov    %rbp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    13b1 <KeyGen+0x1b1>
and    $0xfffffffc,%r12d
sub    %r12d,%r15d
mov    0x38(%rsp),%rax
mov    (%rax,%r13,4),%edi
movslq %r15d,%rax
mov    0x10(%rsp,%rax,4),%esi
call   1040 <mpz_set@plt>
mov    0x30(%rsp),%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
add    $0x1,%r13
mov    0x80(%rsp),%eax
cmp    %r13,%rax
jne    1270 <KeyGen+0x70>
mov    0x10(%rsp),%edi
call   10f0 <mpz_clear@plt>
mov    0x14(%rsp),%edi
call   10f0 <mpz_clear@plt>
mov    0x18(%rsp),%edi
call   10f0 <mpz_clear@plt>
mov    0x1c(%rsp),%edi
call   10f0 <mpz_clear@plt>
call   10f0 <mpz_clear@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"success\00"
define void @KeyGen(i8* %0, i32* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i8** %7) {
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8**
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca [4 x i32]
%21 = alloca i8*
%22 = alloca i8*
store i8* %0, i8** %9
store i32* %1, i32** %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i8** %7, i8*** %16
%23 = load i32, i32* %19
%24 = call i32 @mpz_init(i32 %23)
%25 = call i32 @time(i32* null)
%26 = call i32 @srand(i32 %25)
store i32 0, i32* %17
br label %27
27: ; preds = %36, %8
%28 = load i32, i32* %17
%29 = icmp slt i32 %28, 4
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %17
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @mpz_init(i32 %34)
br label %36
36: ; preds = %30
%37 = load i32, i32* %17
%38 = add nsw i32 %37, 1
store i32 %38, i32* %17
br label %27
39: ; preds = %27
store i32 0, i32* %17
br label %40
40: ; preds = %122, %39
%41 = load i32, i32* %17
%42 = load i32, i32* %15
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %125
44: ; preds = %40
%45 = load i8*, i8** %9
%46 = load i32, i32* %17
%47 = load i8**, i8*** %16
%48 = call i32 @GetHash(i8* %45, i8** %21, i32 %46, i8** %47)
%49 = load i8**, i8*** %16
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %44
br label %141
54: ; preds = %44
%55 = load i8*, i8** %21
%56 = load i8**, i8*** %16
%57 = call i32 @GetHexHash(i8* %55, i8** %22, i8** %56)
%58 = load i8**, i8*** %16
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %54
br label %141
63: ; preds = %54
%64 = load i32, i32* %19
%65 = load i8*, i8** %22
%66 = call i32 @mpz_set_str(i32 %64, i8* %65, i32 16)
%67 = load i32, i32* %19
%68 = load i32, i32* %19
%69 = load i32, i32* %11
%70 = call i32 @mpz_mod(i32 %67, i32 %68, i32 %69)
%71 = load i32, i32* %11
%72 = load i32, i32* %19
%73 = call i32 @GetJnHash(i32 %71, i32 %72)
%74 = call i32 (...) @rand()
%75 = srem i32 %74, 4
store i32 %75, i32* %18
%76 = load i32, i32* %19
%77 = load i32, i32* %13
%78 = call i32 @mpz_legendre(i32 %76, i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %85, label %80
80: ; preds = %63
%81 = load i32, i32* %19
%82 = load i32, i32* %14
%83 = call i32 @mpz_legendre(i32 %81, i32 %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %94
85: ; preds = %80, %63
%86 = load i32, i32* %19
%87 = load i32, i32* %12
%88 = load i32, i32* %19
%89 = call i32 @mpz_mul(i32 %86, i32 %87, i32 %88)
%90 = load i32, i32* %19
%91 = load i32, i32* %19
%92 = load i32, i32* %11
%93 = call i32 @mpz_mod(i32 %90, i32 %91, i32 %92)
br label %94
94: ; preds = %85, %80
%95 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%96 = load i32, i32* %19
%97 = load i32, i32* %13
%98 = load i32, i32* %14
%99 = load i32, i32* %11
%100 = load i8**, i8*** %16
%101 = call i32 @GetSquareRootsModulo(i32* %95, i32 %96, i32 %97, i32 %98, i32 %99, i8** %100)
%102 = load i8**, i8*** %16
%103 = load i8*, i8** %102
%104 = call i64 @strcmp(i8* %103, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %107
106: ; preds = %94
br label %141
107: ; preds = %94
%108 = load i32*, i32** %10
%109 = load i32, i32* %17
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i32, i32* %108, i64 %110
%112 = load i32, i32* %111
%113 = load i32, i32* %18
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 %114
%116 = load i32, i32* %115
%117 = call i32 @mpz_set(i32 %112, i32 %116)
%118 = load i8*, i8** %21
%119 = call i32 @free(i8* %118)
%120 = load i8*, i8** %22
%121 = call i32 @free(i8* %120)
br label %122
122: ; preds = %107
%123 = load i32, i32* %17
%124 = add nsw i32 %123, 1
store i32 %124, i32* %17
br label %40
125: ; preds = %40
store i32 0, i32* %17
br label %126
126: ; preds = %135, %125
%127 = load i32, i32* %17
%128 = icmp slt i32 %127, 4
br i1 %128, label %129, label %138
129: ; preds = %126
%130 = load i32, i32* %17
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 %131
%133 = load i32, i32* %132
%134 = call i32 @mpz_clear(i32 %133)
br label %135
135: ; preds = %129
%136 = load i32, i32* %17
%137 = add nsw i32 %136, 1
store i32 %137, i32* %17
br label %126
138: ; preds = %126
%139 = load i32, i32* %19
%140 = call i32 @mpz_clear(i32 %139)
br label %141
141: ; preds = %138, %106, %62, %53
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"success\00"
define void @KeyGen(i8* %0, i32* nocapture %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i8** %7) {
%9 = alloca [4 x i32]
%10 = alloca i8*
%11 = alloca i8*
%12 = bitcast [4 x i32]* %9 to i8*
%13 = bitcast i8** %10 to i8*
%14 = bitcast i8** %11 to i8*
%15 = tail call i32 @mpz_init(i32 undef)
%16 = tail call i32 @time(i32* null)
%17 = tail call i32 @srand(i32 %16)
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%19 = tail call i32 @mpz_init(i32 undef)
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 1
%21 = tail call i32 @mpz_init(i32 undef)
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 2
%23 = tail call i32 @mpz_init(i32 undef)
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
%25 = tail call i32 @mpz_init(i32 undef)
%26 = icmp sgt i32 %6, 0
%27 = zext i32 %6 to i64
br label %38
28: ; preds = %71
%29 = load i32, i32* %18
%30 = call i32 @mpz_clear(i32 %29)
%31 = load i32, i32* %20
%32 = call i32 @mpz_clear(i32 %31)
%33 = load i32, i32* %22
%34 = call i32 @mpz_clear(i32 %33)
%35 = load i32, i32* %24
%36 = call i32 @mpz_clear(i32 %35)
%37 = call i32 @mpz_clear(i32 undef)
br label %84
38: ; preds = %8, %71
%39 = phi i64 [ 0, %8 ], [ %82, %71 ]
%40 = trunc i64 %39 to i32
%41 = call i32 @GetHash(i8* %0, i8** %10, i32 %40, i8** %7)
%42 = load i8*, i8** %7
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %84
45: ; preds = %38
%46 = load i8*, i8** %10
%47 = call i32 @GetHexHash(i8* %46, i8** %11, i8** %7)
%48 = load i8*, i8** %7
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %84
51: ; preds = %45
%52 = load i8*, i8** %11
%53 = call i32 @mpz_set_str(i32 undef, i8* %52, i32 16)
%54 = call i32 @mpz_mod(i32 undef, i32 undef, i32 %2)
%55 = call i32 @GetJnHash(i32 %2, i32 undef)
%56 = call i32 (...) @rand()
%57 = srem i32 %56, 4
%58 = call i32 @mpz_legendre(i32 undef, i32 %4)
%59 = icmp eq i32 %58, -1
br i1 %59, label %63, label %60
60: ; preds = %51
%61 = call i32 @mpz_legendre(i32 undef, i32 %5)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %66
63: ; preds = %60, %51
%64 = call i32 @mpz_mul(i32 undef, i32 %3, i32 undef)
%65 = call i32 @mpz_mod(i32 undef, i32 undef, i32 %2)
br label %66
66: ; preds = %63, %60
%67 = call i32 @GetSquareRootsModulo(i32* %18, i32 undef, i32 %4, i32 %5, i32 %2, i8** %7)
%68 = load i8*, i8** %7
%69 = call i64 @strcmp(i8* %68, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %84
71: ; preds = %66
%72 = getelementptr inbounds i32, i32* %1, i64 %39
%73 = load i32, i32* %72
%74 = sext i32 %57 to i64
%75 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 %74
%76 = load i32, i32* %75
%77 = call i32 @mpz_set(i32 %73, i32 %76)
%78 = load i8*, i8** %10
%79 = call i32 @free(i8* %78)
%80 = load i8*, i8** %11
%81 = call i32 @free(i8* %80)
%82 = add nuw nsw i64 %39, 1
%83 = icmp eq i64 %82, %27
br i1 %83, label %28, label %38
84: ; preds = %66, %45, %38, %28
ret void
}