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

/* Variables and functions */
int /*<<< orphan*/ SHA256_NSS(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ SHA256_VST(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ SHA256_sodium(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ check_test(unsigned char *, unsigned char *, int, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, ...);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, unsigned char *);
void SHA256_compare_read(FILE *fp) {
  unsigned char c;
  int length;
  fscanf(fp, "%d", &length);
  unsigned char *input = malloc(length * sizeof(char));
  int i = 0;
  while (fscanf(fp, "%2hhx", &c) > 0) {
    input[i++] = c;
  }
  printf("Checking string %s\n", input);
  unsigned char result0[32];
  unsigned char result1[32];
  SHA256_VST(input, result0, length * sizeof(char));
  memset(result1, 0, 32);
  SHA256_NSS(input, result1, length * sizeof(char));
  check_test(
      result0, result1, 32,
      "Disagreement between SHA256_VST and SHA256_NSS in SHA256_compare_0\n");
  memset(result1, 0, 32);
  SHA256_sodium(input, result1, length * sizeof(char));
  check_test(result0, result1, 32,
             "Disagreement between SHA256_VST and SHA256_sodium in "
             "SHA256_compare_0\n");
  fscanf(fp, "%s", &c);
}


x86 assembly (clang, -O0):
<SHA256_compare_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe3c(%rip),%rsi
lea    -0x9(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
cmp    $0x0,%rax
jle    11f9 <SHA256_compare_read+0x79>
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11bc <SHA256_compare_read+0x3c>
mov    -0x18(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1030 <SHA256_VST@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1070 <SHA256_NSS@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x20,%edx
lea    0xdc2(%rip),%rcx
call   10a0 <check_test@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
call   1090 <SHA256_sodium@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x20,%edx
lea    0xdc6(%rip),%rcx
call   10a0 <check_test@plt>
mov    -0x8(%rbp),%rdi
lea    0xdfd(%rip),%rsi
lea    -0x9(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHA256_compare_read>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%r13
lea    0xe69(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    0xc(%rsp),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe4d(%rip),%rsi
lea    0xb(%rsp),%rdx
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
test   %rax,%rax
jle    1200 <SHA256_compare_read+0x80>
lea    0xe32(%rip),%r15
lea    0xb(%rsp),%r12
mov    %r14,%rbx
nopl   0x0(%rax)
movzbl 0xb(%rsp),%eax
mov    %al,(%rbx)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
add    $0x1,%rbx
test   %rax,%rax
jg     11e0 <SHA256_compare_read+0x60>
lea    0xe02(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    0xc(%rsp),%edx
lea    0x30(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <SHA256_VST@plt>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <SHA256_NSS@plt>
lea    0xdd0(%rip),%rcx
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x20,%edx
call   10a0 <check_test@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1090 <SHA256_sodium@plt>
lea    0xddf(%rip),%rcx
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x20,%edx
call   10a0 <check_test@plt>
lea    0xe0f(%rip),%rsi
lea    0xb(%rsp),%rdx
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%2hhx\00"
@.str.2 = [20 x i8] c"Checking string %s\0A\00"
@.str.3 = [68 x i8] c"Disagreement between SHA256_VST and SHA256_NSS in SHA256_compare_0\0A\00"
@.str.4 = [71 x i8] c"Disagreement between SHA256_VST and SHA256_sodium in SHA256_compare_0\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define void @SHA256_compare_read(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca [32 x i8]
store i32* %0, i32** %2
%9 = load i32*, i32** %2
%10 = call i64 (i32*, i8*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %5
store i32 0, i32* %6
br label %16
16: ; preds = %20, %1
%17 = load i32*, i32** %2
%18 = call i64 (i32*, i8*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i8, i8* %3
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 %21, i8* %26
br label %16
27: ; preds = %16
%28 = load i8*, i8** %5
%29 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %5
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 1
%35 = trunc i64 %34 to i32
%36 = call i32 @SHA256_VST(i8* %30, i8* %31, i32 %35)
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 0, i32 32)
%39 = load i8*, i8** %5
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 1
%44 = trunc i64 %43 to i32
%45 = call i32 @SHA256_NSS(i8* %39, i8* %40, i32 %44)
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%48 = call i32 @check_test(i8* %46, i8* %47, i32 32, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i32 0, i32 32)
%51 = load i8*, i8** %5
%52 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = mul i64 %54, 1
%56 = trunc i64 %55 to i32
%57 = call i32 @SHA256_sodium(i8* %51, i8* %52, i32 %56)
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%60 = call i32 @check_test(i8* %58, i8* %59, i32 32, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0))
%61 = load i32*, i32** %2
%62 = call i64 (i32*, i8*, ...) @fscanf(i32* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%2hhx\00"
@.str.2 = [20 x i8] c"Checking string %s\0A\00"
@.str.3 = [68 x i8] c"Disagreement between SHA256_VST and SHA256_NSS in SHA256_compare_0\0A\00"
@.str.4 = [71 x i8] c"Disagreement between SHA256_VST and SHA256_sodium in SHA256_compare_0\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define void @SHA256_compare_read(i32* nocapture %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = bitcast i32* %3 to i8*
%7 = call i64 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = call i8* @malloc(i32 %8)
%10 = call i64 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %1, %12
%13 = phi i64 [ %15, %12 ], [ 0, %1 ]
%14 = load i8, i8* %2
%15 = add nuw i64 %13, 1
%16 = getelementptr inbounds i8, i8* %9, i64 %13
store i8 %14, i8* %16
%17 = call i64 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %12, label %19
19: ; preds = %12, %1
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%23 = load i32, i32* %3
%24 = call i32 @SHA256_VST(i8* %9, i8* %21, i32 %23)
%25 = call i32 @memset(i8* %22, i32 0, i32 32)
%26 = load i32, i32* %3
%27 = call i32 @SHA256_NSS(i8* %9, i8* %22, i32 %26)
%28 = call i32 @check_test(i8* %21, i8* %22, i32 32, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @memset(i8* %22, i32 0, i32 32)
%30 = load i32, i32* %3
%31 = call i32 @SHA256_sodium(i8* %9, i8* %22, i32 %30)
%32 = call i32 @check_test(i8* %21, i8* %22, i32 32, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0))
%33 = call i64 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %2)
ret void
}