#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 */
int /*<<< orphan*/ EXIT_FAILURE;
double atof(char *);
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
double *mandelbrot_end(int, double, double, double, int);
double pow(double, double);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ write_data(char *, int, double *);
int main(int argc, char *argv[]) {
  int size = atoi(argv[1]);
  double dX = atof(argv[2]);
  double dY = atof(argv[3]);
  double rad = atof(argv[4]);
  int iter = atoi(argv[5]);
  int start = atoi(argv[6]);
  int end = atoi(argv[7]);
  int skip = atoi(argv[8]);
  int cores = atoi(argv[9]);
  char *path = argv[10];
  double scale = 0.5;
  int n;
  for (n = start * skip; n < end; n += cores * skip) {
    printf("creating buffer (%d, %f, %f, %.16f, %d)\n", size, dX, dY,
           rad * pow(scale, (double)n), iter);
    double *buffer =
        mandelbrot_end(size, dX, dY, rad * pow(scale, (double)n), iter);
    if (buffer == NULL)
      exit(EXIT_FAILURE);
    printf("writing file %d\n", n);
    char file[255];
    sprintf(file, "%s/mandelbrot_%d.csv", path, n);
    write_data(file, size * size, buffer);
    free(buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1050 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x38(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x40(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x48(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x50(%rax),%rax
mov    %rax,-0x50(%rbp)
movsd  0xdad(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x38(%rbp),%eax
imul   -0x40(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    13c9 <main+0x239>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1a4(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x198(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x1a0(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x1b0(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
call   1080 <pow@plt>
movsd  -0x1b0(%rbp),%xmm2
ff
mov    -0x1a4(%rbp),%esi
movsd  -0x1a0(%rbp),%xmm1
ff
movaps %xmm0,%xmm3
movsd  -0x198(%rbp),%xmm0
ff
mulsd  %xmm3,%xmm2
mov    -0x34(%rbp),%edx
lea    0xd2c(%rip),%rdi
mov    $0x3,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x184(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x178(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x180(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x190(%rbp)
ff
movsd  -0x58(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
call   1080 <pow@plt>
movsd  -0x190(%rbp),%xmm2
ff
mov    -0x184(%rbp),%edi
movsd  -0x180(%rbp),%xmm1
ff
movaps %xmm0,%xmm3
movsd  -0x178(%rbp),%xmm0
ff
mulsd  %xmm3,%xmm2
mov    -0x34(%rbp),%esi
call   1040 <mandelbrot_end@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    136c <main+0x1dc>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x5c(%rbp),%esi
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x170(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    -0x5c(%rbp),%ecx
lea    0xcb0(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x170(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   -0x14(%rbp),%esi
mov    -0x68(%rbp),%rdx
call   1070 <write_data@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
imul   -0x40(%rbp),%eax
add    -0x5c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    1262 <main+0xd2>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,0xc(%rsp)
mov    0x10(%rbx),%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x30(%rsp)
mov    0x18(%rbx),%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x28(%rsp)
mov    0x20(%rbx),%rdi
call   1050 <atof@plt>
movsd  %xmm0,0x20(%rsp)
mov    0x28(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,0x1c(%rsp)
mov    0x30(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
mov    0x38(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r13d
mov    0x40(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
imul   %r12d,%r15d
mov    %r13d,0x18(%rsp)
cmp    %r13d,%r15d
jge    132e <main+0x19e>
mov    %eax,%ebp
mov    0x50(%rbx),%rax
mov    %rax,0x38(%rsp)
mov    0x48(%rbx),%rdi
call   1090 <atoi@plt>
mov    0xc(%rsp),%ecx
imul   %ecx,%ecx
mov    %ecx,0x14(%rsp)
imul   %ebp,%eax
mov    %eax,0x10(%rsp)
imul   %ebp,%r12d
mov    0xc(%rsp),%ebx
mov    0x1c(%rsp),%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
xorpd  0xd90(%rip),%xmm0
movapd %xmm0,0x40(%rsp)
call   1070 <exp2@plt>
movapd %xmm0,%xmm2
mulsd  0x20(%rsp),%xmm2
lea    0xd84(%rip),%rdi
mov    %ebx,%esi
movsd  0x30(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mov    %ebp,%edx
mov    $0x3,%al
call   1060 <printf@plt>
movapd 0x40(%rsp),%xmm0
call   1070 <exp2@plt>
movapd %xmm0,%xmm2
mulsd  0x20(%rsp),%xmm2
mov    %ebx,%edi
movsd  0x30(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mov    %ebp,%esi
call   1040 <mandelbrot_end@plt>
test   %rax,%rax
je     1342 <main+0x1b2>
mov    %rax,%r13
lea    0xd5d(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x50(%rsp),%r14
mov    %r14,%rdi
lea    0xd55(%rip),%rsi
mov    0x38(%rsp),%rdx
mov    %r15d,%ecx
call   10a0 <sprintf@plt>
mov    %r14,%rdi
mov    0x14(%rsp),%esi
mov    %r13,%rdx
call   1080 <write_data@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%eax
add    %eax,%r15d
add    %eax,%r12d
cmp    0x18(%rsp),%r12d
jl     1260 <main+0xd0>
xor    %eax,%eax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"creating buffer (%d, %f, %f, %.16f, %d)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"writing file %d\0A\00"
@.str.2 = [21 x i8] c"%s/mandelbrot_%d.csv\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca double
%17 = alloca i32
%18 = alloca double*
%19 = alloca [255 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call double @atof(i8* %26)
store double %27, double* %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
%31 = call double @atof(i8* %30)
store double %31, double* %8
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 4
%34 = load i8*, i8** %33
%35 = call double @atof(i8* %34)
store double %35, double* %9
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 5
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %10
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 6
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %11
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 7
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %12
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 8
%50 = load i8*, i8** %49
%51 = call i32 @atoi(i8* %50)
store i32 %51, i32* %13
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 9
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %14
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 10
%58 = load i8*, i8** %57
store i8* %58, i8** %15
store double 5.000000e-01, double* %16
%59 = load i32, i32* %11
%60 = load i32, i32* %13
%61 = mul nsw i32 %59, %60
store i32 %61, i32* %17
br label %62
62: ; preds = %109, %2
%63 = load i32, i32* %17
%64 = load i32, i32* %12
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %115
66: ; preds = %62
%67 = load i32, i32* %6
%68 = load double, double* %7
%69 = load double, double* %8
%70 = load double, double* %9
%71 = load double, double* %16
%72 = load i32, i32* %17
%73 = sitofp i32 %72 to double
%74 = call double @pow(double %71, double %73)
%75 = fmul double %70, %74
%76 = load i32, i32* %10
%77 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %67, double %68, double %69, double %75, i32 %76)
%78 = load i32, i32* %6
%79 = load double, double* %7
%80 = load double, double* %8
%81 = load double, double* %9
%82 = load double, double* %16
%83 = load i32, i32* %17
%84 = sitofp i32 %83 to double
%85 = call double @pow(double %82, double %84)
%86 = fmul double %81, %85
%87 = load i32, i32* %10
%88 = call double* @mandelbrot_end(i32 %78, double %79, double %80, double %86, i32 %87)
store double* %88, double** %18
%89 = load double*, double** %18
%90 = icmp eq double* %89, null
br i1 %90, label %91, label %94
91: ; preds = %66
%92 = load i32, i32* @EXIT_FAILURE
%93 = call i32 @exit(i32 %92)
unreachable
94: ; preds = %66
%95 = load i32, i32* %17
%96 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %95)
%97 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%98 = load i8*, i8** %15
%99 = load i32, i32* %17
%100 = call i32 @sprintf(i8* %97, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %98, i32 %99)
%101 = getelementptr inbounds [255 x i8], [255 x i8]* %19, i64 0, i64 0
%102 = load i32, i32* %6
%103 = load i32, i32* %6
%104 = mul nsw i32 %102, %103
%105 = load double*, double** %18
%106 = call i32 @write_data(i8* %101, i32 %104, double* %105)
%107 = load double*, double** %18
%108 = call i32 @free(double* %107)
br label %109
109: ; preds = %94
%110 = load i32, i32* %14
%111 = load i32, i32* %13
%112 = mul nsw i32 %110, %111
%113 = load i32, i32* %17
%114 = add nsw i32 %113, %112
store i32 %114, i32* %17
br label %62
115: ; preds = %62
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"creating buffer (%d, %f, %f, %.16f, %d)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"writing file %d\0A\00"
@.str.2 = [21 x i8] c"%s/mandelbrot_%d.csv\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 @atoi(i8* %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call double @atof(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 3
%11 = load i8*, i8** %10
%12 = tail call double @atof(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 4
%14 = load i8*, i8** %13
%15 = tail call double @atof(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 5
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 6
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 7
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = getelementptr inbounds i8*, i8** %1, i64 8
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
%28 = getelementptr inbounds i8*, i8** %1, i64 10
%29 = load i8*, i8** %28
%30 = mul nsw i32 %27, %21
%31 = icmp slt i32 %30, %24
br i1 %31, label %32, label %60
32: ; preds = %2
%33 = getelementptr inbounds i8*, i8** %1, i64 9
%34 = load i8*, i8** %33
%35 = tail call i32 @atoi(i8* %34)
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%37 = mul nsw i32 %6, %6
%38 = mul nsw i32 %35, %27
br label %39
39: ; preds = %32, %53
%40 = phi i32 [ %30, %32 ], [ %58, %53 ]
%41 = sitofp i32 %40 to double
%42 = fneg double %41
%43 = call double @exp2(double %42)
%44 = fmul double %15, %43
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %6, double %9, double %12, double %44, i32 %18)
%46 = call double @exp2(double %42)
%47 = fmul double %15, %46
%48 = call double* @mandelbrot_end(i32 %6, double %9, double %12, double %47, i32 %18)
%49 = icmp eq double* %48, null
br i1 %49, label %50, label %53
50: ; preds = %39
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %39
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%55 = call i32 @sprintf(i8* %36, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %40)
%56 = call i32 @write_data(i8* %36, i32 %37, double* %48)
%57 = call i32 @free(double* %48)
%58 = add nsw i32 %40, %38
%59 = icmp slt i32 %58, %24
br i1 %59, label %39, label %60
60: ; preds = %53, %2
ret i32 0
}