#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 a = 1, i = 1;
  double p;
  printf("[1] apples\n"
         "[2] pears\n"
         "[3] oranges\n"
         "[4] grapes\n"
         "[0] exit\n");
  while (a != 0 && i <= 5) {
    i++;
    printf("Enter choice: ");
    scanf("%d", &a);
    if (a == 0)
      break;
    switch (a) {
    case 1:
      p = 3.0;
      break;
    case 2:
      p = 2.5;
      break;
    case 3:
      p = 4.0;
      break;
    case 4:
      p = 3.5;
      break;
    default:
      p = 0.0;
      break;
    }
    printf("price=%.2f\n", p);
  }
  printf("Thanks");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
je     1164 <main+0x44>
cmpl   $0x5,-0xc(%rbp)
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1174 <main+0x54>
jmp    123b <main+0x11b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11aa <main+0x8a>
jmp    123b <main+0x11b>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     121b <main+0xfb>
mov    -0x28(%rbp),%rax
lea    0xe56(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  0xe3d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1223 <main+0x103>
movsd  0xe23(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1223 <main+0x103>
movsd  0xe09(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1223 <main+0x103>
movsd  0xdef(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1223 <main+0x103>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe49(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    114b <main+0x2b>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x1,0x4(%rsp)
lea    0xf0f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
lea    0xed9(%rip),%r14
lea    0xee1(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xed8(%rip),%r13
lea    0xeab(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x4,%rax
ja     11c0 <main+0x90>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
movsd  0xe51(%rip),%xmm0
jmp    *%rax
movsd  0xe5f(%rip),%xmm0
jmp    11f0 <main+0xc0>
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
jmp    11f0 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0xe38(%rip),%xmm0
jmp    11f0 <main+0xc0>
nopw   0x0(%rax,%rax,1)
movsd  0xe20(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
je     120f <main+0xdf>
lea    0x1(%rbx),%eax
cmp    $0x5,%ebx
mov    %eax,%ebx
jb     1180 <main+0x50>
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"[1] apples\0A[2] pears\0A[3] oranges\0A[4] grapes\0A[0] exit\0A\00"
@.str.1 = [15 x i8] c"Enter choice: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [12 x i8] c"price=%.2f\0A\00"
@.str.4 = [7 x i8] c"Thanks\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
store i32 0, i32* %1
store i32 1, i32* %2
store i32 1, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %29, %0
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 5
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ false, %6 ], [ %11, %9 ]
br i1 %13, label %14, label %32
14: ; preds = %12
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %32
22: ; preds = %14
%23 = load i32, i32* %2
switch i32 %23, label %28 [
i32 1, label %24
i32 2, label %25
i32 3, label %26
i32 4, label %27
]
24: ; preds = %22
store double 3.000000e+00, double* %4
br label %29
25: ; preds = %22
store double 2.500000e+00, double* %4
br label %29
26: ; preds = %22
store double 4.000000e+00, double* %4
br label %29
27: ; preds = %22
store double 3.500000e+00, double* %4
br label %29
28: ; preds = %22
store double 0.000000e+00, double* %4
br label %29
29: ; preds = %28, %27, %26, %25, %24
%30 = load double, double* %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %30)
br label %6
32: ; preds = %21, %12
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"Enter choice: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [12 x i8] c"price=%.2f\0A\00"
@.str.4 = [7 x i8] c"Thanks\00"
@str = [53 x i8] c"[1] apples\0A[2] pears\0A[3] oranges\0A[4] grapes\0A[0] exit\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %0, %14
%5 = phi i32 [ %6, %14 ], [ 1, %0 ]
%6 = add nuw nsw i32 %5, 1
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 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), i32* %1)
%9 = load i32, i32* %1
switch i32 %9, label %13 [
i32 0, label %21
i32 1, label %14
i32 2, label %10
i32 3, label %11
i32 4, label %12
]
10: ; preds = %4
br label %14
11: ; preds = %4
br label %14
12: ; preds = %4
br label %14
13: ; preds = %4
br label %14
14: ; preds = %4, %13, %12, %11, %10
%15 = phi double [ 0.000000e+00, %13 ], [ 3.500000e+00, %12 ], [ 4.000000e+00, %11 ], [ 2.500000e+00, %10 ], [ 3.000000e+00, %4 ]
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %15)
%17 = load i32, i32* %1
%18 = icmp ne i32 %17, 0
%19 = icmp ult i32 %5, 5
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %4, label %21
21: ; preds = %14, %4
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}