#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 */

/* Variables and functions */
scalar_t__ getlight(int *, int, int);
int count_lights(int *lights) {
  int acc;
  acc = 0;
  for (int x = 0; x < 1000; x++) {
    for (int y = 0; y < 1000; y++) {
      acc += getlight(lights, x, y);
    }
  }
  return acc;
}


x86 assembly (clang, -O0):
<count_lights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jge    1188 <count_lights+0x78>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    1175 <count_lights+0x65>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <getlight@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <count_lights+0x2e>
jmp    117a <count_lights+0x6a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <count_lights+0x1a>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lights>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %ebx,%ebx
nop
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <getlight@plt>
add    %eax,%ebx
add    $0x1,%ebp
cmp    $0x3e8,%ebp
jne    1130 <count_lights+0x20>
add    $0x1,%r15d
cmp    $0x3e8,%r15d
jne    1120 <count_lights+0x10>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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