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

/* Variables and functions */
int mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_export(unsigned char *, size_t *, int, int,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ mpz_import(int /*<<< orphan*/, int, int, int,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned char *);
int /*<<< orphan*/ mpz_init2(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, size_t);
int hashdist(unsigned char *cleft, unsigned char *cright, mpz_t *dist,
             unsigned char *dump) {
  mpz_t left, right;
  mpz_init2(left, 256);
  mpz_init2(right, 256);
  mpz_import(left, 1, 1, 32, 0, 0, cleft);
  mpz_import(right, 1, 1, 32, 0, 0, cright);
  mpz_init2(*dist, 256);
  int ret = mpz_cmp(left, right);
  if (ret < 0) {
    mpz_sub(*dist, right, left);
  } else if (ret == 0) {
    return 0;
  } else {
    mpz_sub(*dist, left, right);
  }
  size_t out;
  mpz_export(dump, &out, 1, 32, 0, 0, *dist);
  printf("out %d\n", out);
}


x86 assembly (clang, -O0):
<hashdist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
mov    $0x100,%esi
call   1070 <mpz_init2@plt>
mov    -0x30(%rbp),%edi
mov    $0x100,%esi
call   1070 <mpz_init2@plt>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    $0x1,%edx
mov    $0x20,%ecx
xor    %r9d,%r9d
mov    %edx,%esi
mov    %r9d,%r8d
mov    %rax,(%rsp)
call   1080 <mpz_import@plt>
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    $0x1,%edx
mov    $0x20,%ecx
xor    %r9d,%r9d
mov    %edx,%esi
mov    %r9d,%r8d
mov    %rax,(%rsp)
call   1080 <mpz_import@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0x100,%esi
call   1070 <mpz_init2@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1060 <mpz_cmp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1214 <hashdist+0xb4>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1030 <mpz_sub@plt>
jmp    1240 <hashdist+0xe0>
cmpl   $0x0,-0x34(%rbp)
jne    122a <hashdist+0xca>
movl   $0x0,-0x4(%rbp)
jmp    1276 <hashdist+0x116>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1030 <mpz_sub@plt>
jmp    1240 <hashdist+0xe0>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
mov    $0x20,%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
mov    %eax,(%rsp)
call   1050 <mpz_export@plt>
mov    -0x40(%rbp),%rsi
lea    0xd8f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashdist>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x100,%esi
call   1070 <mpz_init2@plt>
mov    $0x100,%esi
call   1070 <mpz_init2@plt>
mov    %rbx,(%rsp)
mov    $0x1,%esi
mov    $0x1,%edx
mov    $0x20,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1080 <mpz_import@plt>
mov    %r15,(%rsp)
mov    $0x1,%esi
mov    $0x1,%edx
mov    $0x20,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1080 <mpz_import@plt>
mov    (%r12),%edi
mov    $0x100,%esi
call   1070 <mpz_init2@plt>
call   1060 <mpz_cmp@plt>
test   %eax,%eax
je     121c <hashdist+0xbc>
mov    (%r12),%edi
call   1030 <mpz_sub@plt>
mov    (%r12),%eax
mov    %eax,(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
mov    $0x20,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <mpz_export@plt>
mov    0x10(%rsp),%rsi
lea    0xde9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"out %d\0A\00"
define i32 @hashdist(i8* %0, i8* %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
%14 = load i32, i32* %10
%15 = call i32 @mpz_init2(i32 %14, i32 256)
%16 = load i32, i32* %11
%17 = call i32 @mpz_init2(i32 %16, i32 256)
%18 = load i32, i32* %10
%19 = load i8*, i8** %6
%20 = call i32 @mpz_import(i32 %18, i32 1, i32 1, i32 32, i32 0, i32 0, i8* %19)
%21 = load i32, i32* %11
%22 = load i8*, i8** %7
%23 = call i32 @mpz_import(i32 %21, i32 1, i32 1, i32 32, i32 0, i32 0, i8* %22)
%24 = load i32*, i32** %8
%25 = load i32, i32* %24
%26 = call i32 @mpz_init2(i32 %25, i32 256)
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = call i32 @mpz_cmp(i32 %27, i32 %28)
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %4
%33 = load i32*, i32** %8
%34 = load i32, i32* %33
%35 = load i32, i32* %11
%36 = load i32, i32* %10
%37 = call i32 @mpz_sub(i32 %34, i32 %35, i32 %36)
br label %49
38: ; preds = %4
%39 = load i32, i32* %12
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 0, i32* %5
br label %56
42: ; preds = %38
%43 = load i32*, i32** %8
%44 = load i32, i32* %43
%45 = load i32, i32* %10
%46 = load i32, i32* %11
%47 = call i32 @mpz_sub(i32 %44, i32 %45, i32 %46)
br label %48
48: ; preds = %42
br label %49
49: ; preds = %48, %32
%50 = load i8*, i8** %9
%51 = load i32*, i32** %8
%52 = load i32, i32* %51
%53 = call i32 @mpz_export(i8* %50, i64* %13, i32 1, i32 32, i32 0, i32 0, i32 %52)
%54 = load i64, i64* %13
%55 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %54)
br label %56
56: ; preds = %49, %41
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
@.str = [8 x i8] c"out %d\0A\00"
define i32 @hashdist(i8* %0, i8* %1, i32* nocapture %2, i8* %3) {
%5 = alloca i64
%6 = tail call i32 @mpz_init2(i32 undef, i32 256)
%7 = tail call i32 @mpz_init2(i32 undef, i32 256)
%8 = tail call i32 @mpz_import(i32 undef, i32 1, i32 1, i32 32, i32 0, i32 0, i8* %0)
%9 = tail call i32 @mpz_import(i32 undef, i32 1, i32 1, i32 32, i32 0, i32 0, i8* %1)
%10 = load i32, i32* %2
%11 = tail call i32 @mpz_init2(i32 %10, i32 256)
%12 = tail call i32 @mpz_cmp(i32 undef, i32 undef)
%13 = icmp eq i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %4
%15 = load i32, i32* %2
%16 = tail call i32 @mpz_sub(i32 %15, i32 undef, i32 undef)
%17 = bitcast i64* %5 to i8*
%18 = load i32, i32* %2
%19 = call i32 @mpz_export(i8* %3, i64* %5, i32 1, i32 32, i32 0, i32 0, i32 %18)
%20 = load i64, i64* %5
%21 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %20)
br label %22
22: ; preds = %4, %14
ret i32 0
}