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

/* Variables and functions */
int /*<<< orphan*/ FREE(unsigned char *);
scalar_t__ MALLOC(int);
int dist1(int /*<<< orphan*/, int /*<<< orphan*/, int, int, int, int,
          struct signature *, struct signature *, int, int, float,
          unsigned char *);
int /*<<< orphan*/ fatal(char *);
int dist(struct signature *feats1, struct signature *feats2, int start1,
         int end1, int start2, int end2, int N1, int N2, float thr) {
  int n1 = end1 - start1;
  int n2 = end2 - start2;
  unsigned char *distances =
      (unsigned char *)MALLOC(sizeof(unsigned char) * n1 * n2);
  if (!distances)
    fatal("malloc failed");
  for (int i = 0; i < n1 * n2; i++) {
    distances[i] = 255;
  }
  int result = dist1(0, 0, start1, start2, n1, n2, feats1, feats2, N1, N2, thr,
                     distances);
  FREE(distances);
  return result;
}


x86 assembly (clang, -O0):
<dist>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
mov    %ecx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
movss  %xmm0,-0x34(%rbp)
mov    -0x28(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movslq -0x38(%rbp),%rax
shl    $0x0,%rax
movslq -0x3c(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1050 <MALLOC@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11b0 <dist+0x70>
lea    0xe55(%rip),%rdi
call   1060 <fatal@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    -0x38(%rbp),%ecx
imul   -0x3c(%rbp),%ecx
cmp    %ecx,%eax
jge    11e3 <dist+0xa3>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11b7 <dist+0x77>
mov    -0x24(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
mov    -0x18(%rbp),%r14
mov    -0x20(%rbp),%rbx
mov    0x10(%rbp),%r11d
mov    0x18(%rbp),%r10d
movss  -0x34(%rbp),%xmm0
mov    -0x48(%rbp),%rax
xor    %esi,%esi
mov    %esi,%edi
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1030 <dist1@plt>
mov    %eax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <FREE@plt>
mov    -0x50(%rbp),%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movss  %xmm0,0x4(%rsp)
mov    %r9d,%r15d
mov    %r8d,%r13d
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,0x8(%rsp)
mov    %rdi,0x10(%rsp)
sub    %edx,%ebx
sub    %r8d,%r15d
mov    %r15d,%ebp
imul   %ebx,%ebp
mov    %ebp,%edi
call   1060 <MALLOC@plt>
mov    %rax,%r12
test   %rax,%rax
jne    119f <dist+0x4f>
lea    0xe66(%rip),%rdi
call   1070 <fatal@plt>
mov    0x58(%rsp),%eax
mov    0x50(%rsp),%r10d
test   %ebp,%ebp
jle    11c6 <dist+0x76>
mov    %ebp,%edx
mov    %r12,%rdi
mov    $0xff,%esi
mov    %rax,%rbp
call   1040 <memset@plt>
mov    %rbp,%rax
mov    0x50(%rsp),%r10d
sub    $0x8,%rsp
xor    %edi,%edi
xor    %esi,%esi
mov    %r14d,%edx
mov    %r13d,%ecx
mov    %ebx,%r8d
mov    %r15d,%r9d
movss  0xc(%rsp),%xmm0
push   %r12
push   %rax
push   %r10
push   0x28(%rsp)
push   0x38(%rsp)
call   1030 <dist1@plt>
add    $0x30,%rsp
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <FREE@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.signature = type { i32 }
@.str = [14 x i8] c"malloc failed\00"
define i32 @dist(%struct.signature* %0, %struct.signature* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, float %8) {
%10 = alloca %struct.signature*
%11 = alloca %struct.signature*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca float
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i32
store %struct.signature* %0, %struct.signature** %10
store %struct.signature* %1, %struct.signature** %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store float %8, float* %18
%24 = load i32, i32* %13
%25 = load i32, i32* %12
%26 = sub nsw i32 %24, %25
store i32 %26, i32* %19
%27 = load i32, i32* %15
%28 = load i32, i32* %14
%29 = sub nsw i32 %27, %28
store i32 %29, i32* %20
%30 = load i32, i32* %19
%31 = sext i32 %30 to i64
%32 = mul i64 1, %31
%33 = load i32, i32* %20
%34 = sext i32 %33 to i64
%35 = mul i64 %32, %34
%36 = trunc i64 %35 to i32
%37 = call i64 @MALLOC(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %21
%39 = load i8*, i8** %21
%40 = icmp ne i8* %39, null
br i1 %40, label %43, label %41
41: ; preds = %9
%42 = call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %41, %9
store i32 0, i32* %22
br label %44
44: ; preds = %55, %43
%45 = load i32, i32* %22
%46 = load i32, i32* %19
%47 = load i32, i32* %20
%48 = mul nsw i32 %46, %47
%49 = icmp slt i32 %45, %48
br i1 %49, label %50, label %58
50: ; preds = %44
%51 = load i8*, i8** %21
%52 = load i32, i32* %22
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 -1, i8* %54
br label %55
55: ; preds = %50
%56 = load i32, i32* %22
%57 = add nsw i32 %56, 1
store i32 %57, i32* %22
br label %44
58: ; preds = %44
%59 = load i32, i32* %12
%60 = load i32, i32* %14
%61 = load i32, i32* %19
%62 = load i32, i32* %20
%63 = load %struct.signature*, %struct.signature** %10
%64 = load %struct.signature*, %struct.signature** %11
%65 = load i32, i32* %16
%66 = load i32, i32* %17
%67 = load float, float* %18
%68 = load i8*, i8** %21
%69 = call i32 @dist1(i32 0, i32 0, i32 %59, i32 %60, i32 %61, i32 %62, %struct.signature* %63, %struct.signature* %64, i32 %65, i32 %66, float %67, i8* %68)
store i32 %69, i32* %23
%70 = load i8*, i8** %21
%71 = call i32 @FREE(i8* %70)
%72 = load i32, i32* %23
ret i32 %72
}

LLVM IR (-O2):
%struct.signature = type { i32 }
@.str = [14 x i8] c"malloc failed\00"
define i32 @dist(%struct.signature* %0, %struct.signature* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, float %8) {
%10 = sub nsw i32 %3, %2
%11 = sub nsw i32 %5, %4
%12 = mul i32 %11, %10
%13 = tail call i64 @MALLOC(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %9
%19 = icmp sgt i32 %12, 0
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = zext i32 %12 to i64
br label %22
22: ; preds = %20, %18
%23 = tail call i32 @dist1(i32 0, i32 0, i32 %2, i32 %4, i32 %10, i32 %11, %struct.signature* %0, %struct.signature* %1, i32 %6, i32 %7, float %8, i8* %14)
%24 = tail call i32 @FREE(i8* %14)
ret i32 %23
}