#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 *, char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main(void) {
  unsigned int counter = 0;
  float gallons = 0.0;
  float miles = 0.0;
  float milesPerGallon;
  float average = 0.0;
  printf("%s", "Enter the gallons used (-1 to end): ");
  scanf("%f", &gallons);
  while (gallons != -1) {
    printf("%s", "Enter the miles driven: ");
    scanf("%f", &miles);
    milesPerGallon = miles / gallons;
    printf("%s %f", "The miles/gallon for this tank was ", milesPerGallon);
    average = average + milesPerGallon;
    counter++;
    printf("%s", "\n\nEnter the gallons used (-1 to end): ");
    scanf("%f", &gallons);
  }
  if (counter != 0)
    printf("%s %f", "\n\nThe overall average miles/gallon was ",
           (average / counter));
  else
    printf("%s", "\n\nTough Luck....");
  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,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
lea    0xeaf(%rip),%rdi
lea    0xef0(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0xc(%rbp),%xmm0
movss  0xe80(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    1194 <main+0x74>
jp     1194 <main+0x74>
jmp    1228 <main+0x108>
lea    0xe69(%rip),%rdi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe73(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0x10(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe48(%rip),%rdi
lea    0xe47(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0x18(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    0xdff(%rip),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe09(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1173 <main+0x53>
cmpl   $0x0,-0x8(%rbp)
je     1261 <main+0x141>
movss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%eax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd2(%rip),%rdi
lea    0xe1c(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1276 <main+0x156>
lea    0xd9c(%rip),%rdi
lea    0xe2a(%rip),%rsi
mov    $0x0,%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
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xebf(%rip),%rdi
lea    0xf00(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
movss  0x8(%rsp),%xmm0
ucomiss 0xe8f(%rip),%xmm0
jne    1179 <main+0x59>
jnp    1277 <main+0x157>
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
lea    0xe7b(%rip),%r15
lea    0xe93(%rip),%rbx
lea    0xe8f(%rip),%rbp
lea    0xeac(%rip),%r14
lea    0x8(%rsp),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
lea    0xe4d(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
call   1040 <scanf@plt>
movss  0x10(%rsp),%xmm0
divss  0x8(%rsp),%xmm0
movss  %xmm0,0x14(%rsp)
cvtss2sd %xmm0,%xmm0
lea    0xe35(%rip),%rdi
mov    %rbp,%rsi
mov    $0x1,%al
call   1030 <printf@plt>
movss  0xc(%rsp),%xmm0
addss  0x14(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
movss  0x8(%rsp),%xmm0
add    $0xffffffff,%r13d
ucomiss 0xdd0(%rip),%xmm0
jne    11b0 <main+0x90>
jp     11b0 <main+0x90>
movss  0xc(%rsp),%xmm1
test   %r13d,%r13d
je     1277 <main+0x157>
neg    %r13d
mov    %r13d,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xdb9(%rip),%rdi
lea    0xe03(%rip),%rsi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    128c <main+0x16c>
lea    0xd86(%rip),%rdi
lea    0xe14(%rip),%rsi
xor    %eax,%eax
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 = [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"%f\00"
@.str.3 = [25 x i8] c"Enter the miles driven: \00"
@.str.4 = [6 x i8] c"%s %f\00"
@.str.5 = [36 x i8] c"The miles/gallon for this tank was \00"
@.str.6 = [39 x i8] c"\0A\0AEnter the gallons used (-1 to end): \00"
@.str.7 = [40 x i8] c"\0A\0AThe overall average miles/gallon was \00"
@.str.8 = [17 x i8] c"\0A\0ATough Luck....\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* %3
store float 0.000000e+00, float* %4
store float 0.000000e+00, float* %6
%7 = call i32 (i8*, 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))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %3)
br label %9
9: ; preds = %12, %0
%10 = load float, float* %3
%11 = fcmp une float %10, -1.000000e+00
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = call i32 (i8*, 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))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %4)
%15 = load float, float* %4
%16 = load float, float* %3
%17 = fdiv float %15, %16
store float %17, float* %5
%18 = load float, float* %5
%19 = fpext float %18 to double
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), double %19)
%21 = load float, float* %6
%22 = load float, float* %5
%23 = fadd float %21, %22
store float %23, float* %6
%24 = load i32, i32* %2
%25 = add i32 %24, 1
store i32 %25, i32* %2
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %3)
br label %9
28: ; preds = %9
%29 = load i32, i32* %2
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load float, float* %6
%33 = load i32, i32* %2
%34 = uitofp i32 %33 to float
%35 = fdiv float %32, %34
%36 = fpext float %35 to double
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), double %36)
br label %40
38: ; preds = %28
%39 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %40
40: ; preds = %38, %31
ret i32 0
}

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