#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 uint8_t;

/* Variables and functions */
scalar_t__ crypto_dh_generate(int *, int *);
int /*<<< orphan*/ libcperciva_HMAC_SHA256_Buf(int const *, int, int *, int,
                                               int *);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int proto_crypt_dh_generate(uint8_t yh_l[(256 + 32)], uint8_t x[32],
                            const uint8_t dhmac_l[32], int nofps) {
  if (nofps) {
    memset(yh_l, 0, 256 - 1);
    yh_l[256 - 1] = 1;
  } else {
    if (crypto_dh_generate(yh_l, x))
      goto err0;
  }
  libcperciva_HMAC_SHA256_Buf(dhmac_l, 32, yh_l, 256, &yh_l[256]);
  return (0);
err0:
  return (-1);
}


x86 assembly (clang, -O0):
<proto_crypt_dh_generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1174 <proto_crypt_dh_generate+0x44>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
movl   $0x1,0x3fc(%rax)
jmp    1195 <proto_crypt_dh_generate+0x65>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <crypto_dh_generate@plt>
cmp    $0x0,%rax
je     1190 <proto_crypt_dh_generate+0x60>
jmp    11c3 <proto_crypt_dh_generate+0x93>
jmp    1195 <proto_crypt_dh_generate+0x65>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%r8
add    $0x400,%r8
mov    $0x20,%esi
mov    $0x100,%ecx
call   1050 <libcperciva_HMAC_SHA256_Buf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ca <proto_crypt_dh_generate+0x9a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proto_crypt_dh_generate>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
test   %ecx,%ecx
je     1156 <proto_crypt_dh_generate+0x26>
xor    %esi,%esi
mov    $0xff,%edx
call   1040 <memset@plt>
movl   $0x1,0x3fc(%rbx)
jmp    1168 <proto_crypt_dh_generate+0x38>
call   1030 <crypto_dh_generate@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1186 <proto_crypt_dh_generate+0x56>
lea    0x400(%rbx),%r8
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
mov    $0x100,%ecx
call   1050 <libcperciva_HMAC_SHA256_Buf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @proto_crypt_dh_generate(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %4
%13 = load i32*, i32** %6
%14 = call i32 @memset(i32* %13, i32 0, i32 255)
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i64 255
store i32 1, i32* %16
br label %24
17: ; preds = %4
%18 = load i32*, i32** %6
%19 = load i32*, i32** %7
%20 = call i64 @crypto_dh_generate(i32* %18, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %30
23: ; preds = %17
br label %24
24: ; preds = %23, %12
%25 = load i32*, i32** %8
%26 = load i32*, i32** %6
%27 = load i32*, i32** %6
%28 = getelementptr inbounds i32, i32* %27, i64 256
%29 = call i32 @libcperciva_HMAC_SHA256_Buf(i32* %25, i32 32, i32* %26, i32 256, i32* %28)
store i32 0, i32* %5
br label %31
30: ; preds = %22
store i32 -1, i32* %5
br label %31
31: ; preds = %30, %24
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @proto_crypt_dh_generate(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = tail call i32 @memset(i32* %0, i32 0, i32 255)
%8 = getelementptr inbounds i32, i32* %0, i64 255
store i32 1, i32* %8
br label %12
9: ; preds = %4
%10 = tail call i64 @crypto_dh_generate(i32* %0, i32* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9, %6
%13 = getelementptr inbounds i32, i32* %0, i64 256
%14 = tail call i32 @libcperciva_HMAC_SHA256_Buf(i32* %2, i32 32, i32* %0, i32 256, i32* %13)
br label %15
15: ; preds = %9, %12
%16 = phi i32 [ 0, %12 ], [ -1, %9 ]
ret i32 %16
}