#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 *, float *);
int main() {
  int counter = 0;
  float gallons, miles, avg_per_gallon, tot = 0;
  while (gallons != -1) {
    printf("Enter the gallons used (-1 to end):");
    scanf("%f", &gallons);
    if (gallons == -1) {
      break;
    }
    printf("Enter the miles driven:");
    scanf("%f", &miles);
    counter++;
    avg_per_gallon = miles / gallons;
    printf("The miles/gallon for this tank was %f\n\n", avg_per_gallon);
    tot += avg_per_gallon;
  }
  if (gallons == -1) {
    printf("The overall average miles/gallon %f", (float)tot / (counter));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xeb5(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    115f <main+0x3f>
jp     115f <main+0x3f>
jmp    11ff <main+0xdf>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf15(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0xc(%rbp),%xmm0
movss  0xe76(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    119e <main+0x7e>
jp     119e <main+0x7e>
jmp    11ff <main+0xdf>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movss  -0x10(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0x14(%rbp),%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    113e <main+0x1e>
movss  -0xc(%rbp),%xmm0
movss  0xdf4(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    123b <main+0x11b>
jp     123b <main+0x11b>
movss  -0x18(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe34(%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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xorps  %xmm1,%xmm1
lea    0xf51(%rip),%rbx
lea    0x8(%rsp),%r15
lea    0xee4(%rip),%r12
lea    0x14(%rsp),%r13
lea    0xef0(%rip),%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movss  %xmm1,0xc(%rsp)
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movss  0x8(%rsp),%xmm0
ucomiss 0xe74(%rip),%xmm0
jne    1190 <main+0x70>
jnp    11f0 <main+0xd0>
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <scanf@plt>
add    $0x1,%r14d
movss  0x14(%rsp),%xmm0
divss  0x8(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  0xc(%rsp),%xmm1
addss  0x10(%rsp),%xmm1
movss  0x8(%rsp),%xmm0
ucomiss 0xe1e(%rip),%xmm0
jne    1160 <main+0x40>
jp     1160 <main+0x40>
jmp    11f6 <main+0xd6>
movss  0xc(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe58(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Enter the gallons used (-1 to end):\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [24 x i8] c"Enter the miles driven:\00"
@.str.3 = [40 x i8] c"The miles/gallon for this tank was %f\0A\0A\00"
@.str.4 = [36 x i8] c"The overall average miles/gallon %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
store i32 0, i32* %2
store float 0.000000e+00, float* %6
br label %7
7: ; preds = %16, %0
%8 = load float, float* %3
%9 = fcmp une float %8, -1.000000e+00
br i1 %9, label %10, label %30
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%13 = load float, float* %3
%14 = fcmp oeq float %13, -1.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %10
br label %30
16: ; preds = %10
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
%21 = load float, float* %4
%22 = load float, float* %3
%23 = fdiv float %21, %22
store float %23, float* %5
%24 = load float, float* %5
%25 = fpext float %24 to double
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), double %25)
%27 = load float, float* %5
%28 = load float, float* %6
%29 = fadd float %28, %27
store float %29, float* %6
br label %7
30: ; preds = %15, %7
%31 = load float, float* %3
%32 = fcmp oeq float %31, -1.000000e+00
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load float, float* %6
%35 = load i32, i32* %2
%36 = sitofp i32 %35 to float
%37 = fdiv float %34, %36
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %38)
br label %40
40: ; preds = %33, %30
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Enter the gallons used (-1 to end):\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [24 x i8] c"Enter the miles driven:\00"
@.str.3 = [40 x i8] c"The miles/gallon for this tank was %f\0A\0A\00"
@.str.4 = [36 x i8] c"The overall average miles/gallon %f\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = bitcast float* %1 to i8*
%4 = bitcast float* %2 to i8*
br label %5
5: ; preds = %0, %12
%6 = phi float [ %21, %12 ], [ 0.000000e+00, %0 ]
%7 = phi i32 [ %15, %12 ], [ 0, %0 ]
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%10 = load float, float* %1
%11 = fcmp oeq float %10, -1.000000e+00
br i1 %11, label %24, label %12
12: ; preds = %5
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%15 = add nuw nsw i32 %7, 1
%16 = load float, float* %2
%17 = load float, float* %1
%18 = fdiv float %16, %17
%19 = fpext float %18 to double
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), double %19)
%21 = fadd float %6, %18
%22 = load float, float* %1
%23 = fcmp une float %22, -1.000000e+00
br i1 %23, label %5, label %24
24: ; preds = %12, %5
%25 = phi i32 [ %15, %12 ], [ %7, %5 ]
%26 = phi float [ %21, %12 ], [ %6, %5 ]
%27 = sitofp i32 %25 to float
%28 = fdiv float %26, %27
%29 = fpext float %28 to double
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %29)
ret i32 0
}