#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 y;
typedef int x;

/* Variables and functions */
double pixel_weight(int const *, int, int);
int next_pixel(const int *order) {
  int best, x, y;
  double bestweight, w;
  best = -1;
  bestweight = -1;
  for (y = 0; y < 32; y++) {
    for (x = 0; x < 32; x++) {
      if (order[(((x) + 32) % 32 + (((y) + 32) % 32) * 32)] >= 0)
        continue;
      w = pixel_weight(order, x, y);
      if (w >= bestweight) {
        bestweight = w;
        best = (((x) + 32) % 32 + (((y) + 32) % 32) * 32);
      }
    }
  }
  return best;
}


x86 assembly (clang, -O0):
<next_pixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movsd  0xed5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jge    1219 <next_pixel+0x109>
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    1206 <next_pixel+0xf6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
mov    %edx,%ecx
mov    -0x2c(%rbp),%edx
shl    $0x5,%ecx
add    %ecx,%edx
movslq %edx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
jl     1199 <next_pixel+0x89>
jmp    11f8 <next_pixel+0xe8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <pixel_weight@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     11f3 <next_pixel+0xe3>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,-0x3c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x3c(%rbp),%edx
shl    $0x5,%eax
add    %eax,%edx
mov    %edx,-0xc(%rbp)
jmp    11f8 <next_pixel+0xe8>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1148 <next_pixel+0x38>
jmp    120b <next_pixel+0xfb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <next_pixel+0x27>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_pixel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
xor    %r15d,%r15d
movsd  0xed7(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    $0xffffffff,%r14d
jmp    114a <next_pixel+0x3a>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15d
cmp    $0x20,%r15d
je     1192 <next_pixel+0x82>
mov    %r15d,%r13d
shl    $0x5,%r13d
xor    %ebp,%ebp
jmp    1168 <next_pixel+0x58>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
cmp    $0x20,%ebp
je     1140 <next_pixel+0x30>
mov    %ebp,%ebx
or     %r13d,%ebx
cmpl   $0x0,(%r12,%rbx,4)
jns    1160 <next_pixel+0x50>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <pixel_weight@plt>
ucomisd (%rsp),%xmm0
jb     1160 <next_pixel+0x50>
movsd  %xmm0,(%rsp)
mov    %ebx,%r14d
jmp    1160 <next_pixel+0x50>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @next_pixel(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store i32* %0, i32** %2
store i32 -1, i32* %3
store double -1.000000e+00, double* %6
store i32 0, i32* %5
br label %8
8: ; preds = %53, %1
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 32
br i1 %10, label %11, label %56
11: ; preds = %8
store i32 0, i32* %4
br label %12
12: ; preds = %49, %11
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 32
br i1 %14, label %15, label %52
15: ; preds = %12
%16 = load i32*, i32** %2
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 32
%19 = srem i32 %18, 32
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 32
%22 = srem i32 %21, 32
%23 = mul nsw i32 %22, 32
%24 = add nsw i32 %19, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %16, i64 %25
%27 = load i32, i32* %26
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %15
br label %49
30: ; preds = %15
%31 = load i32*, i32** %2
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = call double @pixel_weight(i32* %31, i32 %32, i32 %33)
store double %34, double* %7
%35 = load double, double* %7
%36 = load double, double* %6
%37 = fcmp oge double %35, %36
br i1 %37, label %38, label %48
38: ; preds = %30
%39 = load double, double* %7
store double %39, double* %6
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 32
%42 = srem i32 %41, 32
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 32
%45 = srem i32 %44, 32
%46 = mul nsw i32 %45, 32
%47 = add nsw i32 %42, %46
store i32 %47, i32* %3
br label %48
48: ; preds = %38, %30
br label %49
49: ; preds = %48, %29
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %12
52: ; preds = %12
br label %53
53: ; preds = %52
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %8
56: ; preds = %8
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @next_pixel(i32* %0) {
br label %2
2: ; preds = %1, %25
%3 = phi i32 [ -1, %1 ], [ %22, %25 ]
%4 = phi double [ -1.000000e+00, %1 ], [ %21, %25 ]
%5 = phi i32 [ 0, %1 ], [ %26, %25 ]
%6 = shl i32 %5, 5
br label %7
7: ; preds = %2, %20
%8 = phi i32 [ %3, %2 ], [ %22, %20 ]
%9 = phi double [ %4, %2 ], [ %21, %20 ]
%10 = phi i32 [ 0, %2 ], [ %23, %20 ]
%11 = or i32 %10, %6
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = icmp sgt i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %7
%17 = tail call double @pixel_weight(i32* %0, i32 %10, i32 %5)
%18 = fcmp ult double %17, %9
br i1 %18, label %20, label %19
19: ; preds = %16
br label %20
20: ; preds = %16, %19, %7
%21 = phi double [ %9, %7 ], [ %17, %19 ], [ %9, %16 ]
%22 = phi i32 [ %8, %7 ], [ %11, %19 ], [ %8, %16 ]
%23 = add nuw nsw i32 %10, 1
%24 = icmp eq i32 %23, 32
br i1 %24, label %25, label %7
25: ; preds = %20
%26 = add nuw nsw i32 %5, 1
%27 = icmp eq i32 %26, 32
br i1 %27, label %28, label %2
28: ; preds = %25
ret i32 %22
}