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

/* Variables and functions */
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
scalar_t__ OPENSSL_malloc(int);
int SHA256_DIGEST_LENGTH;
int SHA256_Final(unsigned char *, int /*<<< orphan*/ *);
int SHA256_Init(int /*<<< orphan*/ *);
int SHA256_Update(int /*<<< orphan*/ *, unsigned char const *, int const);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ stderr;
unsigned char *SHA256_arbitrary(const unsigned char *d, const int d_length,
                                const int o_length) {
  int ok;
  unsigned char dgst[SHA256_DIGEST_LENGTH];
  unsigned char *output = NULL;
  if ((output = (unsigned char *)OPENSSL_malloc(sizeof(unsigned char) *
                                                o_length)) == 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",
        35);
    fflush(stderr);
    ;
    goto err;
  };
  for (int i = 0; i < o_length; i += SHA256_DIGEST_LENGTH) {
    SHA256_CTX ctx;
    ok = (SHA256_Init(&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",
              38);
      fflush(stderr);
      ;
      goto err;
    };
    ok = (SHA256_Update(&ctx, (unsigned char *)&i,
                        sizeof(int) / sizeof(unsigned char)));
    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",
              39);
      fflush(stderr);
      ;
      goto err;
    };
    ok = (SHA256_Update(&ctx, d, d_length));
    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",
              40);
      fflush(stderr);
      ;
      goto err;
    };
    ok = (SHA256_Final(dgst, &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",
              41);
      fflush(stderr);
      ;
      goto err;
    };
    memcpy(&output[i], dgst,
           (((SHA256_DIGEST_LENGTH) < (o_length - i)) ? (SHA256_DIGEST_LENGTH)
                                                      : (o_length - i)));
  }
  return output;
err:
  OPENSSL_free(output);
  return NULL;
}


