#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 *, double *);
int main() {
  int counter;
  double numEntered, sum;
  printf("do-while Loop Example 3\n\n");
  sum = 0.0;
  counter = 1;
  do {
    printf("Enter a value: ");
    scanf("%lf", &numEntered);
    if (numEntered != -1.0) {
      sum = sum + numEntered;
      counter++;
    }
  } while (counter < 10 && numEntered != -1.0);
  printf("\nThe sum is %2.2lf and the avg is %2.2lf.\n\n", sum, sum / counter);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe89(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    118c <main+0x6c>
jp     118c <main+0x6c>
jmp    11a4 <main+0x84>
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a9 <main+0x89>
xor    %eax,%eax
cmpl   $0xa,-0x8(%rbp)
mov    %al,-0x19(%rbp)
jge    11d4 <main+0xb4>
movsd  -0x10(%rbp),%xmm0
movsd  0xe3b(%rip),%xmm1
ucomisd %xmm1,%xmm0
setne  %al
setp   %cl
or     %cl,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    114c <main+0x2c>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0xe3d(%rip),%rdi
mov    $0x2,%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    0xf0f(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm0,%xmm0
mov    $0x1,%ebp
lea    0xeba(%rip),%r14
lea    0xec3(%rip),%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movsd  0xe6d(%rip),%xmm3
movsd  0x10(%rsp),%xmm2
movapd %xmm2,%xmm1
cmpneqsd %xmm3,%xmm1
movq   %xmm1,%rax
sub    %eax,%ebp
ucomisd %xmm3,%xmm2
movapd %xmm2,%xmm1
jne    11c1 <main+0x91>
movapd %xmm2,%xmm1
jp     11c1 <main+0x91>
movsd  0xe47(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
cmp    $0x9,%ebp
ja     11d8 <main+0xa8>
ucomisd %xmm3,%xmm2
jne    1170 <main+0x40>
jp     1170 <main+0x40>
xorps  %xmm2,%xmm2
cvtsi2sd %ebp,%xmm2
movapd %xmm0,%xmm1
divsd  %xmm2,%xmm1
lea    0xe36(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"do-while Loop Example 3\0A\0A\00"
@.str.1 = [16 x i8] c"Enter a value: \00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [44 x i8] c"\0AThe sum is %2.2lf and the avg is %2.2lf.\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %4
store i32 1, i32* %2
br label %6
6: ; preds = %24, %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %3)
%9 = load double, double* %3
%10 = fcmp une double %9, -1.000000e+00
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load double, double* %4
%13 = load double, double* %3
%14 = fadd double %12, %13
store double %14, double* %4
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %17
17: ; preds = %11, %6
br label %18
18: ; preds = %17
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load double, double* %3
%23 = fcmp une double %22, -1.000000e+00
br label %24
24: ; preds = %21, %18
%25 = phi i1 [ false, %18 ], [ %23, %21 ]
br i1 %25, label %6, label %26
26: ; preds = %24
%27 = load double, double* %4
%28 = load double, double* %4
%29 = load i32, i32* %2
%30 = sitofp i32 %29 to double
%31 = fdiv double %28, %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), double %27, double %31)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"Enter a value: \00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [44 x i8] c"\0AThe sum is %2.2lf and the avg is %2.2lf.\0A\0A\00"
@str = [25 x i8] c"do-while Loop Example 3\0A\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = phi i32 [ 1, %0 ], [ %12, %4 ]
%6 = phi double [ 0.000000e+00, %0 ], [ %14, %4 ]
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%9 = load double, double* %1
%10 = fcmp une double %9, -1.000000e+00
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %5, %11
%13 = select i1 %10, double %9, double -0.000000e+00
%14 = fadd double %6, %13
%15 = icmp ult i32 %12, 10
%16 = select i1 %15, i1 %10, i1 false
br i1 %16, label %4, label %17
17: ; preds = %4
%18 = sitofp i32 %12 to double
%19 = fdiv double %14, %18
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), double %14, double %19)
ret i32 0
}