#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*/ FILE;

/* Variables and functions */
int cos(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int sin(double);
void write_regular_polygon(int x0, int y0, int radius, int numverts,
                           float theta0, int r, int g, int b, FILE *f) {
  double dtheta = (2 * 3.14159265359) / numverts, theta = theta0;
  int x, y;
  fprintf(f, "%d %d %d\n", r, g, b);
  fprintf(f, "%d\n", numverts);
  for (int i = 0; i < numverts; i++) {
    x = (int)(radius * cos(theta));
    y = (int)(radius * sin(theta));
    fprintf(f, "%d %d ", x0 + x, y0 + y);
    theta += dtheta;
  }
  fprintf(f, "\n");
}


x86 assembly (clang, -O0):
<write_regular_polygon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xe9b(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    0x18(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    0x10(%rbp),%r8d
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1231 <write_regular_polygon+0x101>
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <cos@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <sin@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
add    -0x34(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0x38(%rbp),%ecx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11b4 <write_regular_polygon+0x84>
mov    0x18(%rbp),%rdi
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_regular_polygon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%eax
movss  %xmm0,0x8(%rsp)
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%r12d
mov    0x58(%rsp),%r14
mov    0x50(%rsp),%r8d
lea    0xe96(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
mov    %r9d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe86(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %ebx,%ebx
jle    1212 <write_regular_polygon+0xd2>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xe59(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
mov    %eax,%r13d
imul   %ebp,%r13d
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
imul   %ebp,%eax
add    %r12d,%r13d
lea    (%rax,%r15,1),%ecx
mov    %r14,%rdi
lea    0xe1b(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
add    $0xffffffff,%ebx
jne    11c0 <write_regular_polygon+0x80>
mov    $0xa,%edi
mov    %r14,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"%d %d %d\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [7 x i8] c"%d %d \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @write_regular_polygon(i32 %0, i32 %1, i32 %2, i32 %3, float %4, i32 %5, i32 %6, i32 %7, i32* %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32*
%19 = alloca double
%20 = alloca double
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i32 %0, i32* %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store float %4, float* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i32* %8, i32** %18
%24 = load i32, i32* %13
%25 = sitofp i32 %24 to double
%26 = fdiv double 0x401921FB54442EEA, %25
store double %26, double* %19
%27 = load float, float* %14
%28 = fpext float %27 to double
store double %28, double* %20
%29 = load i32*, i32** %18
%30 = load i32, i32* %15
%31 = load i32, i32* %16
%32 = load i32, i32* %17
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
%34 = load i32*, i32** %18
%35 = load i32, i32* %13
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %35)
store i32 0, i32* %23
br label %37
37: ; preds = %61, %9
%38 = load i32, i32* %23
%39 = load i32, i32* %13
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %64
41: ; preds = %37
%42 = load i32, i32* %12
%43 = load double, double* %20
%44 = call i32 @cos(double %43)
%45 = mul nsw i32 %42, %44
store i32 %45, i32* %21
%46 = load i32, i32* %12
%47 = load double, double* %20
%48 = call i32 @sin(double %47)
%49 = mul nsw i32 %46, %48
store i32 %49, i32* %22
%50 = load i32*, i32** %18
%51 = load i32, i32* %10
%52 = load i32, i32* %21
%53 = add nsw i32 %51, %52
%54 = load i32, i32* %11
%55 = load i32, i32* %22
%56 = add nsw i32 %54, %55
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %53, i32 %56)
%58 = load double, double* %19
%59 = load double, double* %20
%60 = fadd double %59, %58
store double %60, double* %20
br label %61
61: ; preds = %41
%62 = load i32, i32* %23
%63 = add nsw i32 %62, 1
store i32 %63, i32* %23
br label %37
64: ; preds = %37
%65 = load i32*, i32** %18
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%d %d %d\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [7 x i8] c"%d %d \00"
define void @write_regular_polygon(i32 %0, i32 %1, i32 %2, i32 %3, float %4, i32 %5, i32 %6, i32 %7, i32* nocapture %8) {
%10 = sitofp i32 %3 to double
%11 = fdiv double 0x401921FB54442EEA, %10
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %7)
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%14 = icmp sgt i32 %3, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = fpext float %4 to double
br label %19
17: ; preds = %19, %9
%18 = tail call i32 @fputc(i32 10, i32* %8)
ret void
19: ; preds = %15, %19
%20 = phi i32 [ %30, %19 ], [ 0, %15 ]
%21 = phi double [ %29, %19 ], [ %16, %15 ]
%22 = tail call i32 @cos(double %21)
%23 = mul nsw i32 %22, %2
%24 = tail call i32 @sin(double %21)
%25 = mul nsw i32 %24, %2
%26 = add nsw i32 %23, %0
%27 = add nsw i32 %25, %1
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %27)
%29 = fadd double %11, %21
%30 = add nuw nsw i32 %20, 1
%31 = icmp eq i32 %30, %3
br i1 %31, label %17, label %19
}