#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 *);
void print_state(const int state) {
  printf("Door: ");
  switch (state) {
  case 0:
    printf("CLOSED");
    return;
  case 1:
    printf("OPENING");
    return;
  case 2:
    printf("OPEN");
    return;
  case 3:
    printf("CLOSING");
    return;
  case 4:
    printf("STOPPED_WHILE_CLOSING");
    return;
  case 5:
    printf("STOPPED_WHILE_OPENING");
    return;
  }
}


x86 assembly (clang, -O0):
<print_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xef6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0x5,%rax
ja     11ad <print_state+0x9d>
mov    -0x10(%rbp),%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
jmp    11ad <print_state+0x9d>
lea    0xeeb(%rip),%rdi
call   1030 <printf@plt>
jmp    11ad <print_state+0x9d>
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
jmp    11ad <print_state+0x9d>
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
jmp    11ad <print_state+0x9d>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
jmp    11ad <print_state+0x9d>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_state>:
push   %rbx
mov    %edi,%ebx
lea    0xee6(%rip),%rdi
call   1030 <printf@plt>
cmp    $0x5,%ebx
ja     113b <print_state+0x2b>
movslq %ebx,%rax
lea    0xf12(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
pop    %rbx
jmp    1030 <printf@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Door: \00"
@.str.1 = [7 x i8] c"CLOSED\00"
@.str.2 = [8 x i8] c"OPENING\00"
@.str.3 = [5 x i8] c"OPEN\00"
@.str.4 = [8 x i8] c"CLOSING\00"
@.str.5 = [22 x i8] c"STOPPED_WHILE_CLOSING\00"
@.str.6 = [22 x i8] c"STOPPED_WHILE_OPENING\00"
define void @print_state(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* %2
switch i32 %4, label %17 [
i32 0, label %5
i32 1, label %7
i32 2, label %9
i32 3, label %11
i32 4, label %13
i32 5, label %15
]
5: ; preds = %1
%6 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %17
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %17
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %17
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %17
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %17
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %17
17: ; preds = %5, %7, %9, %11, %13, %15, %1
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"Door: \00"
@.str.1 = [7 x i8] c"CLOSED\00"
@.str.2 = [8 x i8] c"OPENING\00"
@.str.3 = [5 x i8] c"OPEN\00"
@.str.4 = [8 x i8] c"CLOSING\00"
@.str.5 = [22 x i8] c"STOPPED_WHILE_CLOSING\00"
@.str.6 = [22 x i8] c"STOPPED_WHILE_OPENING\00"
@reltable.print_state = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.print_state to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.print_state to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.print_state to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.print_state to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.print_state to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.6 to i64), i64 ptrtoint ([6 x i32]* @reltable.print_state to i64)) to i32)]
define void @print_state(i32 %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = icmp ult i32 %0, 6
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = sext i32 %0 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.print_state to i8*), i64 %6)
%8 = tail call i32 @printf(i8* dereferenceable(1) %7)
br label %9
9: ; preds = %1, %4
ret void
}