#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_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_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    117f <fuzzy_hash_buf+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <fuzzy_hash_buf+0x92>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <fuzzy_update@plt>
cmp    $0x0,%rax
jge    119e <fuzzy_hash_buf+0x5e>
jmp    11c3 <fuzzy_hash_buf+0x83>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1060 <fuzzy_digest@plt>
cmp    $0x0,%rax
jge    11bc <fuzzy_hash_buf+0x7c>
jmp    11c3 <fuzzy_hash_buf+0x83>
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   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
xor    %eax,%eax
call   1050 <fuzzy_new@plt>
test   %rax,%rax
je     1188 <fuzzy_hash_buf+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1040 <fuzzy_update@plt>
test   %rax,%rax
js     1190 <fuzzy_hash_buf+0x50>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <fuzzy_digest@plt>
mov    %rax,%r14
sar    $0x3f,%r14
jmp    1196 <fuzzy_hash_buf+0x56>
mov    $0xffffffff,%r14d
jmp    119e <fuzzy_hash_buf+0x5e>
mov    $0xffffffff,%r14d
mov    %rbx,%rdi
call   1030 <fuzzy_free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
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 %31
13: ; preds = %3
%14 = load %struct.fuzzy_state*, %struct.fuzzy_state** %8
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call i64 @fuzzy_update(%struct.fuzzy_state* %14, i8* %15, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
br label %27
20: ; preds = %13
%21 = load %struct.fuzzy_state*, %struct.fuzzy_state** %8
%22 = load i8*, i8** %7
%23 = call i64 @fuzzy_digest(%struct.fuzzy_state* %21, i8* %22, i32 0)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %27
26: ; preds = %20
store i32 0, i32* %9
br label %27
27: ; preds = %26, %25, %19
%28 = load %struct.fuzzy_state*, %struct.fuzzy_state** %8
%29 = call i32 @fuzzy_free(%struct.fuzzy_state* %28)
%30 = load i32, i32* %9
store i32 %30, i32* %4
br label %31
31: ; preds = %27, %12
%32 = load i32, i32* %4
ret i32 %32
}

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 %16, label %6
6: ; preds = %3
%7 = tail call i64 @fuzzy_update(%struct.fuzzy_state* %4, i8* %0, i32 %1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i64 @fuzzy_digest(%struct.fuzzy_state* %4, i8* %2, i32 0)
%11 = ashr i64 %10, 63
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %9, %6
%14 = phi i32 [ -1, %6 ], [ %12, %9 ]
%15 = tail call i32 @fuzzy_free(%struct.fuzzy_state* %4)
br label %16
16: ; preds = %3, %13
%17 = phi i32 [ %14, %13 ], [ -1, %3 ]
ret i32 %17
}