#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*/ BN_CTX;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ *BN_bin2bn(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int BN_mod(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *);
int BN_num_bytes(int /*<<< orphan*/ *);
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
unsigned char *SHA256_arbitrary(unsigned char const *, int const, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stderr;
BIGNUM *SHA256_mod(const unsigned char *d, const int d_length, BIGNUM *m,
                   BN_CTX *bn_ctx) {
  int ok;
  unsigned char *dgst = NULL;
  int dgst_len;
  BIGNUM *r = NULL;
  dgst_len = 2 * BN_num_bytes(m);
  if ((dgst = SHA256_arbitrary(d, d_length, dgst_len)) == NULL) {
    fprintf(
        stderr, "@@@ %s:%d @@@\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/dstebila/daps/refs/heads/master/bn_extra.c",
        56);
    fflush(stderr);
    ;
    goto err;
  };
  if ((r = BN_bin2bn(dgst, dgst_len, NULL)) == NULL) {
    fprintf(
        stderr, "@@@ %s:%d @@@\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/dstebila/daps/refs/heads/master/bn_extra.c",
        57);
    fflush(stderr);
    ;
    goto err;
  };
  ok = (BN_mod(r, r, m, bn_ctx));
  if (ok != 1) {
    fprintf(
        stderr, "@@@ %s:%d @@@\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/dstebila/daps/refs/heads/master/bn_extra.c",
        58);
    fflush(stderr);
    ;
    goto err;
  };
  goto cleanup;
err:
  r = NULL;
  BN_free(r);
cleanup:
  OPENSSL_free(dgst);
  return r;
}


x86 assembly (clang, -O0):
<SHA256_mod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <BN_num_bytes@plt>
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1060 <SHA256_arbitrary@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1207 <SHA256_mod+0x87>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
lea    0xe25(%rip),%rdx
mov    $0x38,%ecx
call   1050 <fprintf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    12b4 <SHA256_mod+0x134>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <BN_bin2bn@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1259 <SHA256_mod+0xd9>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
lea    0xdd3(%rip),%rdx
mov    $0x39,%ecx
call   1050 <fprintf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    12b4 <SHA256_mod+0x134>
mov    -0x40(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1080 <BN_mod@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     12af <SHA256_mod+0x12f>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    0xd75(%rip),%rsi
lea    0xd7d(%rip),%rdx
mov    $0x3a,%ecx
call   1050 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    12b4 <SHA256_mod+0x134>
jmp    12c5 <SHA256_mod+0x145>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <BN_free@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <OPENSSL_free@plt>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHA256_mod>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1090 <BN_num_bytes@plt>
mov    %eax,%ebx
add    %eax,%ebx
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
call   1060 <SHA256_arbitrary@plt>
mov    %rax,%r12
test   %rax,%rax
je     11e6 <SHA256_mod+0x66>
mov    %r12,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <BN_bin2bn@plt>
test   %rax,%rax
je     11ed <SHA256_mod+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1080 <BN_mod@plt>
mov    $0x3a,%ecx
cmp    $0x1,%eax
jne    11f2 <SHA256_mod+0x72>
jmp    121e <SHA256_mod+0x9e>
mov    $0x38,%ecx
jmp    11f2 <SHA256_mod+0x72>
mov    $0x39,%ecx
mov    0x2de7(%rip),%rbx
mov    (%rbx),%edi
lea    0xdfe(%rip),%rsi
lea    0xe06(%rip),%rdx
call   1050 <fprintf@plt>
mov    (%rbx),%edi
call   1070 <fflush@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <BN_free@plt>
mov    %r12,%rdi
call   10a0 <OPENSSL_free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"@@@ %s:%d @@@\0A\00"
@.str.1 = [133 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dstebila/daps/refs/heads/master/bn_extra.c\00"
define i32* @SHA256_mod(i8* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i8* null, i8** %10
store i32* null, i32** %12
%13 = load i32*, i32** %7
%14 = call i32 @BN_num_bytes(i32* %13)
%15 = mul nsw i32 2, %14
store i32 %15, i32* %11
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i32, i32* %11
%19 = call i8* @SHA256_arbitrary(i8* %16, i32 %17, i32 %18)
store i8* %19, i8** %10
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %26
21: ; preds = %4
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0), i32 56)
%24 = load i32, i32* @stderr
%25 = call i32 @fflush(i32 %24)
br label %50
26: ; preds = %4
%27 = load i8*, i8** %10
%28 = load i32, i32* %11
%29 = call i32* @BN_bin2bn(i8* %27, i32 %28, i32* null)
store i32* %29, i32** %12
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0), i32 57)
%34 = load i32, i32* @stderr
%35 = call i32 @fflush(i32 %34)
br label %50
36: ; preds = %26
%37 = load i32*, i32** %12
%38 = load i32*, i32** %12
%39 = load i32*, i32** %7
%40 = load i32*, i32** %8
%41 = call i32 @BN_mod(i32* %37, i32* %38, i32* %39, i32* %40)
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, 1
br i1 %43, label %44, label %49
44: ; preds = %36
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0), i32 58)
%47 = load i32, i32* @stderr
%48 = call i32 @fflush(i32 %47)
br label %50
49: ; preds = %36
br label %53
50: ; preds = %44, %31, %21
store i32* null, i32** %12
%51 = load i32*, i32** %12
%52 = call i32 @BN_free(i32* %51)
br label %53
53: ; preds = %50, %49
%54 = load i8*, i8** %10
%55 = call i32 @OPENSSL_free(i8* %54)
%56 = load i32*, i32** %12
ret i32* %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"@@@ %s:%d @@@\0A\00"
@.str.1 = [133 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dstebila/daps/refs/heads/master/bn_extra.c\00"
define i32* @SHA256_mod(i8* %0, i32 %1, i32* %2, i32* %3) {
%5 = tail call i32 @BN_num_bytes(i32* %2)
%6 = shl nsw i32 %5, 1
%7 = tail call i8* @SHA256_arbitrary(i8* %0, i32 %1, i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = tail call i32* @BN_bin2bn(i8* %7, i32 %6, i32* null)
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @BN_mod(i32* %10, i32* %10, i32* %2, i32* %3)
%14 = icmp eq i32 %13, 1
br i1 %14, label %22, label %15
15: ; preds = %12, %9, %4
%16 = phi i32 [ 56, %4 ], [ 57, %9 ], [ 58, %12 ]
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%19 = load i32, i32* @stderr
%20 = tail call i32 @fflush(i32 %19)
%21 = tail call i32 @BN_free(i32* null)
br label %22
22: ; preds = %12, %15
%23 = phi i32* [ null, %15 ], [ %10, %12 ]
%24 = tail call i32 @OPENSSL_free(i8* %7)
ret i32* %23
}