#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 lobject {
  int dummy;
};
struct lemon {
  int dummy;
};

/* Variables and functions */
struct lobject *larray_get_item(struct lemon *, struct lobject *, int);
int larray_length(struct lemon *, struct lobject *);
scalar_t__ lobject_is_equal(struct lemon *, struct lobject *, struct lobject *);
int lclass_check_slot(struct lemon *lemon, struct lobject *base, int nslots,
                      struct lobject **slots) {
  int i;
  int j;
  int candidate;
  struct lobject *item;
  candidate = 1;
  for (i = 0; i < nslots; i++) {
    for (j = 1; j < larray_length(lemon, slots[i]); j++) {
      item = larray_get_item(lemon, slots[i], j);
      if (lobject_is_equal(lemon, base, item)) {
        candidate = 0;
      }
    }
  }
  return candidate;
}


x86 assembly (clang, -O0):
<lclass_check_slot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f4 <lclass_check_slot+0xc4>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <larray_length@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jge    11e1 <lclass_check_slot+0xb1>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x28(%rbp),%edx
call   1030 <larray_get_item@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <lobject_is_equal@plt>
cmp    $0x0,%rax
je     11ce <lclass_check_slot+0x9e>
movl   $0x0,-0x2c(%rbp)
jmp    11d3 <lclass_check_slot+0xa3>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1168 <lclass_check_slot+0x38>
jmp    11e6 <lclass_check_slot+0xb6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1155 <lclass_check_slot+0x25>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lclass_check_slot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11bc <lclass_check_slot+0x8c>
mov    %rcx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%eax
mov    %rax,(%rsp)
mov    $0x1,%ebp
xor    %r13d,%r13d
jmp    116a <lclass_check_slot+0x3a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    (%rsp),%r13
je     11c1 <lclass_check_slot+0x91>
mov    (%r15,%r13,8),%rsi
mov    %r12,%rdi
call   1050 <larray_length@plt>
cmp    $0x2,%eax
jl     1160 <lclass_check_slot+0x30>
mov    $0x1,%ebx
mov    (%r15,%r13,8),%rsi
mov    %r12,%rdi
mov    %ebx,%edx
call   1030 <larray_get_item@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <lobject_is_equal@plt>
test   %rax,%rax
mov    $0x0,%eax
cmovne %eax,%ebp
add    $0x1,%ebx
mov    (%r15,%r13,8),%rsi
mov    %r12,%rdi
call   1050 <larray_length@plt>
cmp    %eax,%ebx
jl     1180 <lclass_check_slot+0x50>
jmp    1160 <lclass_check_slot+0x30>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.lemon = type { i32 }
%struct.lobject = type { i32 }
define i32 @lclass_check_slot(%struct.lemon* %0, %struct.lobject* %1, i32 %2, %struct.lobject** nocapture %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %31
6: ; preds = %4
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %27
%9 = phi i64 [ 0, %6 ], [ %29, %27 ]
%10 = phi i32 [ 1, %6 ], [ %28, %27 ]
%11 = getelementptr inbounds %struct.lobject*, %struct.lobject** %3, i64 %9
%12 = load %struct.lobject*, %struct.lobject** %11
%13 = tail call i32 @larray_length(%struct.lemon* %0, %struct.lobject* %12)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %27
15: ; preds = %8, %15
%16 = phi i32 [ %22, %15 ], [ %10, %8 ]
%17 = phi i32 [ %23, %15 ], [ 1, %8 ]
%18 = load %struct.lobject*, %struct.lobject** %11
%19 = tail call %struct.lobject* @larray_get_item(%struct.lemon* %0, %struct.lobject* %18, i32 %17)
%20 = tail call i64 @lobject_is_equal(%struct.lemon* %0, %struct.lobject* %1, %struct.lobject* %19)
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 %16, i32 0
%23 = add nuw nsw i32 %17, 1
%24 = load %struct.lobject*, %struct.lobject** %11
%25 = tail call i32 @larray_length(%struct.lemon* %0, %struct.lobject* %24)
%26 = icmp slt i32 %23, %25
br i1 %26, label %15, label %27
27: ; preds = %15, %8
%28 = phi i32 [ %10, %8 ], [ %22, %15 ]
%29 = add nuw nsw i64 %9, 1
%30 = icmp eq i64 %29, %7
br i1 %30, label %31, label %8
31: ; preds = %27, %4
%32 = phi i32 [ 1, %4 ], [ %28, %27 ]
ret i32 %32
}