#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 quantity, product_number = 0;
  double total_retail = 0;
  printf("Enters pairs of product number and quantity\n");
  printf("Enter -1 to exit");
  scanf("%d", &product_number);
  while (product_number != -1) {
    scanf("%d", &quantity);
    switch (product_number) {
    case 1:
      total_retail = total_retail + quantity * 2.98;
      break;
    case 2:
      total_retail = total_retail + quantity * 4.50;
      break;
    case 3:
      total_retail = total_retail + quantity * 9.98;
      break;
    case 4:
      total_retail = total_retail + quantity * 4.49;
      break;
    case 5:
      total_retail = total_retail + quantity * 6.87;
      break;
    }
    scanf("%d", &product_number);
  }
  printf("Total retail is : %.2f", total_retail);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xef7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf19(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0xffffffff,-0xc(%rbp)
je     1271 <main+0x151>
lea    0xeff(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     125c <main+0x13c>
mov    -0x20(%rbp),%rax
lea    0xe84(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe61(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    125c <main+0x13c>
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe35(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    125c <main+0x13c>
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe09(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    125c <main+0x13c>
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xddd(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    125c <main+0x13c>
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xdb1(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xe17(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
jmp    116a <main+0x4a>
movsd  -0x18(%rbp),%xmm0
lea    0xe00(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xee6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee9(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0xffffffff,0x10(%rsp)
je     1241 <main+0x111>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xec3(%rip),%rbx
lea    0x14(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe8d(%rip),%r12
jmp    11d2 <main+0xa2>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
mulsd  0xe52(%rip),%xmm0
xchg   %ax,%ax
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
cmpl   $0xffffffff,0x10(%rsp)
je     124b <main+0x11b>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
mov    0x10(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     11c0 <main+0x90>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
mulsd  0xe1d(%rip),%xmm0
jmp    11b0 <main+0x80>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
mulsd  0xe02(%rip),%xmm0
jmp    11b0 <main+0x80>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
mulsd  0xde7(%rip),%xmm0
jmp    11b0 <main+0x80>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
mulsd  0xdcc(%rip),%xmm0
jmp    11b0 <main+0x80>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xdfe(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Enters pairs of product number and quantity\0A\00"
@.str.1 = [17 x i8] c"Enter -1 to exit\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"Total retail is : %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
store i32 0, i32* %1
store i32 0, i32* %3
store double 0.000000e+00, double* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
br label %8
8: ; preds = %39, %0
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %41
11: ; preds = %8
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %3
switch i32 %13, label %39 [
i32 1, label %14
i32 2, label %19
i32 3, label %24
i32 4, label %29
i32 5, label %34
]
14: ; preds = %11
%15 = load double, double* %4
%16 = load i32, i32* %2
%17 = sitofp i32 %16 to double
%18 = call double @llvm.fmuladd.f64(double %17, double 2.980000e+00, double %15)
store double %18, double* %4
br label %39
19: ; preds = %11
%20 = load double, double* %4
%21 = load i32, i32* %2
%22 = sitofp i32 %21 to double
%23 = call double @llvm.fmuladd.f64(double %22, double 4.500000e+00, double %20)
store double %23, double* %4
br label %39
24: ; preds = %11
%25 = load double, double* %4
%26 = load i32, i32* %2
%27 = sitofp i32 %26 to double
%28 = call double @llvm.fmuladd.f64(double %27, double 9.980000e+00, double %25)
store double %28, double* %4
br label %39
29: ; preds = %11
%30 = load double, double* %4
%31 = load i32, i32* %2
%32 = sitofp i32 %31 to double
%33 = call double @llvm.fmuladd.f64(double %32, double 4.490000e+00, double %30)
store double %33, double* %4
br label %39
34: ; preds = %11
%35 = load double, double* %4
%36 = load i32, i32* %2
%37 = sitofp i32 %36 to double
%38 = call double @llvm.fmuladd.f64(double %37, double 6.870000e+00, double %35)
store double %38, double* %4
br label %39
39: ; preds = %11, %34, %29, %24, %19, %14
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
br label %8
41: ; preds = %8
%42 = load double, double* %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %42)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Enter -1 to exit\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"Total retail is : %.2f\00"
@str = [44 x i8] c"Enters pairs of product number and quantity\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
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %39, label %10
10: ; preds = %0, %34
%11 = phi double [ %35, %34 ], [ 0.000000e+00, %0 ]
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %2
switch i32 %13, label %34 [
i32 1, label %14
i32 2, label %18
i32 3, label %22
i32 4, label %26
i32 5, label %30
]
14: ; preds = %10
%15 = load i32, i32* %1
%16 = sitofp i32 %15 to double
%17 = call double @llvm.fmuladd.f64(double %16, double 2.980000e+00, double %11)
br label %34
18: ; preds = %10
%19 = load i32, i32* %1
%20 = sitofp i32 %19 to double
%21 = call double @llvm.fmuladd.f64(double %20, double 4.500000e+00, double %11)
br label %34
22: ; preds = %10
%23 = load i32, i32* %1
%24 = sitofp i32 %23 to double
%25 = call double @llvm.fmuladd.f64(double %24, double 9.980000e+00, double %11)
br label %34
26: ; preds = %10
%27 = load i32, i32* %1
%28 = sitofp i32 %27 to double
%29 = call double @llvm.fmuladd.f64(double %28, double 4.490000e+00, double %11)
br label %34
30: ; preds = %10
%31 = load i32, i32* %1
%32 = sitofp i32 %31 to double
%33 = call double @llvm.fmuladd.f64(double %32, double 6.870000e+00, double %11)
br label %34
34: ; preds = %10, %30, %26, %22, %18, %14
%35 = phi double [ %11, %10 ], [ %33, %30 ], [ %29, %26 ], [ %25, %22 ], [ %21, %18 ], [ %17, %14 ]
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%37 = load i32, i32* %2
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %10
39: ; preds = %34, %0
%40 = phi double [ 0.000000e+00, %0 ], [ %35, %34 ]
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), double %40)
ret i32 0
}