#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 offset, sp;
  printf("for Loop Example 7 - Simple Cosine Graph\n\n");
  for (range = 0.0; range <= 20.0; range += 0.5) {
    value = cos(range);
    offset = (value + 1.0) * 15.0;
    for (sp = 0; sp < offset; sp++)
      printf(" ");
    printf("*\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeea(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeb5(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11d5 <main+0xb5>
movsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xea3(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b2 <main+0x92>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118c <main+0x6c>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe52(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1143 <main+0x23>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xee6(%rip),%rdi
call   1040 <puts@plt>
xorpd  %xmm0,%xmm0
lea    0xf00(%rip),%rbx
jmp    1173 <main+0x43>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <puts@plt>
movsd  (%rsp),%xmm0
addsd  0xeab(%rip),%xmm0
movsd  0xeab(%rip),%xmm1
ucomisd %xmm0,%xmm1
jb     11b1 <main+0x81>
movsd  %xmm0,(%rsp)
call   1050 <cos@plt>
addsd  0xe7b(%rip),%xmm0
mulsd  0xe7b(%rip),%xmm0
cvttsd2si %xmm0,%ebp
test   %ebp,%ebp
jle    1150 <main+0x20>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11a0 <main+0x70>
jmp    1150 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"for Loop Example 7 - Simple Cosine Graph\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
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %2
br label %7
7: ; preds = %28, %0
%8 = load double, double* %2
%9 = fcmp ole double %8, 2.000000e+01
br i1 %9, label %10, label %31
10: ; preds = %7
%11 = load double, double* %2
%12 = call double @cos(double %11)
store double %12, double* %3
%13 = load double, double* %3
%14 = fadd double %13, 1.000000e+00
%15 = fmul double %14, 1.500000e+01
%16 = fptosi double %15 to i32
store i32 %16, i32* %4
store i32 0, i32* %5
br label %17
17: ; preds = %23, %10
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %17
26: ; preds = %17
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26
%29 = load double, double* %2
%30 = fadd double %29, 5.000000e-01
store double %30, double* %2
br label %7
31: ; preds = %7
ret i32 0
}

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