#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 *, char *, int *);
int main(void) {
  int num_1, num_2;
  char operator;
  printf("請輸入 + - * / 的二元運算式,\ne.g. 3 + 5: ");
  scanf("%d %c %d", &num_1, &operator, & num_2);
  switch (operator) {
  case '+':
    printf("計算結果: %d\n", num_1 + num_2);
    break;
  case '-':
    printf("計算結果: %d\n", num_1 - num_2);
    break;
  case '*':
    printf("計算結果: %d\n", num_1 * num_2);
    break;
  case '/':
    printf("計算結果: %f\n", (float)num_1 / num_2);
    break;
  default:
    printf("輸入格式錯誤。\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf07(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xd(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1040 <scanf@plt>
movsbl -0xd(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5,%eax
ja     11f0 <main+0xd0>
mov    -0x18(%rbp),%rax
lea    0xe8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%esi
add    -0xc(%rbp),%esi
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fe <main+0xde>
mov    -0x8(%rbp),%esi
sub    -0xc(%rbp),%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fe <main+0xde>
mov    -0x8(%rbp),%esi
imul   -0xc(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fe <main+0xde>
cvtsi2ssl -0x8(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe82(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11fe <main+0xde>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xedd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf02(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xf(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1050 <scanf@plt>
movsbl 0xf(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x5,%eax
ja     118f <main+0x5f>
lea    0xe8f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x10(%rsp),%esi
imul   0x14(%rsp),%esi
jmp    11a5 <main+0x75>
mov    0x10(%rsp),%esi
add    0x14(%rsp),%esi
jmp    11a5 <main+0x75>
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
jmp    11d7 <main+0xa7>
mov    0x14(%rsp),%esi
sub    0x10(%rsp),%esi
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d7 <main+0xa7>
cvtsi2ssl 0x14(%rsp),%xmm0
cvtsi2ssl 0x10(%rsp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe96(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"\E8\AB\8B\E8\BC\B8\E5\85\A5 + - * / \E7\9A\84\E4\BA\8C\E5\85\83\E9\81\8B\E7\AE\97\E5\BC\8F,\0Ae.g. 3 + 5: \00"
@.str.1 = [9 x i8] c"%d %c %d\00"
@.str.2 = [18 x i8] c"\E8\A8\88\E7\AE\97\E7\B5\90\E6\9E\9C: %d\0A\00"
@.str.3 = [18 x i8] c"\E8\A8\88\E7\AE\97\E7\B5\90\E6\9E\9C: %f\0A\00"
@.str.4 = [23 x i8] c"\E8\BC\B8\E5\85\A5\E6\A0\BC\E5\BC\8F\E9\8C\AF\E8\AA\A4\E3\80\82\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i8* %4, i32* %3)
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
switch i32 %8, label %32 [
i32 43, label %9
i32 45, label %14
i32 42, label %19
i32 47, label %24
]
9: ; preds = %0
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = add nsw i32 %10, %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %34
14: ; preds = %0
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = sub nsw i32 %15, %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %34
19: ; preds = %0
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = mul nsw i32 %20, %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %34
24: ; preds = %0
%25 = load i32, i32* %2
%26 = sitofp i32 %25 to float
%27 = load i32, i32* %3
%28 = sitofp i32 %27 to float
%29 = fdiv float %26, %28
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %30)
br label %34
32: ; preds = %0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %24, %19, %14, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"\E8\AB\8B\E8\BC\B8\E5\85\A5 + - * / \E7\9A\84\E4\BA\8C\E5\85\83\E9\81\8B\E7\AE\97\E5\BC\8F,\0Ae.g. 3 + 5: \00"
@.str.1 = [9 x i8] c"%d %c %d\00"
@.str.2 = [18 x i8] c"\E8\A8\88\E7\AE\97\E7\B5\90\E6\9E\9C: %d\0A\00"
@.str.3 = [18 x i8] c"\E8\A8\88\E7\AE\97\E7\B5\90\E6\9E\9C: %f\0A\00"
@str = [22 x i8] c"\E8\BC\B8\E5\85\A5\E6\A0\BC\E5\BC\8F\E9\8C\AF\E8\AA\A4\E3\80\82\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i8* %3, i32* %2)
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
switch i32 %9, label %33 [
i32 43, label %10
i32 45, label %15
i32 42, label %20
i32 47, label %25
]
10: ; preds = %0
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = add nsw i32 %12, %11
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %35
15: ; preds = %0
%16 = load i32, i32* %1
%17 = load i32, i32* %2
%18 = sub nsw i32 %16, %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %35
20: ; preds = %0
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = mul nsw i32 %22, %21
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %35
25: ; preds = %0
%26 = load i32, i32* %1
%27 = sitofp i32 %26 to float
%28 = load i32, i32* %2
%29 = sitofp i32 %28 to float
%30 = fdiv float %27, %29
%31 = fpext float %30 to double
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %31)
br label %35
33: ; preds = %0
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %33, %25, %20, %15, %10
ret i32 0
}