#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 argc, const char *argv[]) {
  int i = 0;
  double value, total;
  printf("This program averages a list of integers.\n");
  printf("Enter -1 to signal the end of the list\n");
  total = 0;
  while (1) {
    printf(" ? ");
    scanf("%lf", &value);
    if (value == -1)
      break;
    total += value;
    i++;
  }
  printf("The total is %g\n", total / (i * 1.0));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  0xe74(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11a1 <main+0x81>
jp     11a1 <main+0x81>
jmp    11be <main+0x9e>
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <main+0x41>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe38(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
lea    0xe8c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xf06(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
movsd  0x8(%rsp),%xmm1
ucomisd 0xe89(%rip),%xmm1
jne    118d <main+0x5d>
jp     118d <main+0x5d>
movsd  0xe75(%rip),%xmm0
jmp    11f5 <main+0xc5>
xorpd  %xmm0,%xmm0
lea    0xe78(%rip),%r14
lea    0xe75(%rip),%r15
lea    0x8(%rsp),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
add    $0x1,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd 0xe22(%rip),%xmm1
jne    11b0 <main+0x80>
jp     11b0 <main+0x80>
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
lea    0xe1c(%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 = [43 x i8] c"This program averages a list of integers.\0A\00"
@.str.1 = [40 x i8] c"Enter -1 to signal the end of the list\0A\00"
@.str.2 = [4 x i8] c" ? \00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [17 x i8] c"The total is %g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store double 0.000000e+00, double* %8
br label %11
11: ; preds = %2, %17
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %7)
%14 = load double, double* %7
%15 = fcmp oeq double %14, -1.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %11
br label %23
17: ; preds = %11
%18 = load double, double* %7
%19 = load double, double* %8
%20 = fadd double %19, %18
store double %20, double* %8
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %11
23: ; preds = %16
%24 = load double, double* %8
%25 = load i32, i32* %6
%26 = sitofp i32 %25 to double
%27 = fmul double %26, 1.000000e+00
%28 = fdiv double %24, %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), double %28)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c" ? \00"
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [17 x i8] c"The total is %g\0A\00"
@str = [42 x i8] c"This program averages a list of integers.\00"
@str.5 = [39 x i8] c"Enter -1 to signal the end of the list\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.5, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %3)
%9 = load double, double* %3
%10 = fcmp oeq double %9, -1.000000e+00
br i1 %10, label %24, label %11
11: ; preds = %2, %11
%12 = phi double [ %19, %11 ], [ %9, %2 ]
%13 = phi double [ %15, %11 ], [ 0.000000e+00, %2 ]
%14 = phi i32 [ %16, %11 ], [ 0, %2 ]
%15 = fadd double %13, %12
%16 = add nuw nsw i32 %14, 1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %3)
%19 = load double, double* %3
%20 = fcmp oeq double %19, -1.000000e+00
br i1 %20, label %21, label %11
21: ; preds = %11
%22 = sitofp i32 %16 to double
%23 = fdiv double %15, %22
br label %24
24: ; preds = %21, %2
%25 = phi double [ %23, %21 ], [ 0x7FF8000000000000, %2 ]
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), double %25)
ret i32 0
}