#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 M_PI;
double cos(double);
scalar_t__ malloc(int);
double sin(double);
double *createCylinder(double radius, double step, int n) {
  double *result = (double *)malloc(3 * n * sizeof(double));
  double length = 2 * M_PI * radius;
  int pointsPerCircle = length / step;
  double angleStep = 2 * M_PI / pointsPerCircle;
  int i;
  for (i = 0; i < n; i++) {
    result[3 * i + 0] = radius * cos(angleStep * i);
    result[3 * i + 1] = radius * sin(angleStep * i),
                   result[3 * i + 2] = (step * i) / pointsPerCircle;
  }
  return result;
}


x86 assembly (clang, -O0):
<createCylinder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
imul   $0x3,-0x14(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cltd
idivl  -0x2c(%rbp)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1261 <createCylinder+0x131>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
imul   $0x3,-0x3c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a5 <createCylinder+0x75>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createCylinder>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
lea    0x0(,%rbx,8),%eax
lea    (%rax,%rax,2),%edi
call   1040 <malloc@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%ecx
add    %ecx,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
mov    %rax,%r14
mov    %ecx,%eax
cltd
idiv   %esi
test   %ebx,%ebx
jle    122f <createCylinder+0xff>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %ebx,%r15d
mov    %r14,%rbx
add    $0x10,%rbx
xor    %r12d,%r12d
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
movsd  %xmm1,0x30(%rsp)
movsd  0x20(%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x28(%rsp)
call   1050 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,-0x10(%rbx)
movsd  0x28(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
mulsd  %xmm2,%xmm0
movsd  %xmm0,-0x8(%rbx)
movsd  0x30(%rsp),%xmm0
mulsd  %xmm1,%xmm0
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rbx)
add    $0x1,%r12
add    $0x18,%rbx
cmp    %r12,%r15
jne    11c0 <createCylinder+0x90>
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double* @createCylinder(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double*
%8 = alloca double
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
store double %0, double* %4
store double %1, double* %5
store i32 %2, i32* %6
%12 = load i32, i32* %6
%13 = mul nsw i32 3, %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %7
%19 = load i32, i32* @M_PI
%20 = mul nsw i32 2, %19
%21 = sitofp i32 %20 to double
%22 = load double, double* %4
%23 = fmul double %21, %22
store double %23, double* %8
%24 = load double, double* %8
%25 = load double, double* %5
%26 = fdiv double %24, %25
%27 = fptosi double %26 to i32
store i32 %27, i32* %9
%28 = load i32, i32* @M_PI
%29 = mul nsw i32 2, %28
%30 = load i32, i32* %9
%31 = sdiv i32 %29, %30
%32 = sitofp i32 %31 to double
store double %32, double* %10
store i32 0, i32* %11
br label %33
33: ; preds = %77, %3
%34 = load i32, i32* %11
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %80
37: ; preds = %33
%38 = load double, double* %4
%39 = load double, double* %10
%40 = load i32, i32* %11
%41 = sitofp i32 %40 to double
%42 = fmul double %39, %41
%43 = call double @cos(double %42)
%44 = fmul double %38, %43
%45 = load double*, double** %7
%46 = load i32, i32* %11
%47 = mul nsw i32 3, %46
%48 = add nsw i32 %47, 0
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %45, i64 %49
store double %44, double* %50
%51 = load double, double* %4
%52 = load double, double* %10
%53 = load i32, i32* %11
%54 = sitofp i32 %53 to double
%55 = fmul double %52, %54
%56 = call double @sin(double %55)
%57 = fmul double %51, %56
%58 = load double*, double** %7
%59 = load i32, i32* %11
%60 = mul nsw i32 3, %59
%61 = add nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %58, i64 %62
store double %57, double* %63
%64 = load double, double* %5
%65 = load i32, i32* %11
%66 = sitofp i32 %65 to double
%67 = fmul double %64, %66
%68 = load i32, i32* %9
%69 = sitofp i32 %68 to double
%70 = fdiv double %67, %69
%71 = load double*, double** %7
%72 = load i32, i32* %11
%73 = mul nsw i32 3, %72
%74 = add nsw i32 %73, 2
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %71, i64 %75
store double %70, double* %76
br label %77
77: ; preds = %37
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %33
80: ; preds = %33
%81 = load double*, double** %7
ret double* %81
}

LLVM IR (-O2):
@M_PI = global i32 0
define double* @createCylinder(double %0, double %1, i32 %2) {
%4 = mul i32 %2, 24
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to double*
%7 = load i32, i32* @M_PI
%8 = shl nsw i32 %7, 1
%9 = sitofp i32 %8 to double
%10 = fmul double %9, %0
%11 = fdiv double %10, %1
%12 = fptosi double %11 to i32
%13 = sdiv i32 %8, %12
%14 = sitofp i32 %13 to double
%15 = icmp sgt i32 %2, 0
br i1 %15, label %16, label %38
16: ; preds = %3
%17 = sitofp i32 %12 to double
%18 = zext i32 %2 to i64
br label %19
19: ; preds = %16, %19
%20 = phi i64 [ 0, %16 ], [ %36, %19 ]
%21 = trunc i64 %20 to i32
%22 = sitofp i32 %21 to double
%23 = fmul double %14, %22
%24 = tail call double @cos(double %23)
%25 = fmul double %24, %0
%26 = mul nuw nsw i64 %20, 3
%27 = getelementptr inbounds double, double* %6, i64 %26
store double %25, double* %27
%28 = tail call double @sin(double %23)
%29 = fmul double %28, %0
%30 = add nuw nsw i64 %26, 1
%31 = getelementptr inbounds double, double* %6, i64 %30
store double %29, double* %31
%32 = fmul double %22, %1
%33 = fdiv double %32, %17
%34 = add nuw nsw i64 %26, 2
%35 = getelementptr inbounds double, double* %6, i64 %34
store double %33, double* %35
%36 = add nuw nsw i64 %20, 1
%37 = icmp eq i64 %36, %18
br i1 %37, label %38, label %19
38: ; preds = %19, %3
ret double* %6
}