#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ calc_pixel(double, double, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              double *);
void calc_mandelbrot(uint8_t *pic, double xstart, double xend, double ystart,
                     double yend, double xstep, double ystep, uint32_t height,
                     uint32_t width) {
  double x, y;
  int i, j;
  uint8_t r, g, b;
  double v;
  assert(pic != NULL);
  x = xstart;
  y = ystart;
  for (i = 0; i < height; i++) {
    for (j = 0; j < width; j++) {
      calc_pixel(x, y, &r, &g, &b, &v);
      pic[(i * width + j) * 3 + 0] = b;
      pic[(i * width + j) * 3 + 1] = g;
      pic[(i * width + j) * 3 + 2] = r;
      x += xstep;
    }
    y += ystep;
    x = xstart;
  }
}


x86 assembly (clang, -O0):
<calc_mandelbrot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movsd  %xmm5,-0x38(%rbp)
mov    %esi,-0x3c(%rbp)
mov    %edx,-0x40(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1256 <calc_mandelbrot+0x136>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    122f <calc_mandelbrot+0x10f>
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
lea    -0x5c(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x64(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   1040 <calc_pixel@plt>
mov    -0x64(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   -0x40(%rbp),%ecx
add    -0x58(%rbp),%ecx
imul   $0x3,%ecx,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x60(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   -0x40(%rbp),%ecx
add    -0x58(%rbp),%ecx
imul   $0x3,%ecx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x5c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   -0x40(%rbp),%ecx
add    -0x58(%rbp),%ecx
imul   $0x3,%ecx,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
movsd  -0x30(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1190 <calc_mandelbrot+0x70>
movsd  -0x38(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    117d <calc_mandelbrot+0x5d>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_mandelbrot>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edx,0x4(%rsp)
mov    %esi,%ebp
movsd  %xmm5,0x38(%rsp)
movsd  %xmm4,0x48(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x20(%rsp)
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
movsd  0x8(%rsp),%xmm2
test   %ebp,%ebp
jle    1256 <calc_mandelbrot+0x136>
movslq 0x4(%rsp),%rax
mov    %ebp,%ecx
mov    %rcx,0x30(%rsp)
mov    %eax,%ecx
add    $0x8,%rbx
shl    $0x2,%rax
lea    (%rax,%rax,2),%rax
mov    %rax,0x28(%rsp)
shl    $0x2,%rcx
lea    (%rcx,%rcx,2),%rcx
xor    %eax,%eax
lea    0x1c(%rsp),%r12
lea    0x18(%rsp),%r13
lea    0x14(%rsp),%rbp
lea    0x60(%rsp),%r14
jmp    11cf <calc_mandelbrot+0xaf>
nopw   0x0(%rax,%rax,1)
addsd  0x38(%rsp),%xmm2
mov    0x40(%rsp),%rax
add    $0x1,%rax
add    0x28(%rsp),%rbx
cmp    0x30(%rsp),%rax
je     1256 <calc_mandelbrot+0x136>
mov    %rax,0x40(%rsp)
cmpl   $0x0,0x4(%rsp)
jle    11b0 <calc_mandelbrot+0x90>
xor    %r15d,%r15d
movsd  0x20(%rsp),%xmm0
movsd  %xmm2,0x8(%rsp)
mov    %rbx,0x50(%rsp)
nop
movsd  %xmm0,0x58(%rsp)
movsd  0x8(%rsp),%xmm1
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %rcx,%rbx
mov    %r14,%rcx
call   1040 <calc_pixel@plt>
movsd  0x58(%rsp),%xmm0
movsd  0x48(%rsp),%xmm1
mov    %rbx,%rcx
mov    0x50(%rsp),%rbx
movsd  0x8(%rsp),%xmm2
mov    0x14(%rsp),%eax
mov    %eax,-0x8(%rbx,%r15,1)
mov    0x18(%rsp),%eax
mov    %eax,-0x4(%rbx,%r15,1)
mov    0x1c(%rsp),%eax
mov    %eax,(%rbx,%r15,1)
addsd  %xmm1,%xmm0
add    $0xc,%r15
cmp    %r15,%rcx
jne    11f0 <calc_mandelbrot+0xd0>
jmp    11b0 <calc_mandelbrot+0x90>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @calc_mandelbrot(i32* %0, double %1, double %2, double %3, double %4, double %5, double %6, i32 %7, i32 %8) {
%10 = alloca i32*
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
%20 = alloca double
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca double
store i32* %0, i32** %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store double %4, double* %14
store double %5, double* %15
store double %6, double* %16
store i32 %7, i32* %17
store i32 %8, i32* %18
%27 = load i32*, i32** %10
%28 = icmp ne i32* %27, null
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load double, double* %11
store double %31, double* %19
%32 = load double, double* %13
store double %32, double* %20
store i32 0, i32* %21
br label %33
33: ; preds = %90, %9
%34 = load i32, i32* %21
%35 = load i32, i32* %17
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %93
37: ; preds = %33
store i32 0, i32* %22
br label %38
38: ; preds = %82, %37
%39 = load i32, i32* %22
%40 = load i32, i32* %18
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %85
42: ; preds = %38
%43 = load double, double* %19
%44 = load double, double* %20
%45 = call i32 @calc_pixel(double %43, double %44, i32* %23, i32* %24, i32* %25, double* %26)
%46 = load i32, i32* %25
%47 = load i32*, i32** %10
%48 = load i32, i32* %21
%49 = load i32, i32* %18
%50 = mul nsw i32 %48, %49
%51 = load i32, i32* %22
%52 = add nsw i32 %50, %51
%53 = mul nsw i32 %52, 3
%54 = add nsw i32 %53, 0
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %47, i64 %55
store i32 %46, i32* %56
%57 = load i32, i32* %24
%58 = load i32*, i32** %10
%59 = load i32, i32* %21
%60 = load i32, i32* %18
%61 = mul nsw i32 %59, %60
%62 = load i32, i32* %22
%63 = add nsw i32 %61, %62
%64 = mul nsw i32 %63, 3
%65 = add nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %58, i64 %66
store i32 %57, i32* %67
%68 = load i32, i32* %23
%69 = load i32*, i32** %10
%70 = load i32, i32* %21
%71 = load i32, i32* %18
%72 = mul nsw i32 %70, %71
%73 = load i32, i32* %22
%74 = add nsw i32 %72, %73
%75 = mul nsw i32 %74, 3
%76 = add nsw i32 %75, 2
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %69, i64 %77
store i32 %68, i32* %78
%79 = load double, double* %15
%80 = load double, double* %19
%81 = fadd double %80, %79
store double %81, double* %19
br label %82
82: ; preds = %42
%83 = load i32, i32* %22
%84 = add nsw i32 %83, 1
store i32 %84, i32* %22
br label %38
85: ; preds = %38
%86 = load double, double* %16
%87 = load double, double* %20
%88 = fadd double %87, %86
store double %88, double* %20
%89 = load double, double* %11
store double %89, double* %19
br label %90
90: ; preds = %85
%91 = load i32, i32* %21
%92 = add nsw i32 %91, 1
store i32 %92, i32* %21
br label %33
93: ; preds = %33
ret void
}

LLVM IR (-O2):
define void @calc_mandelbrot(i32* writeonly %0, double %1, double %2, double %3, double %4, double %5, double %6, i32 %7, i32 %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = bitcast i32* %10 to i8*
%15 = bitcast i32* %11 to i8*
%16 = bitcast i32* %12 to i8*
%17 = bitcast double* %13 to i8*
%18 = icmp ne i32* %0, null
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = icmp sgt i32 %7, 0
br i1 %21, label %22, label %53
22: ; preds = %9
%23 = icmp sgt i32 %8, 0
%24 = sext i32 %8 to i64
%25 = zext i32 %7 to i64
%26 = zext i32 %8 to i64
br label %27
27: ; preds = %22, %49
%28 = phi i64 [ 0, %22 ], [ %51, %49 ]
%29 = phi double [ %3, %22 ], [ %50, %49 ]
br i1 %23, label %30, label %49
30: ; preds = %27
%31 = mul nsw i64 %28, %24
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 0, %30 ], [ %47, %32 ]
%34 = phi double [ %1, %30 ], [ %46, %32 ]
%35 = call i32 @calc_pixel(double %34, double %29, i32* %10, i32* %11, i32* %12, double* %13)
%36 = load i32, i32* %12
%37 = add nsw i64 %33, %31
%38 = mul nsw i64 %37, 3
%39 = getelementptr inbounds i32, i32* %0, i64 %38
store i32 %36, i32* %39
%40 = load i32, i32* %11
%41 = add nsw i64 %38, 1
%42 = getelementptr inbounds i32, i32* %0, i64 %41
store i32 %40, i32* %42
%43 = load i32, i32* %10
%44 = add nsw i64 %38, 2
%45 = getelementptr inbounds i32, i32* %0, i64 %44
store i32 %43, i32* %45
%46 = fadd double %34, %5
%47 = add nuw nsw i64 %33, 1
%48 = icmp eq i64 %47, %26
br i1 %48, label %49, label %32
49: ; preds = %32, %27
%50 = fadd double %29, %6
%51 = add nuw nsw i64 %28, 1
%52 = icmp eq i64 %51, %25
br i1 %52, label %53, label %27
53: ; preds = %49, %9
ret void
}