#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 cos(double);
int /*<<< orphan*/ printf(char *);
int main() {
  double range, value;
  int count, offset, sp;
  printf("for Loop Example 8 - Cosine Graph Rewrite\n\n");
  range = 0.0;
  for (count = 1; count <= 40; count++) {
    value = cos(range);
    offset = (value + 1.0) * 15.0;
    for (sp = 0; sp < offset; sp++)
      printf(" ");
    printf("*\n");
    range += 0.5;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee2(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x28,-0x1c(%rbp)
jg     11dc <main+0xbc>
movsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe9d(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe88(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b0 <main+0x90>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <main+0x6a>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe4c(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <main+0x2a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
xorpd  %xmm0,%xmm0
lea    0xeef(%rip),%r14
jmp    117e <main+0x4e>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xe9a(%rip),%xmm0
add    $0x1,%ebp
cmp    $0x29,%ebp
je     11c1 <main+0x91>
movsd  %xmm0,0x8(%rsp)
call   1050 <cos@plt>
addsd  0xe6f(%rip),%xmm0
mulsd  0xe6f(%rip),%xmm0
cvttsd2si %xmm0,%ebx
test   %ebx,%ebx
jle    1160 <main+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11b0 <main+0x80>
jmp    1160 <main+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"for Loop Example 8 - Cosine Graph Rewrite\0A\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"*\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %2
store i32 1, i32* %4
br label %8
8: ; preds = %31, %0
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 40
br i1 %10, label %11, label %34
11: ; preds = %8
%12 = load double, double* %2
%13 = call double @cos(double %12)
store double %13, double* %3
%14 = load double, double* %3
%15 = fadd double %14, 1.000000e+00
%16 = fmul double %15, 1.500000e+01
%17 = fptosi double %16 to i32
store i32 %17, i32* %5
store i32 0, i32* %6
br label %18
18: ; preds = %24, %11
%19 = load i32, i32* %6
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %18
27: ; preds = %18
%28 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = load double, double* %2
%30 = fadd double %29, 5.000000e-01
store double %30, double* %2
br label %31
31: ; preds = %27
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %8
34: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@str = [43 x i8] c"for Loop Example 8 - Cosine Graph Rewrite\0A\00"
@str.3 = [2 x i8] c"*\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %15
%3 = phi double [ 0.000000e+00, %0 ], [ %17, %15 ]
%4 = phi i32 [ 1, %0 ], [ %18, %15 ]
%5 = tail call double @cos(double %3)
%6 = fadd double %5, 1.000000e+00
%7 = fmul double %6, 1.500000e+01
%8 = fptosi double %7 to i32
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2, %10
%11 = phi i32 [ %13, %10 ], [ 0, %2 ]
%12 = tail call i32 @putchar(i32 32)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, %8
br i1 %14, label %15, label %10
15: ; preds = %10, %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.3, i64 0, i64 0))
%17 = fadd double %3, 5.000000e-01
%18 = add nuw nsw i32 %4, 1
%19 = icmp eq i32 %18, 41
br i1 %19, label %20, label %2
20: ; preds = %15
ret i32 0
}