#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 */
double *malloc(int);
int rand();
double sqrt(double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
double *sierpinski(int n_iter) {
  int i;
  int test;
  double *points = malloc(2 * n_iter * sizeof(double));
  points[0] = 0.0;
  points[1] = 0.0;
  srand(time(NULL));
  for (i = 2; i < (2 * n_iter); i += 2) {
    test = rand() % 3;
    if (test == 0) {
      points[i] = 0.5 * points[i - 2];
      points[i + 1] = 0.5 * points[i - 1];
    } else if (test == 1) {
      points[i] = 0.5 * points[i - 2] + 0.25;
      points[i + 1] = 0.5 * points[i - 1] + sqrt(0.1875);
    } else {
      points[i] = 0.5 * points[i - 2] + 0.5;
      points[i + 1] = 0.5 * points[i - 1];
    }
  }
  return points;
}


x86 assembly (clang, -O0):
<sierpinski>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    132c <sierpinski+0x1dc>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1225 <sierpinski+0xd5>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  0xe1e(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xdf7(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1319 <sierpinski+0x1c9>
cmpl   $0x1,-0xc(%rbp)
jne    12b9 <sierpinski+0x169>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xdb7(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdbb(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xd83(%rip),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  0xd66(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1314 <sierpinski+0x1c4>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xd2d(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xd03(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1319 <sierpinski+0x1c9>
jmp    131e <sierpinski+0x1ce>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    11a0 <sierpinski+0x50>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sierpinski>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
shl    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xorpd  %xmm0,%xmm0
movupd %xmm0,(%rax)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmp    $0x2,%ebp
jl     1246 <sierpinski+0x106>
add    %ebp,%ebp
movslq %ebp,%r14
xorpd  %xmm1,%xmm1
mov    $0x1,%ebp
jmp    11b9 <sierpinski+0x79>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm1,0x8(%rbx,%rbp,8)
movsd  (%rbx,%rbp,8),%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rbx,%rbp,8)
lea    0x2(%rbp),%rax
add    $0x3,%rbp
cmp    %r14,%rbp
mov    %rax,%rbp
jge    1246 <sierpinski+0x106>
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x1,%eax
je     1210 <sierpinski+0xd0>
test   %eax,%eax
movsd  0x8(%rsp),%xmm1
movsd  0xe0a(%rip),%xmm2
mulsd  %xmm2,%xmm1
je     1190 <sierpinski+0x50>
addsd  %xmm2,%xmm1
jmp    1190 <sierpinski+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x8(%rsp),%xmm1
movsd  0xde2(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  0xdde(%rip),%xmm1
movsd  %xmm1,0x8(%rbx,%rbp,8)
movsd  (%rbx,%rbp,8),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xdcf(%rip),%xmm0
jmp    119f <sierpinski+0x5f>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double* @sierpinski(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double*
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = mul nsw i32 2, %6
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = trunc i64 %9 to i32
%11 = call double* @malloc(i32 %10)
store double* %11, double** %5
%12 = load double*, double** %5
%13 = getelementptr inbounds double, double* %12, i64 0
store double 0.000000e+00, double* %13
%14 = load double*, double** %5
%15 = getelementptr inbounds double, double* %14, i64 1
store double 0.000000e+00, double* %15
%16 = call i32 @time(i32* null)
%17 = call i32 @srand(i32 %16)
store i32 2, i32* %3
br label %18
18: ; preds = %106, %1
%19 = load i32, i32* %3
%20 = load i32, i32* %2
%21 = mul nsw i32 2, %20
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %109
23: ; preds = %18
%24 = call i32 (...) @rand()
%25 = srem i32 %24, 3
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %52
28: ; preds = %23
%29 = load double*, double** %5
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %29, i64 %32
%34 = load double, double* %33
%35 = fmul double 5.000000e-01, %34
%36 = load double*, double** %5
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
store double %35, double* %39
%40 = load double*, double** %5
%41 = load i32, i32* %3
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %40, i64 %43
%45 = load double, double* %44
%46 = fmul double 5.000000e-01, %45
%47 = load double*, double** %5
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %47, i64 %50
store double %46, double* %51
br label %105
52: ; preds = %23
%53 = load i32, i32* %4
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %80
55: ; preds = %52
%56 = load double*, double** %5
%57 = load i32, i32* %3
%58 = sub nsw i32 %57, 2
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %56, i64 %59
%61 = load double, double* %60
%62 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %61, double 2.500000e-01)
%63 = load double*, double** %5
%64 = load i32, i32* %3
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %62, double* %66
%67 = load double*, double** %5
%68 = load i32, i32* %3
%69 = sub nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %67, i64 %70
%72 = load double, double* %71
%73 = call double @sqrt(double 1.875000e-01)
%74 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %72, double %73)
%75 = load double*, double** %5
%76 = load i32, i32* %3
%77 = add nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %75, i64 %78
store double %74, double* %79
br label %104
80: ; preds = %52
%81 = load double*, double** %5
%82 = load i32, i32* %3
%83 = sub nsw i32 %82, 2
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %81, i64 %84
%86 = load double, double* %85
%87 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %86, double 5.000000e-01)
%88 = load double*, double** %5
%89 = load i32, i32* %3
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %88, i64 %90
store double %87, double* %91
%92 = load double*, double** %5
%93 = load i32, i32* %3
%94 = sub nsw i32 %93, 1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %92, i64 %95
%97 = load double, double* %96
%98 = fmul double 5.000000e-01, %97
%99 = load double*, double** %5
%100 = load i32, i32* %3
%101 = add nsw i32 %100, 1
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %99, i64 %102
store double %98, double* %103
br label %104
104: ; preds = %80, %55
br label %105
105: ; preds = %104, %28
br label %106
106: ; preds = %105
%107 = load i32, i32* %3
%108 = add nsw i32 %107, 2
store i32 %108, i32* %3
br label %18
109: ; preds = %18
%110 = load double*, double** %5
ret double* %110
}

LLVM IR (-O2):
define noalias double* @sierpinski(i32 %0) {
%2 = shl i32 %0, 4
%3 = tail call double* @malloc(i32 %2)
%4 = bitcast double* %3 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %44
8: ; preds = %1
%9 = shl nuw nsw i32 %0, 1
%10 = sext i32 %9 to i64
br label %11
11: ; preds = %8, %37
%12 = phi double [ 0.000000e+00, %8 ], [ %39, %37 ]
%13 = phi i64 [ 2, %8 ], [ %42, %37 ]
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 3
switch i32 %15, label %30 [
i32 0, label %16
i32 1, label %23
]
16: ; preds = %11
%17 = fmul double %12, 5.000000e-01
%18 = getelementptr inbounds double, double* %3, i64 %13
store double %17, double* %18
%19 = add nsw i64 %13, -1
%20 = getelementptr inbounds double, double* %3, i64 %19
%21 = load double, double* %20
%22 = fmul double %21, 5.000000e-01
br label %37
23: ; preds = %11
%24 = tail call double @llvm.fmuladd.f64(double %12, double 5.000000e-01, double 2.500000e-01)
%25 = getelementptr inbounds double, double* %3, i64 %13
store double %24, double* %25
%26 = add nsw i64 %13, -1
%27 = getelementptr inbounds double, double* %3, i64 %26
%28 = load double, double* %27
%29 = tail call double @llvm.fmuladd.f64(double %28, double 5.000000e-01, double 0x3FDBB67AE8584CAA)
br label %37
30: ; preds = %11
%31 = tail call double @llvm.fmuladd.f64(double %12, double 5.000000e-01, double 5.000000e-01)
%32 = getelementptr inbounds double, double* %3, i64 %13
store double %31, double* %32
%33 = add nsw i64 %13, -1
%34 = getelementptr inbounds double, double* %3, i64 %33
%35 = load double, double* %34
%36 = fmul double %35, 5.000000e-01
br label %37
37: ; preds = %16, %30, %23
%38 = phi double [ %22, %16 ], [ %36, %30 ], [ %29, %23 ]
%39 = phi double [ %17, %16 ], [ %31, %30 ], [ %24, %23 ]
%40 = or i64 %13, 1
%41 = getelementptr inbounds double, double* %3, i64 %40
store double %38, double* %41
%42 = add nuw nsw i64 %13, 2
%43 = icmp slt i64 %42, %10
br i1 %43, label %11, label %44
44: ; preds = %37, %1
ret double* %3
}