#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 /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int numValuesEnteredSoFar = 0;
  int numValuesToEnter;
  double numEntered, sum;
  printf("while Loop Example 5\n\n");
  printf("How many numbers would you like to enter? ");
  scanf("%d", &numValuesToEnter);
  sum = 0.0;
  while (numValuesEnteredSoFar < numValuesToEnter) {
    numValuesEnteredSoFar++;
    printf("Enter value %d: ", numValuesEnteredSoFar);
    scanf("%lf", &numEntered);
    sum = sum + numEntered;
  }
  printf("The sum of the values is %4.4lf.\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee9(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <main+0x98>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    116c <main+0x4c>
movsd  -0x20(%rbp),%xmm0
lea    0xe96(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xf24(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11c6 <main+0x96>
xorpd  %xmm0,%xmm0
lea    0xeb5(%rip),%r14
lea    0xebf(%rip),%r15
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
cmp    0x4(%rsp),%ebp
jl     1190 <main+0x60>
jmp    11ca <main+0x9a>
xorpd  %xmm0,%xmm0
lea    0xe72(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"while Loop Example 5\0A\0A\00"
@.str.1 = [43 x i8] c"How many numbers would you like to enter? \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [17 x i8] c"Enter value %d: \00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [34 x i8] c"The sum of the values is %4.4lf.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store double 0.000000e+00, double* %5
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %9
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %4)
%19 = load double, double* %5
%20 = load double, double* %4
%21 = fadd double %19, %20
store double %21, double* %5
br label %9
22: ; preds = %9
%23 = load double, double* %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), double %23)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [43 x i8] c"How many numbers would you like to enter? \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [17 x i8] c"Enter value %d: \00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [34 x i8] c"The sum of the values is %4.4lf.\0A\00"
@str = [22 x i8] c"while Loop Example 5\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = bitcast i32* %1 to i8*
%4 = bitcast double* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %0, %10
%11 = phi double [ %17, %10 ], [ 0.000000e+00, %0 ]
%12 = phi i32 [ %13, %10 ], [ 0, %0 ]
%13 = add nuw nsw i32 %12, 1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %2)
%16 = load double, double* %2
%17 = fadd double %11, %16
%18 = load i32, i32* %1
%19 = icmp slt i32 %13, %18
br i1 %19, label %10, label %20
20: ; preds = %10, %0
%21 = phi double [ 0.000000e+00, %0 ], [ %17, %10 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), double %21)
ret i32 0
}