#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*/ uint32_t;
struct fuzzy_state {
  int dummy;
};

/* Variables and functions */
scalar_t__ fuzzy_digest(struct fuzzy_state *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fuzzy_free(struct fuzzy_state *);
struct fuzzy_state *fuzzy_new();
scalar_t__ fuzzy_set_total_input_length(struct fuzzy_state *,
                                        int /*<<< orphan*/);
scalar_t__ fuzzy_update(struct fuzzy_state *, unsigned char const *,
                        int /*<<< orphan*/);
int fuzzy_hash_buf(const unsigned char *buf, uint32_t buf_len, char *result) {
  struct fuzzy_state *ctx;
  int ret = -1;
  if (NULL == (ctx = fuzzy_new()))
    return -1;
  if (fuzzy_set_total_input_length(ctx, buf_len) < 0)
    goto out;
  if (fuzzy_update(ctx, buf, buf_len) < 0)
    goto out;
  if (fuzzy_digest(ctx, result, 0) < 0)
    goto out;
  ret = 0;
out:
  fuzzy_free(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<fuzzy_hash_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <fuzzy_new@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    118f <fuzzy_hash_buf+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <fuzzy_hash_buf+0xad>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <fuzzy_set_total_input_length@plt>
cmp    $0x0,%rax
jge    11aa <fuzzy_hash_buf+0x5a>
jmp    11ee <fuzzy_hash_buf+0x9e>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <fuzzy_update@plt>
cmp    $0x0,%rax
jge    11c9 <fuzzy_hash_buf+0x79>
jmp    11ee <fuzzy_hash_buf+0x9e>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1060 <fuzzy_digest@plt>
cmp    $0x0,%rax
jge    11e7 <fuzzy_hash_buf+0x97>
jmp    11ee <fuzzy_hash_buf+0x9e>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fuzzy_free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fuzzy_hash_buf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r12
xor    %eax,%eax
call   1050 <fuzzy_new@plt>
test   %rax,%rax
je     11b4 <fuzzy_hash_buf+0x64>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1070 <fuzzy_set_total_input_length@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
js     11aa <fuzzy_hash_buf+0x5a>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <fuzzy_update@plt>
test   %rax,%rax
js     11aa <fuzzy_hash_buf+0x5a>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <fuzzy_digest@plt>
mov    %rax,%r15
sar    $0x3f,%r15
mov    %rbx,%rdi
call   1030 <fuzzy_free@plt>
jmp    11ba <fuzzy_hash_buf+0x6a>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.fuzzy_state = type { i32 }
define i32 @fuzzy_hash_buf(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.fuzzy_state*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 -1, i32* %9
%10 = call %struct.fuzzy_state* (...) @fuzzy_new()
store %struct.fuzzy_state* %10, %struct.fuzzy_state** %8
%11 = icmp eq %struct.fuzzy_state* null, %10
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %37
13: ; preds = %3
%14 = load %struct.fuzzy_state*, %struct.fuzzy_state** %8
%15 = load i32, i32* %6
%16 = call i64 @fuzzy_set_total_input_length(%struct.fuzzy_state* %14, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
br label %33
19: ; preds = %13
%20 = load %struct.fuzzy_state*, %struct.fuzzy_state** %8
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = call i64 @fuzzy_update(%struct.fuzzy_state* %20, i8* %21, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %33
26: ; preds = %19
%27 = load %struct.fuzzy_state*, %struct.fuzzy_state** %8
%28 = load i8*, i8** %7
%29 = call i64 @fuzzy_digest(%struct.fuzzy_state* %27, i8* %28, i32 0)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %33
32: ; preds = %26
store i32 0, i32* %9
br label %33
33: ; preds = %32, %31, %25, %18
%34 = load %struct.fuzzy_state*, %struct.fuzzy_state** %8
%35 = call i32 @fuzzy_free(%struct.fuzzy_state* %34)
%36 = load i32, i32* %9
store i32 %36, i32* %4
br label %37
37: ; preds = %33, %12
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
%struct.fuzzy_state = type { i32 }
define i32 @fuzzy_hash_buf(i8* %0, i32 %1, i8* %2) {
%4 = tail call %struct.fuzzy_state* (...) @fuzzy_new()
%5 = icmp eq %struct.fuzzy_state* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = tail call i64 @fuzzy_set_total_input_length(%struct.fuzzy_state* %4, i32 %1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = tail call i64 @fuzzy_update(%struct.fuzzy_state* %4, i8* %0, i32 %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i64 @fuzzy_digest(%struct.fuzzy_state* %4, i8* %2, i32 0)
%14 = ashr i64 %13, 63
%15 = trunc i64 %14 to i32
br label %16
16: ; preds = %12, %9, %6
%17 = phi i32 [ -1, %6 ], [ -1, %9 ], [ %15, %12 ]
%18 = tail call i32 @fuzzy_free(%struct.fuzzy_state* %4)
br label %19
19: ; preds = %3, %16
%20 = phi i32 [ %17, %16 ], [ -1, %3 ]
ret i32 %20
}