#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 main() {
  int menuSelection;
  double currencyRate = 1.0;
  printf("Your shopping assistant\n");
  do {
    printf("\n1. Set exchange rate in SEK (current rate: %.2f)", currencyRate);
    printf("\n2. Read prices in the foreign currency");
    printf("\n3. End\n");
    printf("\nGive your choice (1 - 3): ");
    scanf("%d", &menuSelection);
    printf("\n");
    if (menuSelection == 1) {
      printf("Give exchange rate: ");
      scanf("%lf", &currencyRate);
    } else if (menuSelection == 2) {
      double priceSum = 0;
      double price;
      do {
        printf("Give price (finish with < 0): ");
        scanf("%lf", &price);
        if (price >= 0) {
          priceSum = priceSum + price;
        } else {
          printf("\nSum in foreign currency: %.2f", priceSum);
          printf("\nSum in SEK: %.2f\n", (priceSum * currencyRate));
        }
      } while (price >= 0);
    } else if (menuSelection == 3) {
      printf("End of program!\n\n");
    } else {
      printf("Not a valid choice!\n");
    }
  } while (menuSelection != 3);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xecb(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf12(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xf7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11d6 <main+0xb6>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef2(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    12aa <main+0x18a>
cmpl   $0x2,-0x8(%rbp)
jne    1275 <main+0x155>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     122e <main+0x10e>
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1259 <main+0x139>
movsd  -0x18(%rbp),%xmm0
lea    0xea1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0xea8(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    125e <main+0x13e>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    11e8 <main+0xc8>
jmp    12a5 <main+0x185>
cmpl   $0x3,-0x8(%rbp)
jne    1292 <main+0x172>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a0 <main+0x180>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a5 <main+0x185>
jmp    12aa <main+0x18a>
jmp    12af <main+0x18f>
cmpl   $0x3,-0x8(%rbp)
jne    114a <main+0x2a>
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
sub    $0x28,%rsp
movabs $0x3ff0000000000000,%rax
mov    %rax,0x18(%rsp)
lea    0xf8f(%rip),%rdi
call   1040 <puts@plt>
movsd  0xe8f(%rip),%xmm0
lea    0xc(%rsp),%rbp
lea    0xf25(%rip),%r14
lea    0xf1a(%rip),%r15
lea    0x20(%rsp),%r12
lea    0xf31(%rip),%r13
lea    0xf49(%rip),%rbx
nopw   0x0(%rax,%rax,1)
lea    0xe69(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf48(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea9(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%eax
cmp    $0x3,%eax
je     12c0 <main+0x180>
cmp    $0x2,%eax
je     1230 <main+0xf0>
cmp    $0x1,%eax
jne    12d0 <main+0x190>
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
jmp    12dc <main+0x19c>
xchg   %ax,%ax
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
jmp    1276 <main+0x136>
nopl   0x0(%rax)
mov    %r13,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x18(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xorpd  %xmm1,%xmm1
movsd  0x20(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jb     12dc <main+0x19c>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movsd  0x20(%rsp),%xmm0
ucomisd 0xd6d(%rip),%xmm0
xorpd  %xmm1,%xmm1
jb     1240 <main+0x100>
movsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
jmp    1270 <main+0x130>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe60(%rip),%rdi
jmp    12d7 <main+0x197>
nopl   0x0(%rax)
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x3,0xc(%rsp)
je     12ee <main+0x1ae>
movsd  0x18(%rsp),%xmm0
jmp    11a0 <main+0x60>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Your shopping assistant\0A\00"
@.str.1 = [50 x i8] c"\0A1. Set exchange rate in SEK (current rate: %.2f)\00"
@.str.2 = [40 x i8] c"\0A2. Read prices in the foreign currency\00"
@.str.3 = [9 x i8] c"\0A3. End\0A\00"
@.str.4 = [28 x i8] c"\0AGive your choice (1 - 3): \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [21 x i8] c"Give exchange rate: \00"
@.str.8 = [4 x i8] c"%lf\00"
@.str.9 = [31 x i8] c"Give price (finish with < 0): \00"
@.str.10 = [31 x i8] c"\0ASum in foreign currency: %.2f\00"
@.str.11 = [19 x i8] c"\0ASum in SEK: %.2f\0A\00"
@.str.12 = [18 x i8] c"End of program!\0A\0A\00"
@.str.13 = [21 x i8] c"Not a valid choice!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
store double 1.000000e+00, double* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %55, %0
%8 = load double, double* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), double %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %7
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double* %3)
br label %54
20: ; preds = %7
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %45
23: ; preds = %20
store double 0.000000e+00, double* %4
br label %24
24: ; preds = %41, %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double* %5)
%27 = load double, double* %5
%28 = fcmp oge double %27, 0.000000e+00
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load double, double* %4
%31 = load double, double* %5
%32 = fadd double %30, %31
store double %32, double* %4
br label %40
33: ; preds = %24
%34 = load double, double* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), double %34)
%36 = load double, double* %4
%37 = load double, double* %3
%38 = fmul double %36, %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), double %38)
br label %40
40: ; preds = %33, %29
br label %41
41: ; preds = %40
%42 = load double, double* %5
%43 = fcmp oge double %42, 0.000000e+00
br i1 %43, label %24, label %44
44: ; preds = %41
br label %53
45: ; preds = %20
%46 = load i32, i32* %2
%47 = icmp eq i32 %46, 3
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
br label %52
50: ; preds = %45
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
br label %52
52: ; preds = %50, %48
br label %53
53: ; preds = %52, %44
br label %54
54: ; preds = %53, %17
br label %55
55: ; preds = %54
%56 = load i32, i32* %2
%57 = icmp ne i32 %56, 3
br i1 %57, label %7, label %58
58: ; preds = %55
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str.1 = [50 x i8] c"\0A1. Set exchange rate in SEK (current rate: %.2f)\00"
@.str.2 = [40 x i8] c"\0A2. Read prices in the foreign currency\00"
@.str.4 = [28 x i8] c"\0AGive your choice (1 - 3): \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.7 = [21 x i8] c"Give exchange rate: \00"
@.str.8 = [4 x i8] c"%lf\00"
@.str.9 = [31 x i8] c"Give price (finish with < 0): \00"
@.str.10 = [31 x i8] c"\0ASum in foreign currency: %.2f\00"
@.str.11 = [19 x i8] c"\0ASum in SEK: %.2f\0A\00"
@str = [24 x i8] c"Your shopping assistant\00"
@str.14 = [8 x i8] c"\0A3. End\00"
@str.15 = [20 x i8] c"Not a valid choice!\00"
@str.16 = [17 x i8] c"End of program!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = bitcast i32* %1 to i8*
%5 = bitcast double* %2 to i8*
store double 1.000000e+00, double* %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%7 = bitcast double* %3 to i8*
br label %8
8: ; preds = %47, %0
%9 = phi double [ %48, %47 ], [ 1.000000e+00, %0 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), double %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.14, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%15 = call i32 @putchar(i32 10)
%16 = load i32, i32* %1
switch i32 %16, label %42 [
i32 1, label %17
i32 2, label %20
i32 3, label %40
]
17: ; preds = %8
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double* %2)
br label %44
20: ; preds = %8
br label %21
21: ; preds = %35, %20
%22 = phi double [ 0.000000e+00, %20 ], [ %37, %35 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), double* %3)
%25 = load double, double* %3
%26 = fcmp ult double %25, 0.000000e+00
br i1 %26, label %29, label %27
27: ; preds = %21
%28 = fadd double %22, %25
br label %35
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), double %22)
%31 = load double, double* %2
%32 = fmul double %22, %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), double %32)
%34 = load double, double* %3
br label %35
35: ; preds = %27, %29
%36 = phi double [ %25, %27 ], [ %34, %29 ]
%37 = phi double [ %28, %27 ], [ %22, %29 ]
%38 = fcmp ult double %36, 0.000000e+00
br i1 %38, label %39, label %21
39: ; preds = %35
br label %44
40: ; preds = %8
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.16, i64 0, i64 0))
br label %44
42: ; preds = %8
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.15, i64 0, i64 0))
br label %44
44: ; preds = %17, %40, %42, %39
%45 = load i32, i32* %1
%46 = icmp eq i32 %45, 3
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = load double, double* %2
br label %8
49: ; preds = %44
ret i32 0
}