#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 */
float getPrice(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int productNumber, quantitySold;
  float price;
  float totalSales = 0.0;
  do {
    printf("Enter the product number (or -1 to exit): ");
    scanf("%d", &productNumber);
    if (productNumber != -1)
      price = getPrice(productNumber);
    else
      price = -1;
    if ((int)price != -1) {
      printf("Enter number of items sold: ");
      scanf("%d", &quantitySold);
      if (quantitySold > 0)
        totalSales += (price * quantitySold);
    }
  } while (productNumber != -1);
  printf("\nThe total retail value of all products sold\n");
  printf("last week was $%.2f\n ", totalSales);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0xffffffff,-0x8(%rbp)
je     1181 <main+0x51>
mov    -0x8(%rbp),%edi
call   1050 <getPrice@plt>
movss  %xmm0,-0x10(%rbp)
jmp    118e <main+0x5e>
movss  0xe77(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
cvttss2si -0x10(%rbp),%eax
cmp    $0xffffffff,%eax
je     11e5 <main+0xb5>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7e(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11e0 <main+0xb0>
movss  -0x10(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm2
movss  -0x14(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    11e5 <main+0xb5>
jmp    11ea <main+0xba>
cmpl   $0xffffffff,-0x8(%rbp)
jne    1147 <main+0x17>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6b(%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   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
lea    0xea8(%rip),%r14
lea    0xecc(%rip),%rbx
lea    0x4(%rsp),%r15
lea    0xec3(%rip),%r12
lea    0xc(%rsp),%r13
jmp    1187 <main+0x47>
cs nopw 0x0(%rax,%rax,1)
cmpl   $0xffffffff,0x4(%rsp)
je     11ff <main+0xbf>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
movss  0xe58(%rip),%xmm0
cmp    $0xffffffff,%edi
je     11b2 <main+0x72>
call   1060 <getPrice@plt>
cvttss2si %xmm0,%eax
cmp    $0xffffffff,%eax
je     1180 <main+0x40>
movss  %xmm0,0x8(%rsp)
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1180 <main+0x40>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  (%rsp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rsp)
jmp    1180 <main+0x40>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
movss  (%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe34(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Enter the product number (or -1 to exit): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Enter number of items sold: \00"
@.str.3 = [46 x i8] c"\0AThe total retail value of all products sold\0A\00"
@.str.4 = [22 x i8] c"last week was $%.2f\0A \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %5
br label %6
6: ; preds = %32, %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i32, i32* %2
%13 = call float @getPrice(i32 %12)
store float %13, float* %4
br label %15
14: ; preds = %6
store float -1.000000e+00, float* %4
br label %15
15: ; preds = %14, %11
%16 = load float, float* %4
%17 = fptosi float %16 to i32
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load float, float* %4
%26 = load i32, i32* %3
%27 = sitofp i32 %26 to float
%28 = load float, float* %5
%29 = call float @llvm.fmuladd.f32(float %25, float %27, float %28)
store float %29, float* %5
br label %30
30: ; preds = %24, %19
br label %31
31: ; preds = %30, %15
br label %32
32: ; preds = %31
%33 = load i32, i32* %2
%34 = icmp ne i32 %33, -1
br i1 %34, label %6, label %35
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%37 = load float, float* %5
%38 = fpext float %37 to double
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"Enter the product number (or -1 to exit): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Enter number of items sold: \00"
@.str.4 = [22 x i8] c"last week was $%.2f\0A \00"
@str = [45 x i8] c"\0AThe total retail value of all products sold\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %25, %0
%6 = phi float [ 0.000000e+00, %0 ], [ %26, %25 ]
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, -1
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = call float @getPrice(i32 %9)
br label %13
13: ; preds = %5, %11
%14 = phi float [ %12, %11 ], [ -1.000000e+00, %5 ]
%15 = fptosi float %14 to i32
%16 = icmp eq i32 %15, -1
br i1 %16, label %25, label %17
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%20 = load i32, i32* %2
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = sitofp i32 %20 to float
%24 = call float @llvm.fmuladd.f32(float %14, float %23, float %6)
br label %25
25: ; preds = %13, %22, %17
%26 = phi float [ %24, %22 ], [ %6, %17 ], [ %6, %13 ]
%27 = load i32, i32* %1
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %5
29: ; preds = %25
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%31 = fpext float %26 to double
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %31)
ret i32 0
}