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

/* Variables and functions */
unsigned int UINT32_MAX;
int earworm_core(void *, size_t, void const *, size_t, void const *, size_t,
                 unsigned int, int /*<<< orphan*/, unsigned int,
                 int /*<<< orphan*/ const *);
int /*<<< orphan*/ *get_test_arena(unsigned int);
int PHS(void *out, size_t outlen, const void *in, size_t inlen,
        const void *salt, size_t saltlen, unsigned int t_cost,
        unsigned int m_cost) {
  if (saltlen > ((size_t)32) || t_cost < 1 || t_cost > UINT32_MAX)
    return -1;
  const uint8_t *arena = get_test_arena(m_cost);
  if (arena == NULL)
    return -1;
  return earworm_core(out, outlen, in, inlen, salt, saltlen, m_cost, 0, t_cost,
                      arena);
}


x86 assembly (clang, -O0):
<PHS>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9,-0x40(%rbp)
cmpq   $0x20,-0x40(%rbp)
ja     116e <PHS+0x4e>
cmpl   $0x1,0x10(%rbp)
jb     116e <PHS+0x4e>
mov    0x10(%rbp),%eax
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%eax
jbe    117a <PHS+0x5a>
movl   $0xffffffff,-0xc(%rbp)
jmp    11e1 <PHS+0xc1>
mov    0x18(%rbp),%edi
call   1030 <get_test_arena@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    119d <PHS+0x7d>
movl   $0xffffffff,-0xc(%rbp)
jmp    11e1 <PHS+0xc1>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    0x18(%rbp),%r11d
mov    0x10(%rbp),%r10d
mov    -0x48(%rbp),%rax
xor    %ebx,%ebx
mov    %r11d,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1040 <earworm_core@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<PHS>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x20,%r9
ja     118e <PHS+0x6e>
mov    0x40(%rsp),%ebp
test   %ebp,%ebp
je     118e <PHS+0x6e>
mov    0x2eb8(%rip),%rax
cmp    %ebp,(%rax)
jb     118e <PHS+0x6e>
mov    %r9,%rbx
mov    0x48(%rsp),%eax
mov    %rdi,(%rsp)
mov    %eax,%edi
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r14
call   1030 <get_test_arena@plt>
mov    (%rsp),%rdi
test   %rax,%rax
je     118e <PHS+0x6e>
mov    %r14,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    %rbx,%r9
push   %rax
push   %rbp
push   $0x0
mov    0x60(%rsp),%eax
push   %rax
call   1040 <earworm_core@plt>
add    $0x28,%rsp
jmp    1197 <PHS+0x77>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@UINT32_MAX = global i32 0
define i32 @PHS(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32*
store i8* %0, i8** %10
store i64 %1, i64* %11
store i8* %2, i8** %12
store i64 %3, i64* %13
store i8* %4, i8** %14
store i64 %5, i64* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
%19 = load i64, i64* %15
%20 = icmp ugt i64 %19, 32
br i1 %20, label %28, label %21
21: ; preds = %8
%22 = load i32, i32* %16
%23 = icmp ult i32 %22, 1
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = load i32, i32* %16
%26 = load i32, i32* @UINT32_MAX
%27 = icmp ugt i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24, %21, %8
store i32 -1, i32* %9
br label %46
29: ; preds = %24
%30 = load i32, i32* %17
%31 = call i32* @get_test_arena(i32 %30)
store i32* %31, i32** %18
%32 = load i32*, i32** %18
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 -1, i32* %9
br label %46
35: ; preds = %29
%36 = load i8*, i8** %10
%37 = load i64, i64* %11
%38 = load i8*, i8** %12
%39 = load i64, i64* %13
%40 = load i8*, i8** %14
%41 = load i64, i64* %15
%42 = load i32, i32* %17
%43 = load i32, i32* %16
%44 = load i32*, i32** %18
%45 = call i32 @earworm_core(i8* %36, i64 %37, i8* %38, i64 %39, i8* %40, i64 %41, i32 %42, i32 0, i32 %43, i32* %44)
store i32 %45, i32* %9
br label %46
46: ; preds = %35, %34, %28
%47 = load i32, i32* %9
ret i32 %47
}

LLVM IR (-O2):
@UINT32_MAX = global i32 0
define i32 @PHS(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5, i32 %6, i32 %7) {
%9 = icmp ugt i64 %5, 32
%10 = icmp eq i32 %6, 0
%11 = or i1 %9, %10
%12 = load i32, i32* @UINT32_MAX
%13 = icmp ult i32 %12, %6
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %20, label %15
15: ; preds = %8
%16 = tail call i32* @get_test_arena(i32 %7)
%17 = icmp eq i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @earworm_core(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5, i32 %7, i32 0, i32 %6, i32* %16)
br label %20
20: ; preds = %18, %15, %8
%21 = phi i32 [ -1, %8 ], [ %19, %18 ], [ -1, %15 ]
ret i32 %21
}