#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 */

/* Variables and functions */
int /*<<< orphan*/ crypto_scalarmult_nistp256(unsigned char *, unsigned char *,
                                              unsigned char *);
int /*<<< orphan*/ crypto_scalarmult_nistp256_base(unsigned char *,
                                                   unsigned char *);
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ randombytes(unsigned char *, int);
int main() {
  unsigned char alicesk[32];
  unsigned char alicepk[64];
  unsigned char bobsk[32];
  unsigned char bobpk[64];
  unsigned char bobsec[64];
  unsigned char alicesec[64];
  printf("start\n");
  printf("DH section\n");
  for (int i = 0; i < 10; i++) {
    randombytes(alicesk, 32);
    randombytes(bobsk, 32);
    crypto_scalarmult_nistp256_base(alicepk, alicesk);
    crypto_scalarmult_nistp256_base(bobpk, bobsk);
    crypto_scalarmult_nistp256(bobsec, bobsk, alicepk);
    crypto_scalarmult_nistp256(alicesec, alicesk, bobpk);
    if (memcmp(bobsec, alicesec, 64)) {
      printf("0\n");
    } else {
      printf("1\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x154(%rbp)
cmpl   $0xa,-0x154(%rbp)
jge    1256 <main+0x106>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   1050 <randombytes@plt>
lea    -0x90(%rbp),%rdi
mov    $0x20,%esi
call   1050 <randombytes@plt>
lea    -0x70(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <crypto_scalarmult_nistp256_base@plt>
lea    -0xd0(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1030 <crypto_scalarmult_nistp256_base@plt>
lea    -0x110(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1070 <crypto_scalarmult_nistp256@plt>
lea    -0x150(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1070 <crypto_scalarmult_nistp256@plt>
lea    -0x110(%rbp),%rdi
lea    -0x150(%rbp),%rsi
mov    $0x40,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     1231 <main+0xe1>
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
jmp    123d <main+0xed>
lea    0xdde(%rip),%rdi
call   1040 <printf@plt>
jmp    1242 <main+0xf2>
mov    -0x154(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x154(%rbp)
jmp    1184 <main+0x34>
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%r15d
nop
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
call   1050 <randombytes@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <randombytes@plt>
lea    0x100(%rsp),%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <crypto_scalarmult_nistp256_base@plt>
lea    0xc0(%rsp),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <crypto_scalarmult_nistp256_base@plt>
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <crypto_scalarmult_nistp256@plt>
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1070 <crypto_scalarmult_nistp256@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
lea    0xe08(%rip),%rdi
lea    0xdff(%rip),%rax
cmove  %rax,%rdi
call   1030 <puts@plt>
add    $0xffffffff,%r15d
jne    1180 <main+0x30>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"start\0A\00"
@.str.1 = [12 x i8] c"DH section\0A\00"
@.str.2 = [3 x i8] c"0\0A\00"
@.str.3 = [3 x i8] c"1\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca [64 x i8]
%4 = alloca [32 x i8]
%5 = alloca [64 x i8]
%6 = alloca [64 x i8]
%7 = alloca [64 x i8]
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %11
11: ; preds = %42, %0
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %45
14: ; preds = %11
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%16 = call i32 @randombytes(i8* %15, i32 32)
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%18 = call i32 @randombytes(i8* %17, i32 32)
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%21 = call i32 @crypto_scalarmult_nistp256_base(i8* %19, i8* %20)
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%24 = call i32 @crypto_scalarmult_nistp256_base(i8* %22, i8* %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%28 = call i32 @crypto_scalarmult_nistp256(i8* %25, i8* %26, i8* %27)
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%32 = call i32 @crypto_scalarmult_nistp256(i8* %29, i8* %30, i8* %31)
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%35 = call i64 @memcmp(i8* %33, i8* %34, i32 64)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %14
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %41
39: ; preds = %14
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
br label %42
42: ; preds = %41
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %11
45: ; preds = %11
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@str = [6 x i8] c"start\00"
@str.4 = [11 x i8] c"DH section\00"
@str.5 = [2 x i8] c"1\00"
@str.6 = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca [64 x i8]
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
%5 = alloca [64 x i8]
%6 = alloca [64 x i8]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.4, i64 0, i64 0))
br label %16
15: ; preds = %16
ret i32 0
16: ; preds = %0, %16
%17 = phi i32 [ 0, %0 ], [ %28, %16 ]
%18 = call i32 @randombytes(i8* %7, i32 32)
%19 = call i32 @randombytes(i8* %9, i32 32)
%20 = call i32 @crypto_scalarmult_nistp256_base(i8* %8, i8* %7)
%21 = call i32 @crypto_scalarmult_nistp256_base(i8* %10, i8* %9)
%22 = call i32 @crypto_scalarmult_nistp256(i8* %11, i8* %9, i8* %8)
%23 = call i32 @crypto_scalarmult_nistp256(i8* %12, i8* %7, i8* %10)
%24 = call i64 @memcmp(i8* %11, i8* %12, i32 64)
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0)
%27 = call i32 @puts(i8* dereferenceable(1) %26)
%28 = add nuw nsw i32 %17, 1
%29 = icmp eq i32 %28, 10
br i1 %29, label %15, label %16
}