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

/* Variables and functions */
float M_PI;
float cosf(float);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, float, int, int);
int rand();
int /*<<< orphan*/ setpx(int /*<<< orphan*/ *, int, int, int, int);
float sinf(float);
int /*<<< orphan*/ stderr;
void circle(uint8_t *img, int w, int h) {
  float r = w < h ? w * 0.5f : h * 0.5f;
  float xc = 0.5f * w;
  float yc = 0.5f * h;
  float t;
  for (t = 0; t <= 2.0f * M_PI; t += 0.0001 * M_PI) {
    int x = r * cosf(t) + xc;
    int y = r * sinf(t) + yc;
    fprintf(stderr, "t=%.3f x=%d y=%d\n", t, x, y);
    setpx(img, w, x, y, rand() % 127 + 128);
  }
}


x86 assembly (clang, -O0):
<circle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1189 <circle+0x39>
cvtsi2ssl -0xc(%rbp),%xmm0
movss  0xe85(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
jmp    119f <circle+0x4f>
cvtsi2ssl -0x10(%rbp),%xmm0
movss  0xe6a(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm1
movss  0xe4a(%rip),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
cvtsi2ssl -0x10(%rbp),%xmm1
movss  0xe34(%rip),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm1
movss  0xe1a(%rip),%xmm0
mov    0x2df7(%rip),%rax
mulss  (%rax),%xmm0
ucomiss %xmm1,%xmm0
jb     12fb <circle+0x1ab>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x20(%rbp),%xmm0
call   1040 <cosf@plt>
movaps %xmm0,%xmm2
movss  -0x48(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <sinf@plt>
movaps %xmm0,%xmm2
movss  -0x44(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
movss  -0x20(%rbp),%xmm0
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xd97(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%ecx
mov    $0x7f,%r8d
cltd
idiv   %r8d
mov    %edx,%r8d
mov    -0x30(%rbp),%edx
add    $0x80,%r8d
call   1060 <setpx@plt>
mov    0x2d1c(%rip),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xd23(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    11dd <circle+0x8d>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<circle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    %edx,%esi
mov    %edx,%eax
cmovl  %esi,%eax
mov    0x2e7c(%rip),%r13
movss  0x0(%r13),%xmm1
addss  %xmm1,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jb     129c <circle+0x14c>
mov    %esi,%r12d
mov    %rdi,%r14
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
movss  0xe69(%rip),%xmm2
mulss  %xmm2,%xmm1
movss  %xmm1,0xc(%rsp)
xorps  %xmm1,%xmm1
cvtsi2ss %esi,%xmm1
mulss  %xmm2,%xmm1
movss  %xmm1,0x14(%rsp)
xorps  %xmm1,%xmm1
cvtsi2ss %edx,%xmm1
mulss  %xmm2,%xmm1
movss  %xmm1,0x10(%rsp)
lea    0xe46(%rip),%r15
nopw   0x0(%rax,%rax,1)
movss  %xmm0,0x8(%rsp)
call   1040 <cosf@plt>
mulss  0xc(%rsp),%xmm0
addss  0x14(%rsp),%xmm0
cvttss2si %xmm0,%ebp
movss  0x8(%rsp),%xmm0
call   1030 <sinf@plt>
mulss  0xc(%rsp),%xmm0
addss  0x10(%rsp),%xmm0
cvttss2si %xmm0,%ebx
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
movss  0x8(%rsp),%xmm0
mov    %ebp,%edx
mov    %ebx,%ecx
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0xffffffff81020409,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x6,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x7,%edx
sub    %edx,%ecx
lea    (%rax,%rcx,1),%r8d
add    $0x80,%r8d
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1060 <setpx@plt>
movss  0x0(%r13),%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
movss  0x8(%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
mulsd  0xd84(%rip),%xmm1
addsd  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
addss  %xmm3,%xmm3
ucomiss %xmm0,%xmm3
jae    11d0 <circle+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global float 0.000000e+00
@stderr = global i32 0
@.str = [18 x i8] c"t=%.3f x=%d y=%d\0A\00"
define void @circle(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* %5
%18 = sitofp i32 %17 to float
%19 = fmul float %18, 5.000000e-01
br label %24
20: ; preds = %3
%21 = load i32, i32* %6
%22 = sitofp i32 %21 to float
%23 = fmul float %22, 5.000000e-01
br label %24
24: ; preds = %20, %16
%25 = phi float [ %19, %16 ], [ %23, %20 ]
store float %25, float* %7
%26 = load i32, i32* %5
%27 = sitofp i32 %26 to float
%28 = fmul float 5.000000e-01, %27
store float %28, float* %8
%29 = load i32, i32* %6
%30 = sitofp i32 %29 to float
%31 = fmul float 5.000000e-01, %30
store float %31, float* %9
store float 0.000000e+00, float* %10
br label %32
32: ; preds = %63, %24
%33 = load float, float* %10
%34 = load float, float* @M_PI
%35 = fmul float 2.000000e+00, %34
%36 = fcmp ole float %33, %35
br i1 %36, label %37, label %70
37: ; preds = %32
%38 = load float, float* %7
%39 = load float, float* %10
%40 = call float @cosf(float %39)
%41 = load float, float* %8
%42 = call float @llvm.fmuladd.f32(float %38, float %40, float %41)
%43 = fptosi float %42 to i32
store i32 %43, i32* %11
%44 = load float, float* %7
%45 = load float, float* %10
%46 = call float @sinf(float %45)
%47 = load float, float* %9
%48 = call float @llvm.fmuladd.f32(float %44, float %46, float %47)
%49 = fptosi float %48 to i32
store i32 %49, i32* %12
%50 = load i32, i32* @stderr
%51 = load float, float* %10
%52 = load i32, i32* %11
%53 = load i32, i32* %12
%54 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), float %51, i32 %52, i32 %53)
%55 = load i32*, i32** %4
%56 = load i32, i32* %5
%57 = load i32, i32* %11
%58 = load i32, i32* %12
%59 = call i32 (...) @rand()
%60 = srem i32 %59, 127
%61 = add nsw i32 %60, 128
%62 = call i32 @setpx(i32* %55, i32 %56, i32 %57, i32 %58, i32 %61)
br label %63
63: ; preds = %37
%64 = load float, float* @M_PI
%65 = fpext float %64 to double
%66 = load float, float* %10
%67 = fpext float %66 to double
%68 = call double @llvm.fmuladd.f64(double 1.000000e-04, double %65, double %67)
%69 = fptrunc double %68 to float
store float %69, float* %10
br label %32
70: ; preds = %32
ret void
}

LLVM IR (-O2):
@M_PI = global float 0.000000e+00
@stderr = global i32 0
@.str = [18 x i8] c"t=%.3f x=%d y=%d\0A\00"
define void @circle(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
%5 = select i1 %4, i32 %1, i32 %2
%6 = sitofp i32 %5 to float
%7 = fmul float %6, 5.000000e-01
%8 = sitofp i32 %1 to float
%9 = fmul float %8, 5.000000e-01
%10 = sitofp i32 %2 to float
%11 = fmul float %10, 5.000000e-01
%12 = load float, float* @M_PI
%13 = fmul float %12, 2.000000e+00
%14 = fcmp ult float %13, 0.000000e+00
br i1 %14, label %36, label %15
15: ; preds = %3, %15
%16 = phi float [ %33, %15 ], [ 0.000000e+00, %3 ]
%17 = tail call float @cosf(float %16)
%18 = tail call float @llvm.fmuladd.f32(float %7, float %17, float %9)
%19 = fptosi float %18 to i32
%20 = tail call float @sinf(float %16)
%21 = tail call float @llvm.fmuladd.f32(float %7, float %20, float %11)
%22 = fptosi float %21 to i32
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), float %16, i32 %19, i32 %22)
%25 = tail call i32 (...) @rand()
%26 = srem i32 %25, 127
%27 = add nsw i32 %26, 128
%28 = tail call i32 @setpx(i32* %0, i32 %1, i32 %19, i32 %22, i32 %27)
%29 = load float, float* @M_PI
%30 = fpext float %29 to double
%31 = fpext float %16 to double
%32 = tail call double @llvm.fmuladd.f64(double %30, double 1.000000e-04, double %31)
%33 = fptrunc double %32 to float
%34 = fmul float %29, 2.000000e+00
%35 = fcmp ult float %34, %33
br i1 %35, label %36, label %15
36: ; preds = %15, %3
ret void
}