#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*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int num;
  printf("输入一个整数:");
  scanf("%d", &num);
  switch (num % 3) {
  case 0:
    puts("能被3整除");
    break;
  case 1:
    puts("能除以3的余数1");
    break;
  case 2:
    puts("除以 3 余数是 2");
    break;
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rcx
mov    %ecx,%eax
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
je     11ac <main+0x7c>
jmp    118a <main+0x5a>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
je     11bd <main+0x8d>
jmp    119b <main+0x6b>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
je     11ce <main+0x9e>
jmp    11da <main+0xaa>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
jmp    11da <main+0xaa>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
jmp    11da <main+0xaa>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
movslq 0x4(%rsp),%rax
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x2,%eax
ja     1186 <main+0x56>
cltq
lea    0xed6(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"\E8\BE\93\E5\85\A5\E4\B8\80\E4\B8\AA\E6\95\B4\E6\95\B0:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [14 x i8] c"\E8\83\BD\E8\A2\AB3\E6\95\B4\E9\99\A4\00"
@.str.3 = [21 x i8] c"\E8\83\BD\E9\99\A4\E4\BB\A53\E7\9A\84\E4\BD\99\E6\95\B01\00"
@.str.4 = [21 x i8] c"\E9\99\A4\E4\BB\A5 3 \E4\BD\99\E6\95\B0\E6\98\AF 2\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%5 = load i32, i32* %2
%6 = srem i32 %5, 3
switch i32 %6, label %13 [
i32 0, label %7
i32 1, label %9
i32 2, label %11
]
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %13
9: ; preds = %0
%10 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %13
11: ; preds = %0
%12 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %0, %11, %9, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"\E8\BE\93\E5\85\A5\E4\B8\80\E4\B8\AA\E6\95\B4\E6\95\B0:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [14 x i8] c"\E8\83\BD\E8\A2\AB3\E6\95\B4\E9\99\A4\00"
@.str.3 = [21 x i8] c"\E8\83\BD\E9\99\A4\E4\BB\A53\E7\9A\84\E4\BD\99\E6\95\B01\00"
@.str.4 = [21 x i8] c"\E9\99\A4\E4\BB\A5 3 \E4\BD\99\E6\95\B0\E6\98\AF 2\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.4 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = srem i32 %5, 3
%7 = icmp ult i32 %6, 3
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = sext i32 %6 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %10)
%12 = call i32 @puts(i8* dereferenceable(1) %11)
br label %13
13: ; preds = %0, %8
ret i32 0
}