#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 *, int *);
int main(void) {
  int GallonsUsed, MilesDriven;
  float MilesPerGallon, OverallAverageMilesPerGallon, iTotGas, iTotMiles;
  iTotGas = 0;
  iTotMiles = 0;
  while (GallonsUsed != -1) {
    printf("Enter the gallons used ( -1 to end):\n");
    scanf("%d", &GallonsUsed);
    if (GallonsUsed != -1) {
      printf("Enter the miles driven:\n");
      scanf("%d", &MilesDriven);
      MilesPerGallon = (float)MilesDriven / GallonsUsed;
      iTotGas = iTotGas + GallonsUsed;
      iTotMiles = iTotMiles + MilesDriven;
    } else {
      printf("The overall average Miles/Gallon was %f\n",
             OverallAverageMilesPerGallon);
      break;
    }
    OverallAverageMilesPerGallon = iTotMiles / iTotGas;
    printf("The Miles / Gallon for this tank was %f\n", MilesPerGallon);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     1214 <main+0xf4>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0xffffffff,-0x8(%rbp)
je     11cd <main+0xad>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cvtsi2ssl -0xc(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x18(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11e9 <main+0xc9>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe65(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1214 <main+0xf4>
movss  -0x1c(%rbp),%xmm0
divss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe63(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    113f <main+0x1f>
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    0xf10(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rbx
lea    0x8(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
lea    0xf06(%rip),%r12
lea    0x14(%rsp),%r13
lea    0xeac(%rip),%rbp
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
xorps  %xmm0,%xmm0
cvtsi2ssl 0x14(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssl 0x8(%rsp),%xmm1
movss  %xmm0,0x10(%rsp)
movss  %xmm1,0xc(%rsp)
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmpl   $0xffffffff,0x8(%rsp)
je     1237 <main+0x107>
movss  0x4(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
movss  (%rsp),%xmm0
addss  0x10(%rsp),%xmm0
movss  %xmm0,(%rsp)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
cmpl   $0xffffffff,0x8(%rsp)
jne    1190 <main+0x60>
movss  (%rsp),%xmm0
divss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd3(%rip),%rdi
mov    $0x1,%al
call   1040 <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 = [38 x i8] c"Enter the gallons used ( -1 to end):\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"Enter the miles driven:\0A\00"
@.str.3 = [41 x i8] c"The overall average Miles/Gallon was %f\0A\00"
@.str.4 = [41 x i8] c"The Miles / Gallon for this tank was %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %6
store float 0.000000e+00, float* %7
br label %8
8: ; preds = %36, %0
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %43
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %32
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 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), i32* %3)
%19 = load i32, i32* %3
%20 = sitofp i32 %19 to float
%21 = load i32, i32* %2
%22 = sitofp i32 %21 to float
%23 = fdiv float %20, %22
store float %23, float* %4
%24 = load float, float* %6
%25 = load i32, i32* %2
%26 = sitofp i32 %25 to float
%27 = fadd float %24, %26
store float %27, float* %6
%28 = load float, float* %7
%29 = load i32, i32* %3
%30 = sitofp i32 %29 to float
%31 = fadd float %28, %30
store float %31, float* %7
br label %36
32: ; preds = %11
%33 = load float, float* %5
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), double %34)
br label %43
36: ; preds = %16
%37 = load float, float* %7
%38 = load float, float* %6
%39 = fdiv float %37, %38
store float %39, float* %5
%40 = load float, float* %4
%41 = fpext float %40 to double
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), double %41)
br label %8
43: ; preds = %32, %8
ret i32 0
}

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