#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*/ SHA256_NSS(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ check_KAT(unsigned char *, unsigned char *, int, char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
SHA256_NSS_KAT_2() {
  unsigned char *input = malloc(sizeof(char) * 1000000);
  char to_repeat[] = "a";
  int i;
  for (i = 0; i < 1000000; i++) {
    memcpy(input + i * 1, to_repeat, 1);
  }
  unsigned char result[32];
  unsigned char expected_result[32] = {
      0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92, 0x81, 0xA1, 0xC7,
      0xE2, 0x84, 0xD7, 0x3E, 0x67, 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97,
      0x20, 0x0E, 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0};
  SHA256_NSS(input, result, 1000000);
  check_KAT(result, expected_result, 32, "SHA256_NSS_KAT_2");
}


x86 assembly (clang, -O0):
<SHA256_NSS_KAT_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    $0xf4240,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    0xea3(%rip),%ax
mov    %ax,-0x12(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0xf4240,-0x18(%rbp)
jge    11a0 <SHA256_NSS_KAT_2+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
shl    $0x0,%eax
cltq
add    %rax,%rdi
lea    -0x12(%rbp),%rsi
mov    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <SHA256_NSS_KAT_2+0x28>
mov    0xe79(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe76(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xf4240,%edx
call   1030 <SHA256_NSS@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x20,%edx
lea    0xe10(%rip),%rcx
call   1060 <check_KAT@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHA256_NSS_KAT_2>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    $0xf4240,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
movw   $0x61,0xe(%rsp)
xor    %ebx,%ebx
lea    0xe(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%rbx,1),%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <memcpy@plt>
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    1170 <SHA256_NSS_KAT_2+0x30>
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe5f(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x30(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xf4240,%edx
call   1030 <SHA256_NSS@plt>
lea    0xe5e(%rip),%rcx
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x20,%edx
call   1060 <check_KAT@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.SHA256_NSS_KAT_2.to_repeat = [2 x i8] c"a\00"
@__const.SHA256_NSS_KAT_2.expected_result = [32 x i8] c"\CD\C7n\\\99\14\FB\92\81\A1\C7\E2\84\D7>g\F1\80\9AH\A4\97 \0E\04m9\CC\C7\11,\D0"
@.str = [17 x i8] c"SHA256_NSS_KAT_2\00"
define i32 @SHA256_NSS_KAT_2() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [2 x i8]
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = call i8* @malloc(i32 1000000)
store i8* %7, i8** %2
%8 = bitcast [2 x i8]* %3 to i8*
store i32 0, i32* %4
br label %9
9: ; preds = %20, %0
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 1000000
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = mul nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%19 = call i32 @memcpy(i8* %17, i8* %18, i32 1)
br label %20
20: ; preds = %12
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %9
23: ; preds = %9
%24 = bitcast [32 x i8]* %6 to i8*
%25 = load i8*, i8** %2
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%27 = call i32 @SHA256_NSS(i8* %25, i8* %26, i32 1000000)
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%30 = call i32 @check_KAT(i8* %28, i8* %29, i32 32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@__const.SHA256_NSS_KAT_2.expected_result = [32 x i8] c"\CD\C7n\\\99\14\FB\92\81\A1\C7\E2\84\D7>g\F1\80\9AH\A4\97 \0E\04m9\CC\C7\11,\D0"
@.str = [17 x i8] c"SHA256_NSS_KAT_2\00"
define i32 @SHA256_NSS_KAT_2() {
%1 = alloca i16
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = tail call dereferenceable_or_null(1000000) i8* @malloc(i32 1000000)
%5 = bitcast i16* %1 to i8*
store i16 97, i16* %1
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 0, %0 ], [ %10, %6 ]
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = call i32 @memcpy(i8* %8, i8* %5, i32 1)
%10 = add nuw nsw i64 %7, 1
%11 = icmp eq i64 %10, 1000000
br i1 %11, label %12, label %6
12: ; preds = %6
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%15 = call i32 @SHA256_NSS(i8* %4, i8* %13, i32 1000000)
%16 = call i32 @check_KAT(i8* %13, i8* %14, i32 32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
ret i32 undef
}