x86 assembly (clang, -O0):
<SHA256_arbitrary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <OPENSSL_malloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1217 <SHA256_arbitrary+0x97>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
lea    0xe15(%rip),%rdx
mov    $0x23,%ecx
call   1040 <fprintf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    13de <SHA256_arbitrary+0x25e>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13ca <SHA256_arbitrary+0x24a>
lea    -0x40(%rbp),%rdi
call   1030 <SHA256_Init@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     1274 <SHA256_arbitrary+0xf4>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
lea    0xdb8(%rip),%rdx
mov    $0x26,%ecx
call   1040 <fprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    13de <SHA256_arbitrary+0x25e>
lea    -0x3c(%rbp),%rsi
lea    -0x40(%rbp),%rdi
mov    $0x4,%edx
call   1090 <SHA256_Update@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     12c7 <SHA256_arbitrary+0x147>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
lea    0xd65(%rip),%rdx
mov    $0x27,%ecx
call   1040 <fprintf@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    13de <SHA256_arbitrary+0x25e>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x40(%rbp),%rdi
call   1090 <SHA256_Update@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     1318 <SHA256_arbitrary+0x198>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
lea    0xd0c(%rip),%rsi
lea    0xd14(%rip),%rdx
mov    $0x28,%ecx
call   1040 <fprintf@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    13de <SHA256_arbitrary+0x25e>
mov    -0x50(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <SHA256_Final@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     1366 <SHA256_arbitrary+0x1e6>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xcbe(%rip),%rsi
lea    0xcc6(%rip),%rdx
mov    $0x29,%ecx
call   1040 <fprintf@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    13de <SHA256_arbitrary+0x25e>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    0x2c5c(%rip),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%ecx
sub    -0x3c(%rbp),%ecx
cmp    %ecx,%eax
jge    139d <SHA256_arbitrary+0x21d>
mov    0x2c45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    13a6 <SHA256_arbitrary+0x226>
mov    -0x18(%rbp),%eax
sub    -0x3c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    -0x5c(%rbp),%edx
call   1050 <memcpy@plt>
mov    0x2c1b(%rip),%rax
mov    (%rax),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    121e <SHA256_arbitrary+0x9e>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    13f6 <SHA256_arbitrary+0x276>
mov    -0x38(%rbp),%rdi
call   10a0 <OPENSSL_free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SHA256_arbitrary>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
mov    %esi,-0x30(%rbp)
mov    %rdi,-0x38(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %edx,%edi
call   1070 <OPENSSL_malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1260 <SHA256_arbitrary+0xe0>
movl   $0x0,-0x2c(%rbp)
test   %r13d,%r13d
jle    12c6 <SHA256_arbitrary+0x146>
lea    -0x3c(%rbp),%r15
nopl   0x0(%rax)
mov    %r15,%rdi
call   1030 <SHA256_Init@plt>
cmp    $0x1,%eax
jne    127e <SHA256_arbitrary+0xfe>
mov    %r15,%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   1090 <SHA256_Update@plt>
cmp    $0x1,%eax
jne    1285 <SHA256_arbitrary+0x105>
mov    %r15,%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1090 <SHA256_Update@plt>
cmp    $0x1,%eax
jne    128c <SHA256_arbitrary+0x10c>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <SHA256_Final@plt>
cmp    $0x1,%eax
jne    1293 <SHA256_arbitrary+0x113>
movslq -0x2c(%rbp),%rdi
mov    %r13d,%edx
sub    %edi,%edx
add    %r14,%rdi
mov    0x2d9a(%rip),%r12
mov    (%r12),%eax
cmp    %edx,%eax
cmovl  %eax,%edx
mov    %rbx,%rsi
call   1050 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    (%r12),%eax
mov    %eax,-0x2c(%rbp)
cmp    %r13d,%eax
jl     11e0 <SHA256_arbitrary+0x60>
jmp    12c6 <SHA256_arbitrary+0x146>
mov    0x2d79(%rip),%rbx
mov    (%rbx),%edi
lea    0xd90(%rip),%rsi
lea    0xd98(%rip),%rdx
mov    $0x23,%ecx
jmp    12af <SHA256_arbitrary+0x12f>
mov    $0x26,%ecx
jmp    1298 <SHA256_arbitrary+0x118>
mov    $0x27,%ecx
jmp    1298 <SHA256_arbitrary+0x118>
mov    $0x28,%ecx
jmp    1298 <SHA256_arbitrary+0x118>
mov    $0x29,%ecx
mov    0x2d41(%rip),%rbx
mov    (%rbx),%edi
lea    0xd58(%rip),%rsi
lea    0xd60(%rip),%rdx
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1060 <fflush@plt>
mov    %r14,%rdi
call   10a0 <OPENSSL_free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
@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 i8* @SHA256_arbitrary(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%15 = load i32, i32* @SHA256_DIGEST_LENGTH
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i8, i64 %16
store i64 %16, i64* %10
store i8* null, i8** %11
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i64 @OPENSSL_malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %11
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %31
26: ; preds = %3
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, 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 35)
%29 = load i32, i32* @stderr
%30 = call i32 @fflush(i32 %29)
br label %100
31: ; preds = %3
store i32 0, i32* %12
br label %32
32: ; preds = %94, %31
%33 = load i32, i32* %12
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %98
36: ; preds = %32
%37 = call i32 @SHA256_Init(i32* %13)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 1
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, 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 38)
%43 = load i32, i32* @stderr
%44 = call i32 @fflush(i32 %43)
br label %100
45: ; preds = %36
%46 = bitcast i32* %12 to i8*
%47 = call i32 @SHA256_Update(i32* %13, i8* %46, i32 4)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 1
br i1 %49, label %50, label %55
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, 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 39)
%53 = load i32, i32* @stderr
%54 = call i32 @fflush(i32 %53)
br label %100
55: ; preds = %45
%56 = load i8*, i8** %5
%57 = load i32, i32* %6
%58 = call i32 @SHA256_Update(i32* %13, i8* %56, i32 %57)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp ne i32 %59, 1
br i1 %60, label %61, label %66
61: ; preds = %55
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, 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 40)
%64 = load i32, i32* @stderr
%65 = call i32 @fflush(i32 %64)
br label %100
66: ; preds = %55
%67 = call i32 @SHA256_Final(i8* %18, i32* %13)
store i32 %67, i32* %8
%68 = load i32, i32* %8
%69 = icmp ne i32 %68, 1
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = call i32 @fprintf(i32 %71, 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 41)
%73 = load i32, i32* @stderr
%74 = call i32 @fflush(i32 %73)
br label %100
75: ; preds = %66
%76 = load i8*, i8** %11
%77 = load i32, i32* %12
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i32, i32* @SHA256_DIGEST_LENGTH
%81 = load i32, i32* %7
%82 = load i32, i32* %12
%83 = sub nsw i32 %81, %82
%84 = icmp slt i32 %80, %83
br i1 %84, label %85, label %87
85: ; preds = %75
%86 = load i32, i32* @SHA256_DIGEST_LENGTH
br label %91
87: ; preds = %75
%88 = load i32, i32* %7
%89 = load i32, i32* %12
%90 = sub nsw i32 %88, %89
br label %91
91: ; preds = %87, %85
%92 = phi i32 [ %86, %85 ], [ %90, %87 ]
%93 = call i32 @memcpy(i8* %79, i8* %18, i32 %92)
br label %94
94: ; preds = %91
%95 = load i32, i32* @SHA256_DIGEST_LENGTH
%96 = load i32, i32* %12
%97 = add nsw i32 %96, %95
store i32 %97, i32* %12
br label %32
98: ; preds = %32
%99 = load i8*, i8** %11
store i8* %99, i8** %4
store i32 1, i32* %14
br label %103
100: ; preds = %70, %61, %50, %40, %26
%101 = load i8*, i8** %11
%102 = call i32 @OPENSSL_free(i8* %101)
store i8* null, i8** %4
store i32 1, i32* %14
br label %103
103: ; preds = %100, %98
%104 = load i8*, i8** %9
%105 = load i8*, i8** %4
ret i8* %105
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
@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 i8* @SHA256_arbitrary(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = load i32, i32* @SHA256_DIGEST_LENGTH
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = tail call i64 @OPENSSL_malloc(i32 %2)
%10 = inttoptr i64 %9 to i8*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, 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 35)
%15 = load i32, i32* @stderr
%16 = tail call i32 @fflush(i32 %15)
br label %54
17: ; preds = %3
%18 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%19 = icmp sgt i32 %2, 0
br i1 %19, label %20, label %53
20: ; preds = %17
%21 = bitcast i32* %5 to i8*
br label %22
22: ; preds = %20, %40
%23 = call i32 @SHA256_Init(i32* %5)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = call i32 @SHA256_Update(i32* %5, i8* %18, i32 4)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = call i32 @SHA256_Update(i32* %5, i8* %0, i32 %1)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = call i32 @SHA256_Final(i8* %8, i32* %5)
%33 = icmp eq i32 %32, 1
br i1 %33, label %40, label %34
34: ; preds = %31, %28, %25, %22
%35 = phi i32 [ 38, %22 ], [ 39, %25 ], [ 40, %28 ], [ 41, %31 ]
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, 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 %35)
%38 = load i32, i32* @stderr
%39 = call i32 @fflush(i32 %38)
br label %54
40: ; preds = %31
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %10, i64 %42
%44 = load i32, i32* @SHA256_DIGEST_LENGTH
%45 = sub nsw i32 %2, %41
%46 = icmp slt i32 %44, %45
%47 = select i1 %46, i32 %44, i32 %45
%48 = call i32 @memcpy(i8* %43, i8* %8, i32 %47)
%49 = load i32, i32* @SHA256_DIGEST_LENGTH
%50 = load i32, i32* %4
%51 = add nsw i32 %50, %49
store i32 %51, i32* %4
%52 = icmp slt i32 %51, %2
br i1 %52, label %22, label %53
53: ; preds = %40, %17
br label %56
54: ; preds = %34, %12
%55 = call i32 @OPENSSL_free(i8* %10)
br label %56
56: ; preds = %53, %54
%57 = phi i8* [ null, %54 ], [ %10, %53 ]
ret i8* %57
}