#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(unsigned char *, int /*<<< orphan*/, unsigned char *);
int /*<<< orphan*/ SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ memcmp(unsigned char *, unsigned char *, int /*<<< orphan*/);
size_t hash_until(unsigned char *private, unsigned char *public, size_t iter) {
  size_t i = 0;
  while (i++ < iter) {
    SHA256(private, SHA256_DIGEST_LENGTH, private);
    if (public && !memcmp(private, public, SHA256_DIGEST_LENGTH))
      return i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<hash_until>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
cmp    -0x20(%rbp),%rax
jae    11a7 <hash_until+0x87>
mov    -0x10(%rbp),%rdi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <SHA256@plt>
cmpq   $0x0,-0x18(%rbp)
je     11a2 <hash_until+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11a2 <hash_until+0x82>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <hash_until+0x8f>
jmp    113c <hash_until+0x1c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_until>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdx,%rdx
je     118b <hash_until+0x6b>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
neg    %r14
mov    $0x1,%ebx
mov    0x2e9a(%rip),%r13
jmp    1162 <hash_until+0x42>
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     118b <hash_until+0x6b>
mov    0x0(%r13),%esi
mov    %r12,%rdi
mov    %r12,%rdx
call   1030 <SHA256@plt>
test   %r15,%r15
je     1150 <hash_until+0x30>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <memcmp@plt>
test   %eax,%eax
jne    1150 <hash_until+0x30>
jmp    118d <hash_until+0x6d>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
define i64 @hash_until(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 0, i64* %8
br label %9
9: ; preds = %29, %3
%10 = load i64, i64* %8
%11 = add i64 %10, 1
store i64 %11, i64* %8
%12 = load i64, i64* %7
%13 = icmp ult i64 %10, %12
br i1 %13, label %14, label %30
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = load i32, i32* @SHA256_DIGEST_LENGTH
%17 = load i8*, i8** %5
%18 = call i32 @SHA256(i8* %15, i32 %16, i8* %17)
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = load i32, i32* @SHA256_DIGEST_LENGTH
%25 = call i32 @memcmp(i8* %22, i8* %23, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %21
%28 = load i64, i64* %8
store i64 %28, i64* %4
br label %31
29: ; preds = %21, %14
br label %9
30: ; preds = %9
store i64 0, i64* %4
br label %31
31: ; preds = %30, %27
%32 = load i64, i64* %4
ret i64 %32
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
define i64 @hash_until(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = icmp eq i8* %1, null
br label %7
7: ; preds = %5, %15
%8 = phi i64 [ 1, %5 ], [ %16, %15 ]
%9 = load i32, i32* @SHA256_DIGEST_LENGTH
%10 = tail call i32 @SHA256(i8* %0, i32 %9, i8* %0)
br i1 %6, label %15, label %11
11: ; preds = %7
%12 = load i32, i32* @SHA256_DIGEST_LENGTH
%13 = tail call i32 @memcmp(i8* %0, i8* %1, i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11, %7
%16 = add i64 %8, 1
%17 = icmp eq i64 %8, %2
br i1 %17, label %18, label %7
18: ; preds = %11, %15, %3
%19 = phi i64 [ 0, %3 ], [ 0, %15 ], [ %8, %11 ]
ret i64 %19
}