#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 range_t {
  int dummy;
};

/* Variables and functions */
scalar_t__ equiv(int *, int /*<<< orphan*/ *, int *, struct range_t *);
int /*<<< orphan*/ free(struct range_t *);
int length_l(void **);
struct range_t *range(int *, int /*<<< orphan*/);
int find(int **formulae, int n_formulae, int *formula) {
  if (n_formulae <= 0)
    n_formulae = length_l((void **)formulae);
  if (n_formulae <= 0)
    return -1;
  struct range_t *t = range(formula, 0);
  int i;
  for (i = 0; i < n_formulae; i++) {
    if (equiv(formulae[i], NULL, formula, t)) {
      free(t);
      return i;
    }
  }
  free(t);
  return -1;
}


x86 assembly (clang, -O0):
<find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1169 <find+0x29>
mov    -0x10(%rbp),%rdi
call   1060 <length_l@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     117f <find+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <find+0xbf>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <range@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ef <find+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <equiv@plt>
cmp    $0x0,%rax
je     11dc <find+0x9c>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ff <find+0xbf>
jmp    11e1 <find+0xa1>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1195 <find+0x55>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r14
test   %esi,%esi
jg     1162 <find+0x22>
mov    %r14,%rdi
call   1060 <length_l@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11b7 <find+0x77>
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <range@plt>
mov    %rax,%r12
mov    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,8),%rdi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1030 <equiv@plt>
test   %rax,%rax
jne    11a4 <find+0x64>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <find+0x40>
mov    $0xffffffff,%ebx
mov    %r12,%rdi
call   1040 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebx
jmp    11ac <find+0x6c>

LLVM IR (-O0):
%struct.range_t = type { i32 }
define i32 @find(i32** %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.range_t*
%9 = alloca i32
store i32** %0, i32*** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i32, i32* %6
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32**, i32*** %5
%14 = bitcast i32** %13 to i8**
%15 = call i32 @length_l(i8** %14)
store i32 %15, i32* %6
br label %16
16: ; preds = %12, %3
%17 = load i32, i32* %6
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %4
br label %48
20: ; preds = %16
%21 = load i32*, i32** %7
%22 = call %struct.range_t* @range(i32* %21, i32 0)
store %struct.range_t* %22, %struct.range_t** %8
store i32 0, i32* %9
br label %23
23: ; preds = %42, %20
%24 = load i32, i32* %9
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %45
27: ; preds = %23
%28 = load i32**, i32*** %5
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32*, i32** %28, i64 %30
%32 = load i32*, i32** %31
%33 = load i32*, i32** %7
%34 = load %struct.range_t*, %struct.range_t** %8
%35 = call i64 @equiv(i32* %32, i32* null, i32* %33, %struct.range_t* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %27
%38 = load %struct.range_t*, %struct.range_t** %8
%39 = call i32 @free(%struct.range_t* %38)
%40 = load i32, i32* %9
store i32 %40, i32* %4
br label %48
41: ; preds = %27
br label %42
42: ; preds = %41
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %23
45: ; preds = %23
%46 = load %struct.range_t*, %struct.range_t** %8
%47 = call i32 @free(%struct.range_t* %46)
store i32 -1, i32* %4
br label %48
48: ; preds = %45, %37, %19
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
%struct.range_t = type { i32 }
define i32 @find(i32** %0, i32 %1, i32* %2) {
%4 = icmp slt i32 %1, 1
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = bitcast i32** %0 to i8**
%7 = tail call i32 @length_l(i8** %6)
%8 = icmp slt i32 %7, 1
br i1 %8, label %27, label %9
9: ; preds = %5, %3
%10 = phi i32 [ %7, %5 ], [ %1, %3 ]
%11 = tail call %struct.range_t* @range(i32* %2, i32 0)
%12 = zext i32 %10 to i64
br label %13
13: ; preds = %9, %21
%14 = phi i64 [ 0, %9 ], [ %22, %21 ]
%15 = getelementptr inbounds i32*, i32** %0, i64 %14
%16 = load i32*, i32** %15
%17 = tail call i64 @equiv(i32* %16, i32* null, i32* %2, %struct.range_t* %11)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = trunc i64 %14 to i32
br label %24
21: ; preds = %13
%22 = add nuw nsw i64 %14, 1
%23 = icmp eq i64 %22, %12
br i1 %23, label %24, label %13
24: ; preds = %21, %19
%25 = phi i32 [ %20, %19 ], [ -1, %21 ]
%26 = tail call i32 @free(%struct.range_t* %11)
br label %27
27: ; preds = %24, %5
%28 = phi i32 [ -1, %5 ], [ %25, %24 ]
ret i32 %28
}