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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
je     11d9 <main+0xb9>
lea    0xeab(%rip),%rdi
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0xffffffff,-0x10(%rbp)
je     11d4 <main+0xb4>
lea    0xe7c(%rip),%rdi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cvtsi2ssl -0x8(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe89(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <main+0x24>
cvtsi2ssl -0xc(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe7a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,(%rsp)
lea    0xec7(%rip),%r15
lea    0xee8(%rip),%rbx
mov    %rsp,%r12
lea    0xefa(%rip),%r14
xor    %r13d,%r13d
xor    %ebp,%ebp
nop
mov    %r15,%rdi
lea    0xea9(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
cmpl   $0xffffffff,(%rsp)
je     11c2 <main+0xa2>
mov    %r15,%rdi
lea    0xeaf(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
xorps  %xmm0,%xmm0
cvtsi2ssl 0x4(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssl (%rsp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    0x4(%rsp),%ebp
mov    (%rsp),%eax
add    %eax,%r13d
cmp    $0xffffffff,%eax
jne    1150 <main+0x30>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %r13d,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe8c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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