#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 int16_t;

/* Variables and functions */
int /*<<< orphan*/ killmon(int);
int16_t killmonsters(int *clfirst, int *clcoll) {
  int next = clfirst[2], m, n = 0;
  while (next != -1) {
    m = next - ((0 + 1) + 7);
    killmon(m);
    n++;
    next = clcoll[next];
  }
  return n;
}


x86 assembly (clang, -O0):
<killmonsters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1168 <killmonsters+0x58>
mov    -0x14(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <killmon@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <killmonsters+0x21>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<killmonsters>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rdi),%ebx
cmp    $0xffffffff,%ebx
je     1149 <killmonsters+0x39>
mov    %rsi,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x8(%rbx),%edi
call   1030 <killmon@plt>
add    $0x1,%ebp
movslq %ebx,%rax
mov    (%r14,%rax,4),%ebx
cmp    $0xffffffff,%ebx
jne    1130 <killmonsters+0x20>
jmp    114b <killmonsters+0x3b>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @killmonsters(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%8 = load i32*, i32** %3
%9 = getelementptr inbounds i32, i32* %8, i64 2
%10 = load i32, i32* %9
store i32 %10, i32* %5
store i32 0, i32* %7
br label %11
11: ; preds = %14, %2
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 8
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = call i32 @killmon(i32 %17)
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
store i32 %25, i32* %5
br label %11
26: ; preds = %11
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
define i32 @killmonsters(i32* nocapture %0, i32* nocapture %1) {
%3 = getelementptr inbounds i32, i32* %0, i64 2
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %2, %6
%7 = phi i32 [ %14, %6 ], [ %4, %2 ]
%8 = phi i32 [ %11, %6 ], [ 0, %2 ]
%9 = add nsw i32 %7, -8
%10 = tail call i32 @killmon(i32 %9)
%11 = add nuw nsw i32 %8, 1
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %6
16: ; preds = %6, %2
%17 = phi i32 [ 0, %2 ], [ %11, %6 ]
ret i32 %17
}