#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 */
unsigned char *GetHash(unsigned char *, char **);
unsigned char *GetHexHash(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, 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]);
  hash = GetHash(identity, error);
  if (strcmp(*error, "success") != 0)
    return;
  hex_hash = GetHexHash(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, 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    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    -0x28(%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,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    1265 <KeyGen+0x65>
movslq -0x20(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edi
call   1080 <mpz_init@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1240 <KeyGen+0x40>
mov    -0x8(%rbp),%rdi
mov    0x10(%rbp),%rsi
call   1110 <GetHash@plt>
mov    %rax,-0x48(%rbp)
mov    0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd7c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1298 <KeyGen+0x98>
jmp    13dd <KeyGen+0x1dd>
mov    -0x48(%rbp),%rdi
mov    0x10(%rbp),%rsi
call   1060 <GetHexHash@plt>
mov    %rax,-0x50(%rbp)
mov    0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd49(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     12cb <KeyGen+0xcb>
jmp    13dd <KeyGen+0x1dd>
mov    -0x28(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   10d0 <mpz_set_str@plt>
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10e0 <mpz_mod@plt>
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1100 <GetJnHash@plt>
mov    $0x0,%al
call   1120 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <mpz_legendre@plt>
cmp    $0xffffffff,%eax
je     132f <KeyGen+0x12f>
mov    -0x28(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <mpz_legendre@plt>
cmp    $0xffffffff,%eax
jne    134b <KeyGen+0x14b>
mov    -0x28(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%edx
call   10b0 <mpz_mul@plt>
mov    -0x28(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10e0 <mpz_mod@plt>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    0x10(%rbp),%r9
call   10a0 <GetSquareRootsModulo@plt>
mov    0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xc8d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1387 <KeyGen+0x187>
jmp    13dd <KeyGen+0x1dd>
mov    -0xc(%rbp),%edi
movslq -0x24(%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>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    13d5 <KeyGen+0x1d5>
movslq -0x20(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edi
call   10f0 <mpz_clear@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    13b0 <KeyGen+0x1b0>
mov    -0x28(%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    $0x28,%rsp
mov    %r9d,%r14d
mov    %r8d,%r12d
mov    %ecx,0xc(%rsp)
mov    %edx,%r15d
mov    %esi,0x8(%rsp)
mov    %rdi,%rbp
mov    0x60(%rsp),%rbx
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>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1110 <GetHash@plt>
mov    %rax,%r13
mov    (%rbx),%rdi
lea    0xd9a(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    137f <KeyGen+0x17f>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <GetHexHash@plt>
mov    %rax,%rbp
mov    (%rbx),%rdi
lea    0xd74(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    137f <KeyGen+0x17f>
mov    %r14d,0x4(%rsp)
mov    %rbp,0x20(%rsp)
mov    %rbp,%rsi
mov    $0x10,%edx
call   10d0 <mpz_set_str@plt>
mov    %r15d,%edx
call   10e0 <mpz_mod@plt>
mov    %r15d,%edi
call   1100 <GetJnHash@plt>
xor    %eax,%eax
call   1120 <rand@plt>
mov    %eax,%r14d
lea    0x3(%r14),%ebp
test   %eax,%eax
cmovns %eax,%ebp
mov    %r12d,%esi
call   1050 <mpz_legendre@plt>
cmp    $0xffffffff,%eax
je     12ef <KeyGen+0xef>
mov    0x4(%rsp),%esi
call   1050 <mpz_legendre@plt>
cmp    $0xffffffff,%eax
jne    1300 <KeyGen+0x100>
mov    0xc(%rsp),%esi
call   10b0 <mpz_mul@plt>
mov    %r15d,%edx
call   10e0 <mpz_mod@plt>
lea    0x10(%rsp),%rdi
mov    %r12d,%edx
mov    0x4(%rsp),%ecx
mov    %r15d,%r8d
mov    %rbx,%r9
call   10a0 <GetSquareRootsModulo@plt>
mov    (%rbx),%rdi
lea    0xcdf(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
mov    0x20(%rsp),%rbx
jne    137f <KeyGen+0x17f>
and    $0xfffffffc,%ebp
sub    %ebp,%r14d
movslq %r14d,%rax
mov    0x10(%rsp,%rax,4),%esi
mov    0x8(%rsp),%edi
call   1040 <mpz_set@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
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    $0x28,%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, i8** %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8**
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [4 x i32]
%19 = alloca i8*
%20 = alloca i8*
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i8** %6, i8*** %14
%21 = load i32, i32* %17
%22 = call i32 @mpz_init(i32 %21)
%23 = call i32 @time(i32* null)
%24 = call i32 @srand(i32 %23)
store i32 0, i32* %15
br label %25
25: ; preds = %34, %7
%26 = load i32, i32* %15
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = load i32, i32* %15
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = call i32 @mpz_init(i32 %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %15
%36 = add nsw i32 %35, 1
store i32 %36, i32* %15
br label %25
37: ; preds = %25
%38 = load i8*, i8** %8
%39 = load i8**, i8*** %14
%40 = call i8* @GetHash(i8* %38, i8** %39)
store i8* %40, i8** %19
%41 = load i8**, i8*** %14
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %37
br label %125
46: ; preds = %37
%47 = load i8*, i8** %19
%48 = load i8**, i8*** %14
%49 = call i8* @GetHexHash(i8* %47, i8** %48)
store i8* %49, i8** %20
%50 = load i8**, i8*** %14
%51 = load i8*, i8** %50
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %46
br label %125
55: ; preds = %46
%56 = load i32, i32* %17
%57 = load i8*, i8** %20
%58 = call i32 @mpz_set_str(i32 %56, i8* %57, i32 16)
%59 = load i32, i32* %17
%60 = load i32, i32* %17
%61 = load i32, i32* %10
%62 = call i32 @mpz_mod(i32 %59, i32 %60, i32 %61)
%63 = load i32, i32* %10
%64 = load i32, i32* %17
%65 = call i32 @GetJnHash(i32 %63, i32 %64)
%66 = call i32 (...) @rand()
%67 = srem i32 %66, 4
store i32 %67, i32* %16
%68 = load i32, i32* %17
%69 = load i32, i32* %12
%70 = call i32 @mpz_legendre(i32 %68, i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %77, label %72
72: ; preds = %55
%73 = load i32, i32* %17
%74 = load i32, i32* %13
%75 = call i32 @mpz_legendre(i32 %73, i32 %74)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %86
77: ; preds = %72, %55
%78 = load i32, i32* %17
%79 = load i32, i32* %11
%80 = load i32, i32* %17
%81 = call i32 @mpz_mul(i32 %78, i32 %79, i32 %80)
%82 = load i32, i32* %17
%83 = load i32, i32* %17
%84 = load i32, i32* %10
%85 = call i32 @mpz_mod(i32 %82, i32 %83, i32 %84)
br label %86
86: ; preds = %77, %72
%87 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 0
%88 = load i32, i32* %17
%89 = load i32, i32* %12
%90 = load i32, i32* %13
%91 = load i32, i32* %10
%92 = load i8**, i8*** %14
%93 = call i32 @GetSquareRootsModulo(i32* %87, i32 %88, i32 %89, i32 %90, i32 %91, i8** %92)
%94 = load i8**, i8*** %14
%95 = load i8*, i8** %94
%96 = call i64 @strcmp(i8* %95, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %86
br label %125
99: ; preds = %86
%100 = load i32, i32* %9
%101 = load i32, i32* %16
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 %102
%104 = load i32, i32* %103
%105 = call i32 @mpz_set(i32 %100, i32 %104)
%106 = load i8*, i8** %19
%107 = call i32 @free(i8* %106)
%108 = load i8*, i8** %20
%109 = call i32 @free(i8* %108)
store i32 0, i32* %15
br label %110
110: ; preds = %119, %99
%111 = load i32, i32* %15
%112 = icmp slt i32 %111, 4
br i1 %112, label %113, label %122
113: ; preds = %110
%114 = load i32, i32* %15
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 %115
%117 = load i32, i32* %116
%118 = call i32 @mpz_clear(i32 %117)
br label %119
119: ; preds = %113
%120 = load i32, i32* %15
%121 = add nsw i32 %120, 1
store i32 %121, i32* %15
br label %110
122: ; preds = %110
%123 = load i32, i32* %17
%124 = call i32 @mpz_clear(i32 %123)
br label %125
125: ; preds = %122, %98, %54, %45
ret void
}

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