#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)
      break;
    sum = sum + numEntered;
    counter++;
  } while (counter < 10);
  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    11ae <main+0x8e>
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jl     114c <main+0x2c>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0xe6e(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xf5d(%rip),%rdi
call   1030 <puts@plt>
lea    0xf11(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf13(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd 0xe97(%rip),%xmm1
jne    1182 <main+0x52>
jp     1182 <main+0x52>
movsd  0xe83(%rip),%xmm2
jmp    1428 <main+0x2f8>
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0xe4f(%rip),%xmm0
jne    11d0 <main+0xa0>
jp     11d0 <main+0xa0>
movsd  0xe4b(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
jmp    1428 <main+0x2f8>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe73(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0xdfb(%rip),%xmm0
jne    1224 <main+0xf4>
jp     1224 <main+0xf4>
movsd  0xdff(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
jmp    1428 <main+0x2f8>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe1f(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0xda7(%rip),%xmm0
jne    1278 <main+0x148>
jp     1278 <main+0x148>
movsd  0xdb3(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
jmp    1428 <main+0x2f8>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdcb(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0xd53(%rip),%xmm0
jne    12cc <main+0x19c>
jp     12cc <main+0x19c>
movsd  0xd67(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
jmp    1428 <main+0x2f8>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xd75(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd77(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0xcff(%rip),%xmm0
jne    1320 <main+0x1f0>
jp     1320 <main+0x1f0>
movsd  0xd1b(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
jmp    1428 <main+0x2f8>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xd21(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd23(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0xcab(%rip),%xmm0
jne    1374 <main+0x244>
jp     1374 <main+0x244>
movsd  0xccf(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
jmp    1428 <main+0x2f8>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xccd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xccf(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0xc57(%rip),%xmm0
jne    13c5 <main+0x295>
jp     13c5 <main+0x295>
movsd  0xc83(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
jmp    1428 <main+0x2f8>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xc7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc7e(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm1
ucomisd 0xc06(%rip),%xmm1
jne    1416 <main+0x2e6>
jp     1416 <main+0x2e6>
movsd  0xc3a(%rip),%xmm2
movsd  0x8(%rsp),%xmm0
jmp    1428 <main+0x2f8>
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xc28(%rip),%xmm2
movapd %xmm0,%xmm1
divsd  %xmm2,%xmm1
lea    0xc35(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
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 = %18, %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 oeq double %9, -1.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %6
br label %21
12: ; preds = %6
%13 = load double, double* %4
%14 = load double, double* %3
%15 = fadd double %13, %14
store double %15, double* %4
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %18
18: ; preds = %12
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 10
br i1 %20, label %6, label %21
21: ; preds = %18, %11
%22 = load double, double* %4
%23 = load double, double* %4
%24 = load i32, i32* %2
%25 = sitofp i32 %24 to double
%26 = fdiv double %23, %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), double %22, double %26)
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))
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%6 = load double, double* %1
%7 = fcmp oeq double %6, -1.000000e+00
br i1 %7, label %58, label %8
8: ; preds = %0
%9 = fadd double %6, 0.000000e+00
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%12 = load double, double* %1
%13 = fcmp oeq double %12, -1.000000e+00
br i1 %13, label %58, label %14
14: ; preds = %8
%15 = fadd double %9, %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%18 = load double, double* %1
%19 = fcmp oeq double %18, -1.000000e+00
br i1 %19, label %58, label %20
20: ; preds = %14
%21 = fadd double %15, %18
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%24 = load double, double* %1
%25 = fcmp oeq double %24, -1.000000e+00
br i1 %25, label %58, label %26
26: ; preds = %20
%27 = fadd double %21, %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%30 = load double, double* %1
%31 = fcmp oeq double %30, -1.000000e+00
br i1 %31, label %58, label %32
32: ; preds = %26
%33 = fadd double %27, %30
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%36 = load double, double* %1
%37 = fcmp oeq double %36, -1.000000e+00
br i1 %37, label %58, label %38
38: ; preds = %32
%39 = fadd double %33, %36
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%42 = load double, double* %1
%43 = fcmp oeq double %42, -1.000000e+00
br i1 %43, label %58, label %44
44: ; preds = %38
%45 = fadd double %39, %42
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%48 = load double, double* %1
%49 = fcmp oeq double %48, -1.000000e+00
br i1 %49, label %58, label %50
50: ; preds = %44
%51 = fadd double %45, %48
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%54 = load double, double* %1
%55 = fcmp oeq double %54, -1.000000e+00
br i1 %55, label %58, label %56
56: ; preds = %50
%57 = fadd double %51, %54
br label %58
58: ; preds = %56, %50, %44, %38, %32, %26, %20, %14, %8, %0
%59 = phi double [ 1.000000e+00, %0 ], [ 2.000000e+00, %8 ], [ 3.000000e+00, %14 ], [ 4.000000e+00, %20 ], [ 5.000000e+00, %26 ], [ 6.000000e+00, %32 ], [ 7.000000e+00, %38 ], [ 8.000000e+00, %44 ], [ 9.000000e+00, %50 ], [ 1.000000e+01, %56 ]
%60 = phi double [ 0.000000e+00, %0 ], [ %9, %8 ], [ %15, %14 ], [ %21, %20 ], [ %27, %26 ], [ %33, %32 ], [ %39, %38 ], [ %45, %44 ], [ %51, %50 ], [ %57, %56 ]
%61 = fdiv double %60, %59
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), double %60, double %61)
ret i32 0
}