#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 wbuf {
  int dummy;
};
struct hull {
  int dummy;
};

/* Variables and functions */
scalar_t__ intersect_with(struct wbuf *, struct hull *, struct hull **, size_t);
struct hull *next(struct hull *);
int find_intersections(struct wbuf *buf, struct hull **outlines, size_t n) {
  size_t i;
  struct hull *t;
  for (i = 0; i < n; i++) {
    t = outlines[i];
    if (!t) {
      continue;
    }
    do {
      if (intersect_with(buf, t, outlines, i + 1)) {
        return -1;
      }
      t = next(t);
    } while (t != outlines[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_intersections>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11d7 <find_intersections+0xb7>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    116a <find_intersections+0x4a>
jmp    11c6 <find_intersections+0xa6>
jmp    116f <find_intersections+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
call   1030 <intersect_with@plt>
cmp    $0x0,%rax
je     119e <find_intersections+0x7e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <find_intersections+0xbe>
mov    -0x30(%rbp),%rdi
call   1040 <next@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jne    116f <find_intersections+0x4f>
jmp    11c6 <find_intersections+0xa6>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    113c <find_intersections+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_intersections>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     1191 <find_intersections+0x71>
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    1148 <find_intersections+0x28>
nopl   (%rax)
mov    %r12,%rbp
cmp    %r14,%r12
je     1191 <find_intersections+0x71>
mov    0x0(%r13,%rbp,8),%rbx
lea    0x1(%rbp),%r12
test   %rbx,%rbx
je     1140 <find_intersections+0x20>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
call   1030 <intersect_with@plt>
test   %rax,%rax
jne    118a <find_intersections+0x6a>
mov    %rbx,%rdi
call   1040 <next@plt>
mov    %rax,%rbx
cmp    0x0(%r13,%rbp,8),%rax
jne    1160 <find_intersections+0x40>
jmp    1140 <find_intersections+0x20>
mov    $0xffffffff,%eax
jmp    1193 <find_intersections+0x73>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.wbuf = type { i32 }
%struct.hull = type { i32 }
define i32 @find_intersections(%struct.wbuf* %0, %struct.hull** %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %21, label %5
5: ; preds = %3, %19
%6 = phi i64 [ %10, %19 ], [ 0, %3 ]
%7 = getelementptr inbounds %struct.hull*, %struct.hull** %1, i64 %6
%8 = load %struct.hull*, %struct.hull** %7
%9 = icmp eq %struct.hull* %8, null
%10 = add nuw i64 %6, 1
br i1 %9, label %19, label %11
11: ; preds = %5, %15
%12 = phi %struct.hull* [ %16, %15 ], [ %8, %5 ]
%13 = tail call i64 @intersect_with(%struct.wbuf* %0, %struct.hull* %12, %struct.hull** %1, i64 %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = tail call %struct.hull* @next(%struct.hull* %12)
%17 = load %struct.hull*, %struct.hull** %7
%18 = icmp eq %struct.hull* %16, %17
br i1 %18, label %19, label %11
19: ; preds = %15, %5
%20 = icmp eq i64 %10, %2
br i1 %20, label %21, label %5
21: ; preds = %19, %11, %3
%22 = phi i32 [ 0, %3 ], [ -1, %11 ], [ 0, %19 ]
ret i32 %22
}