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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cvttss2si -0x10(%rbp),%eax
cmp    $0xffffffff,%eax
je     1219 <main+0xf9>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea5(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0x10(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x14(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11c3 <main+0xa3>
jp     11c3 <main+0xa3>
jmp    11d7 <main+0xb7>
movss  -0x14(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    11df <main+0xbf>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe52(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe1a(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
jmp    115d <main+0x3d>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1235 <main+0x115>
jp     1235 <main+0x115>
jmp    1249 <main+0x129>
movss  -0xc(%rbp),%xmm0
divss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1251 <main+0x131>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe0a(%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
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee6(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
cvttss2si 0x8(%rsp),%eax
xorps  %xmm0,%xmm0
cmp    $0xffffffff,%eax
je     124d <main+0x12d>
lea    0xec6(%rip),%r14
lea    0xebc(%rip),%rbx
lea    0x14(%rsp),%r15
lea    0xecc(%rip),%r12
lea    0xe84(%rip),%r13
lea    0x8(%rsp),%rbp
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
jmp    11f1 <main+0xd1>
nopl   0x0(%rax)
movss  0x10(%rsp),%xmm3
addss  %xmm1,%xmm3
movss  %xmm3,0x10(%rsp)
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
mov    %r12,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <scanf@plt>
cvttss2si 0x8(%rsp),%eax
cmp    $0xffffffff,%eax
je     122c <main+0x10c>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movss  0x8(%rsp),%xmm1
movss  0x14(%rsp),%xmm0
ucomiss 0xde7(%rip),%xmm1
xorps  %xmm2,%xmm2
jne    1220 <main+0x100>
jnp    11a0 <main+0x80>
movaps %xmm0,%xmm2
divss  %xmm1,%xmm2
jmp    11a0 <main+0x80>
xorps  %xmm0,%xmm0
movss  0x10(%rsp),%xmm1
ucomiss %xmm0,%xmm1
xorps  %xmm0,%xmm0
jne    123f <main+0x11f>
jnp    124d <main+0x12d>
movss  0xc(%rsp),%xmm0
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe1b(%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 = [37 x i8] c"Enter the gallons used (-1 to end): \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [25 x i8] c"Enter the miles driven: \00"
@.str.3 = [42 x i8] c"The miles / gallon for this tank was %f\0A\0A\00"
@.str.4 = [38 x i8] c"\0AThe overall miles per gallon was %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %2
store float 0.000000e+00, float* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
br label %9
9: ; preds = %29, %0
%10 = load float, float* %4
%11 = fptosi float %10 to i32
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %5)
%16 = load float, float* %4
%17 = load float, float* %2
%18 = fadd float %17, %16
store float %18, float* %2
%19 = load float, float* %5
%20 = load float, float* %3
%21 = fadd float %20, %19
store float %21, float* %3
%22 = load float, float* %4
%23 = fcmp une float %22, 0.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %13
%25 = load float, float* %5
%26 = load float, float* %4
%27 = fdiv float %25, %26
store float %27, float* %6
br label %29
28: ; preds = %13
store float 0.000000e+00, float* %6
br label %29
29: ; preds = %28, %24
%30 = load float, float* %6
%31 = fpext float %30 to double
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), double %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
br label %9
35: ; preds = %9
%36 = load float, float* %2
%37 = fcmp une float %36, 0.000000e+00
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load float, float* %3
%40 = load float, float* %2
%41 = fdiv float %39, %40
store float %41, float* %6
br label %43
42: ; preds = %35
store float 0.000000e+00, float* %6
br label %43
43: ; preds = %42, %38
%44 = load float, float* %6
%45 = fpext float %44 to double
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), double %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Enter the gallons used (-1 to end): \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [25 x i8] c"Enter the miles driven: \00"
@.str.3 = [42 x i8] c"The miles / gallon for this tank was %f\0A\0A\00"
@.str.4 = [38 x i8] c"\0AThe overall miles per gallon was %f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = bitcast float* %1 to i8*
%4 = bitcast float* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%7 = load float, float* %1
%8 = fptosi float %7 to i32
%9 = icmp eq i32 %8, -1
br i1 %9, label %34, label %10
10: ; preds = %0, %10
%11 = phi float [ %18, %10 ], [ 0.000000e+00, %0 ]
%12 = phi float [ %16, %10 ], [ 0.000000e+00, %0 ]
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 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 = load float, float* %1
%16 = fadd float %12, %15
%17 = load float, float* %2
%18 = fadd float %11, %17
%19 = fcmp une float %15, 0.000000e+00
%20 = fdiv float %17, %15
%21 = select i1 %19, float %20, float 0.000000e+00
%22 = fpext float %21 to double
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), double %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%26 = load float, float* %1
%27 = fptosi float %26 to i32
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %10
29: ; preds = %10
%30 = fcmp une float %16, 0.000000e+00
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = fdiv float %18, %16
%33 = fpext float %32 to double
br label %34
34: ; preds = %0, %29, %31
%35 = phi double [ %33, %31 ], [ 0.000000e+00, %29 ], [ 0.000000e+00, %0 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), double %35)
ret i32 0
}