#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__ isDiverge(float, float);
int divergeCount(float cx, float cy, int repeat) {
  float x = 0.0f, y = 0.0f;
  int count;
  for (count = 0; count < repeat; ++count) {
    float zx = x * x - y * y + cx;
    float zy = 2.0f * x * y + cy;
    if (isDiverge(zx, zy)) {
      return count;
    }
    x = zx;
    y = zy;
  }
  return count;
}


x86 assembly (clang, -O0):
<divergeCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
mov    %edi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e5 <divergeCount+0xd5>
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  -0x18(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xe7d(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
call   1030 <isDiverge@plt>
cmp    $0x0,%rax
je     11c3 <divergeCount+0xb3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11eb <divergeCount+0xdb>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <divergeCount+0x2c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<divergeCount>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
test   %edi,%edi
jle    1183 <divergeCount+0x73>
mov    %edi,%ebp
xor    %ebx,%ebx
xorps  %xmm0,%xmm0
xorps  %xmm1,%xmm1
movaps %xmm0,%xmm2
movaps %xmm1,%xmm3
mulss  %xmm1,%xmm3
mulss  %xmm0,%xmm0
subss  %xmm3,%xmm0
addss  0x8(%rsp),%xmm0
addss  %xmm2,%xmm2
mulss  %xmm2,%xmm1
addss  0xc(%rsp),%xmm1
movss  %xmm0,0x14(%rsp)
movss  %xmm1,0x10(%rsp)
call   1030 <isDiverge@plt>
test   %rax,%rax
jne    1185 <divergeCount+0x75>
add    $0x1,%ebx
cmp    %ebx,%ebp
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
jne    1130 <divergeCount+0x20>
mov    %ebp,%ebx
jmp    1185 <divergeCount+0x75>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @divergeCount(float %0, float %1, i32 %2) {
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca i32
%11 = alloca float
%12 = alloca float
store float %0, float* %5
store float %1, float* %6
store i32 %2, i32* %7
store float 0.000000e+00, float* %8
store float 0.000000e+00, float* %9
store i32 0, i32* %10
br label %13
13: ; preds = %41, %3
%14 = load i32, i32* %10
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %44
17: ; preds = %13
%18 = load float, float* %8
%19 = load float, float* %8
%20 = load float, float* %9
%21 = load float, float* %9
%22 = fmul float %20, %21
%23 = fneg float %22
%24 = call float @llvm.fmuladd.f32(float %18, float %19, float %23)
%25 = load float, float* %5
%26 = fadd float %24, %25
store float %26, float* %11
%27 = load float, float* %8
%28 = fmul float 2.000000e+00, %27
%29 = load float, float* %9
%30 = load float, float* %6
%31 = call float @llvm.fmuladd.f32(float %28, float %29, float %30)
store float %31, float* %12
%32 = load float, float* %11
%33 = load float, float* %12
%34 = call i64 @isDiverge(float %32, float %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %17
%37 = load i32, i32* %10
store i32 %37, i32* %4
br label %46
38: ; preds = %17
%39 = load float, float* %11
store float %39, float* %8
%40 = load float, float* %12
store float %40, float* %9
br label %41
41: ; preds = %38
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %13
44: ; preds = %13
%45 = load i32, i32* %10
store i32 %45, i32* %4
br label %46
46: ; preds = %44, %36
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
define i32 @divergeCount(float %0, float %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %20
5: ; preds = %3, %17
%6 = phi float [ %12, %17 ], [ 0.000000e+00, %3 ]
%7 = phi i32 [ %18, %17 ], [ 0, %3 ]
%8 = phi float [ %14, %17 ], [ 0.000000e+00, %3 ]
%9 = fneg float %8
%10 = fmul float %8, %9
%11 = tail call float @llvm.fmuladd.f32(float %6, float %6, float %10)
%12 = fadd float %11, %0
%13 = fmul float %6, 2.000000e+00
%14 = tail call float @llvm.fmuladd.f32(float %13, float %8, float %1)
%15 = tail call i64 @isDiverge(float %12, float %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %5
%18 = add nuw nsw i32 %7, 1
%19 = icmp eq i32 %18, %2
br i1 %19, label %20, label %5
20: ; preds = %5, %17, %3
%21 = phi i32 [ 0, %3 ], [ %2, %17 ], [ %7, %5 ]
ret i32 %21
}