#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, char *, float *);
void main() {
  float a, b, d;
  char p;
  printf("输入计算式:\n");
  scanf("%f%c%f", &a, &p, &b);
  switch (p) {
  case '+':
    d = a + b;
    break;
  case '-':
    d = a - b;
    break;
  case '*':
    d = a * b;
    break;
  case '/':
    if (b != 0) {
      d = a / b;
      break;
    }
  default:
    printf("error\n");
    getchar();
    getchar();
    exit(0);
  }
  printf(" =%.2f\n", d);
  getchar();
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecd(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0xd(%rbp),%rdx
lea    -0x8(%rbp),%rcx
call   1050 <scanf@plt>
movsbl -0xd(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     1209 <main+0xc9>
mov    -0x18(%rbp),%rax
lea    0xe71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0x4(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    122c <main+0xec>
movss  -0x4(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    122c <main+0xec>
movss  -0x4(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    122c <main+0xec>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11f0 <main+0xb0>
jp     11f0 <main+0xb0>
jmp    1204 <main+0xc4>
movss  -0x4(%rbp),%xmm0
divss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    122c <main+0xec>
jmp    1209 <main+0xc9>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %edi,%edi
call   1060 <exit@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdfc(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb1(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xf(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x5,%eax
ja     1201 <main+0xb1>
lea    0xe71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  0x14(%rsp),%xmm0
mulss  0x10(%rsp),%xmm0
jmp    11dc <main+0x8c>
movss  0x14(%rsp),%xmm0
addss  0x10(%rsp),%xmm0
jmp    11dc <main+0x8c>
movss  0x14(%rsp),%xmm0
subss  0x10(%rsp),%xmm0
jmp    11dc <main+0x8c>
movss  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    11d2 <main+0x82>
jnp    1201 <main+0xb1>
movss  0x14(%rsp),%xmm0
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe38(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x18,%rsp
ret
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"\E8\BE\93\E5\85\A5\E8\AE\A1\E7\AE\97\E5\BC\8F:\0A\00"
@.str.1 = [7 x i8] c"%f%c%f\00"
@.str.2 = [7 x i8] c"error\0A\00"
@.str.3 = [8 x i8] c" =%.2f\0A\00"
define void @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca i8
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), float* %1, i8* %4, float* %2)
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
switch i32 %8, label %29 [
i32 43, label %9
i32 45, label %13
i32 42, label %17
i32 47, label %21
]
9: ; preds = %0
%10 = load float, float* %1
%11 = load float, float* %2
%12 = fadd float %10, %11
store float %12, float* %3
br label %34
13: ; preds = %0
%14 = load float, float* %1
%15 = load float, float* %2
%16 = fsub float %14, %15
store float %16, float* %3
br label %34
17: ; preds = %0
%18 = load float, float* %1
%19 = load float, float* %2
%20 = fmul float %18, %19
store float %20, float* %3
br label %34
21: ; preds = %0
%22 = load float, float* %2
%23 = fcmp une float %22, 0.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load float, float* %1
%26 = load float, float* %2
%27 = fdiv float %25, %26
store float %27, float* %3
br label %34
28: ; preds = %21
br label %29
29: ; preds = %0, %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 (...) @getchar()
%32 = call i32 (...) @getchar()
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %24, %17, %13, %9
%35 = load float, float* %3
%36 = fpext float %35 to double
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %36)
%38 = call i32 (...) @getchar()
%39 = call i32 (...) @getchar()
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%f%c%f\00"
@.str.3 = [8 x i8] c" =%.2f\0A\00"
@str = [17 x i8] c"\E8\BE\93\E5\85\A5\E8\AE\A1\E7\AE\97\E5\BC\8F:\00"
@str.4 = [6 x i8] c"error\00"
define void @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca i8
%4 = bitcast float* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), float* %1, i8* %3, float* %2)
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
switch i32 %9, label %28 [
i32 43, label %10
i32 45, label %14
i32 42, label %18
i32 47, label %22
]
10: ; preds = %0
%11 = load float, float* %1
%12 = load float, float* %2
%13 = fadd float %11, %12
br label %33
14: ; preds = %0
%15 = load float, float* %1
%16 = load float, float* %2
%17 = fsub float %15, %16
br label %33
18: ; preds = %0
%19 = load float, float* %1
%20 = load float, float* %2
%21 = fmul float %19, %20
br label %33
22: ; preds = %0
%23 = load float, float* %2
%24 = fcmp une float %23, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load float, float* %1
%27 = fdiv float %26, %23
br label %33
28: ; preds = %22, %0
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.4, i64 0, i64 0))
%30 = call i32 (...) @getchar()
%31 = call i32 (...) @getchar()
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %25, %18, %14, %10
%34 = phi float [ %27, %25 ], [ %21, %18 ], [ %17, %14 ], [ %13, %10 ]
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %35)
%37 = call i32 (...) @getchar()
%38 = call i32 (...) @getchar()
ret void
}