#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 */
double calculate(double);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int inputYOrN(int /*<<< orphan*/);
int /*<<< orphan*/ lineBreak();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sscanf(char *, char *, double *);
int /*<<< orphan*/ stdin;
void electricBill(void) {
  int cont;
  puts("Electric Bill Calculator");
  lineBreak();
  cont = inputYOrN(0);
  while (cont) {
    double bill, pm, cm, units;
    char buffer_a[20], buffer_b[20];
    lineBreak();
    printf("Enter your previous month reading: ");
    fgets(buffer_a, 15, stdin);
    sscanf(buffer_a, "%lf", &pm);
    puts(" ");
    printf("Enter your current month reading:  ");
    fgets(buffer_b, 15, stdin);
    sscanf(buffer_b, "%lf", &cm);
    puts(" ");
    units = cm - pm;
    if (units < 0) {
      printf("Invalid inputs. Try again.\n");
    } else {
      printf("Total units consumed: %.2f\n", units);
      bill = calculate(units);
      printf("Total Bill = $%.2f\n", bill);
    }
    cont = inputYOrN(0);
  }
}


x86 assembly (clang, -O0):
<electricBill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1070 <lineBreak@plt>
xor    %edi,%edi
call   1030 <inputYOrN@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     12a4 <electricBill+0x134>
mov    $0x0,%al
call   1070 <lineBreak@plt>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
mov    $0xf,%esi
call   1080 <fgets@plt>
lea    -0x40(%rbp),%rdi
lea    0xe67(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1090 <sscanf@plt>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    $0xf,%esi
call   1080 <fgets@plt>
lea    -0x60(%rbp),%rdi
lea    0xe22(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1090 <sscanf@plt>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1260 <electricBill+0xf0>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1295 <electricBill+0x125>
movsd  -0x28(%rbp),%xmm0
lea    0xe15(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x28(%rbp),%xmm0
call   1060 <calculate@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe0f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1030 <inputYOrN@plt>
mov    %eax,-0x4(%rbp)
jmp    1195 <electricBill+0x25>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<electricBill>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <lineBreak@plt>
xor    %edi,%edi
call   1030 <inputYOrN@plt>
test   %eax,%eax
je     12ac <electricBill+0x13c>
mov    0x2e41(%rip),%rbp
lea    0x40(%rsp),%r15
lea    0xe92(%rip),%r13
lea    0xeb1(%rip),%rbx
lea    0x20(%rsp),%r14
lea    0x10(%rsp),%r12
jmp    1210 <electricBill+0xa0>
cs nopw 0x0(%rax,%rax,1)
lea    0xe96(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
movsd  %xmm1,0x8(%rsp)
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1060 <calculate@plt>
lea    0xe8f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1030 <inputYOrN@plt>
test   %eax,%eax
je     12ac <electricBill+0x13c>
xor    %eax,%eax
call   1070 <lineBreak@plt>
lea    0xe03(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r15,%rdi
mov    $0xf,%esi
call   1080 <fgets@plt>
mov    %r15,%rdi
mov    %r13,%rsi
lea    0x18(%rsp),%rdx
call   1090 <sscanf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r14,%rdi
mov    $0xf,%esi
call   1080 <fgets@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1090 <sscanf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
movsd  0x10(%rsp),%xmm1
subsd  0x18(%rsp),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11d0 <electricBill+0x60>
lea    0xdfb(%rip),%rdi
call   1040 <puts@plt>
jmp    1201 <electricBill+0x91>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Electric Bill Calculator\00"
@.str.1 = [36 x i8] c"Enter your previous month reading: \00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [36 x i8] c"Enter your current month reading: \00"
@.str.5 = [28 x i8] c"Invalid inputs. Try again.\0A\00"
@.str.6 = [28 x i8] c"Total units consumed: %.2f\0A\00"
@.str.7 = [20 x i8] c"Total Bill = $%.2f\0A\00"
define void @electricBill() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @lineBreak()
%10 = call i32 @inputYOrN(i32 0)
store i32 %10, i32* %1
br label %11
11: ; preds = %44, %0
%12 = load i32, i32* %1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %46
14: ; preds = %11
%15 = call i32 (...) @lineBreak()
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 15, i32 %18)
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %3)
%22 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %24, i32 15, i32 %25)
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %4)
%29 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = load double, double* %4
%31 = load double, double* %3
%32 = fsub double %30, %31
store double %32, double* %5
%33 = load double, double* %5
%34 = fcmp olt double %33, 0.000000e+00
br i1 %34, label %35, label %37
35: ; preds = %14
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %44
37: ; preds = %14
%38 = load double, double* %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), double %38)
%40 = load double, double* %5
%41 = call double @calculate(double %40)
store double %41, double* %2
%42 = load double, double* %2
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), double %42)
br label %44
44: ; preds = %37, %35
%45 = call i32 @inputYOrN(i32 0)
store i32 %45, i32* %1
br label %11
46: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Electric Bill Calculator\00"
@.str.1 = [36 x i8] c"Enter your previous month reading: \00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [36 x i8] c"Enter your current month reading: \00"
@.str.6 = [28 x i8] c"Total units consumed: %.2f\0A\00"
@.str.7 = [20 x i8] c"Total Bill = $%.2f\0A\00"
@str = [27 x i8] c"Invalid inputs. Try again.\00"
define void @electricBill() {
%1 = alloca double
%2 = alloca double
%3 = alloca [20 x i8]
%4 = alloca [20 x i8]
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (...) @lineBreak()
%7 = tail call i32 @inputYOrN(i32 0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %39, label %9
9: ; preds = %0
%10 = bitcast double* %1 to i8*
%11 = bitcast double* %2 to i8*
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
br label %14
14: ; preds = %9, %36
%15 = call i32 (...) @lineBreak()
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %12, i32 15, i32 %17)
%19 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* %13, i32 15, i32 %22)
%24 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %2)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = load double, double* %2
%27 = load double, double* %1
%28 = fsub double %26, %27
%29 = fcmp olt double %28, 0.000000e+00
br i1 %29, label %30, label %32
30: ; preds = %14
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %36
32: ; preds = %14
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), double %28)
%34 = call double @calculate(double %28)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), double %34)
br label %36
36: ; preds = %32, %30
%37 = call i32 @inputYOrN(i32 0)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %14
39: ; preds = %36, %0
ret void
}