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


x86 assembly (clang, -O0):
<cantor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsd  0xe96(%rip),%xmm0
movsd  %xmm0,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1227 <cantor+0xe7>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11dd <cantor+0x9d>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe49(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1214 <cantor+0xd4>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe19(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe05(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1219 <cantor+0xd9>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1185 <cantor+0x45>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cantor>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
movabs $0x3ff0000000000000,%rax
mov    %rax,(%r15)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmp    $0x2,%r14d
jl     11d0 <cantor+0x90>
mov    %r14d,%r14d
mov    $0x1,%ebx
movsd  0xe73(%rip),%xmm0
jmp    119f <cantor+0x5f>
nop
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
je     11d0 <cantor+0x90>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
movsd  0x8(%rsp),%xmm1
divsd  0xe4e(%rip),%xmm1
movapd %xmm1,%xmm0
addsd  0xe4a(%rip),%xmm0
test   $0x1,%al
je     1190 <cantor+0x50>
movapd %xmm1,%xmm0
jmp    1190 <cantor+0x50>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @cantor(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 = sext i32 %6 to i64
%8 = mul i64 %7, 8
%9 = trunc i64 %8 to i32
%10 = call double* @malloc(i32 %9)
store double* %10, double** %5
%11 = load double*, double** %5
%12 = getelementptr inbounds double, double* %11, i64 0
store double 1.000000e+00, double* %12
%13 = call i32 @time(i32* null)
%14 = call i32 @srand(i32 %13)
store i32 1, i32* %3
br label %15
15: ; preds = %50, %1
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %53
19: ; preds = %15
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 2
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %19
%25 = load double*, double** %5
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %25, i64 %28
%30 = load double, double* %29
%31 = fdiv double %30, 3.000000e+00
%32 = load double*, double** %5
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
store double %31, double* %35
br label %49
36: ; preds = %19
%37 = load double*, double** %5
%38 = load i32, i32* %3
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %37, i64 %40
%42 = load double, double* %41
%43 = fdiv double %42, 3.000000e+00
%44 = fadd double %43, 0x3FE5555555555555
%45 = load double*, double** %5
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
store double %44, double* %48
br label %49
49: ; preds = %36, %24
br label %50
50: ; preds = %49
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %15
53: ; preds = %15
%54 = load double*, double** %5
ret double* %54
}

LLVM IR (-O2):
define noalias double* @cantor(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call double* @malloc(i32 %2)
store double 1.000000e+00, double* %3
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %21
7: ; preds = %1
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi double [ 1.000000e+00, %7 ], [ %17, %9 ]
%11 = phi i64 [ 1, %7 ], [ %19, %9 ]
%12 = tail call i32 (...) @rand()
%13 = and i32 %12, 1
%14 = icmp eq i32 %13, 0
%15 = fdiv double %10, 3.000000e+00
%16 = fadd double %15, 0x3FE5555555555555
%17 = select i1 %14, double %16, double %15
%18 = getelementptr inbounds double, double* %3, i64 %11
store double %17, double* %18
%19 = add nuw nsw i64 %11, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %21, label %9
21: ; preds = %9, %1
ret double* %3
}