#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 */
scalar_t__ strcmp(char *, char *);
int door_state(char *command, int state) {
  int temp;
  if (strcmp(command, "button_clicked") == 0)
    temp = 1;
  else {
    if (strcmp(command, "cycle_complete") == 0)
      temp = 0;
    else
      return 6;
  }
  if (temp)
    switch (state) {
    case 0:
      state = 1;
      break;
    case 1:
      state = 5;
      break;
    case 2:
      state = 3;
      break;
    case 5:
      state = 3;
      break;
    case 3:
      state = 4;
      break;
    case 4:
      state = 2;
      break;
    default:
      state = 6;
      break;
    }
  else {
    if (state == 4 || state == 5)
      return 6;
    switch (state) {
    case 1:
      state = 2;
      break;
    case 3:
      state = 0;
      break;
    default:
      state = 6;
      break;
    }
  }
  return state;
}


x86 assembly (clang, -O0):
<door_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeee(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1145 <door_state+0x35>
movl   $0x1,-0x18(%rbp)
jmp    117c <door_state+0x6c>
mov    -0x10(%rbp),%rdi
lea    0xed7(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    116b <door_state+0x5b>
movl   $0x0,-0x18(%rbp)
jmp    1177 <door_state+0x67>
movl   $0x6,-0x4(%rbp)
jmp    126e <door_state+0x15e>
jmp    117c <door_state+0x6c>
cmpl   $0x0,-0x18(%rbp)
je     11ff <door_state+0xef>
mov    -0x14(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x5,%rax
ja     11f3 <door_state+0xe3>
mov    -0x20(%rbp),%rax
lea    0xe5e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x14(%rbp)
jmp    11fa <door_state+0xea>
movl   $0x5,-0x14(%rbp)
jmp    11fa <door_state+0xea>
movl   $0x3,-0x14(%rbp)
jmp    11fa <door_state+0xea>
movl   $0x3,-0x14(%rbp)
jmp    11fa <door_state+0xea>
movl   $0x4,-0x14(%rbp)
jmp    11fa <door_state+0xea>
movl   $0x2,-0x14(%rbp)
jmp    11fa <door_state+0xea>
movl   $0x6,-0x14(%rbp)
jmp    1268 <door_state+0x158>
cmpl   $0x4,-0x14(%rbp)
je     1213 <door_state+0x103>
cmpl   $0x5,-0x14(%rbp)
jne    121f <door_state+0x10f>
movl   $0x6,-0x4(%rbp)
jmp    126e <door_state+0x15e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     1244 <door_state+0x134>
jmp    1233 <door_state+0x123>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
je     1250 <door_state+0x140>
jmp    125c <door_state+0x14c>
movl   $0x2,-0x14(%rbp)
jmp    1263 <door_state+0x153>
movl   $0x0,-0x14(%rbp)
jmp    1263 <door_state+0x153>
movl   $0x6,-0x14(%rbp)
jmp    1268 <door_state+0x158>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<door_state>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xee1(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1169 <door_state+0x59>
lea    0xedf(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
mov    %rax,%rcx
mov    %ebp,%edx
and    $0xfffffffe,%edx
mov    $0x6,%eax
cmp    $0x4,%edx
je     1180 <door_state+0x70>
test   %rcx,%rcx
jne    1180 <door_state+0x70>
xor    %eax,%eax
cmp    $0x3,%ebp
mov    $0x6,%ecx
cmove  %eax,%ecx
cmp    $0x1,%ebp
mov    $0x2,%eax
cmovne %ecx,%eax
jmp    1180 <door_state+0x70>
mov    $0x6,%eax
cmp    $0x6,%ebp
jae    1180 <door_state+0x70>
movslq %ebp,%rax
lea    0xea3(%rip),%rcx
mov    (%rcx,%rax,4),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"button_clicked\00"
@.str.1 = [15 x i8] c"cycle_complete\00"
define i32 @door_state(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %6
br label %18
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 0, i32* %6
br label %17
16: ; preds = %11
store i32 6, i32* %3
br label %46
17: ; preds = %15
br label %18
18: ; preds = %17, %10
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i32, i32* %5
switch i32 %22, label %29 [
i32 0, label %23
i32 1, label %24
i32 2, label %25
i32 5, label %26
i32 3, label %27
i32 4, label %28
]
23: ; preds = %21
store i32 1, i32* %5
br label %30
24: ; preds = %21
store i32 5, i32* %5
br label %30
25: ; preds = %21
store i32 3, i32* %5
br label %30
26: ; preds = %21
store i32 3, i32* %5
br label %30
27: ; preds = %21
store i32 4, i32* %5
br label %30
28: ; preds = %21
store i32 2, i32* %5
br label %30
29: ; preds = %21
store i32 6, i32* %5
br label %30
30: ; preds = %29, %28, %27, %26, %25, %24, %23
br label %44
31: ; preds = %18
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 4
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 5
br i1 %36, label %37, label %38
37: ; preds = %34, %31
store i32 6, i32* %3
br label %46
38: ; preds = %34
%39 = load i32, i32* %5
switch i32 %39, label %42 [
i32 1, label %40
i32 3, label %41
]
40: ; preds = %38
store i32 2, i32* %5
br label %43
41: ; preds = %38
store i32 0, i32* %5
br label %43
42: ; preds = %38
store i32 6, i32* %5
br label %43
43: ; preds = %42, %41, %40
br label %44
44: ; preds = %43, %30
%45 = load i32, i32* %5
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %37, %16
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [15 x i8] c"button_clicked\00"
@.str.1 = [15 x i8] c"cycle_complete\00"
@switch.table.door_state = [6 x i32] [i32 1, i32 5, i32 3, i32 4, i32 2, i32 3]
define i32 @door_state(i8* %0, i32 %1) {
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
%8 = and i32 %1, -2
%9 = icmp eq i32 %8, 4
%10 = or i1 %9, %7
br i1 %10, label %22, label %13
11: ; preds = %2
%12 = icmp ult i32 %1, 6
br i1 %12, label %18, label %22
13: ; preds = %5
%14 = icmp eq i32 %1, 3
%15 = select i1 %14, i32 0, i32 6
%16 = icmp eq i32 %1, 1
%17 = select i1 %16, i32 2, i32 %15
br label %22
18: ; preds = %11
%19 = sext i32 %1 to i64
%20 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.door_state, i64 0, i64 %19
%21 = load i32, i32* %20
br label %22
22: ; preds = %11, %18, %13, %5
%23 = phi i32 [ 6, %5 ], [ %17, %13 ], [ %21, %18 ], [ 6, %11 ]
ret i32 %23
}