#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 */
char *do_door(int *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char commands[5000];
  scanf("%[^EOF]s", commands);
  printf("Door: CLOSED\n");
  int f = 0, door = 0, movement = 0, operation;
  for (; f < strlen(commands); f++) {
    if (commands[f] == 'b')
      operation = 1;
    if (commands[f] == 'c')
      operation = 0;
    printf("Door: %s\n", do_door(&door, &movement, operation));
    while (commands[f] != '\n')
      f++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1390(%rbp),%rsi
lea    0xea0(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1394(%rbp)
movl   $0x0,-0x1398(%rbp)
movl   $0x0,-0x139c(%rbp)
mov    -0x1394(%rbp),%eax
mov    %eax,-0x13a4(%rbp)
lea    -0x1390(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x13a4(%rbp),%eax
cmp    %ecx,%eax
jge    126c <main+0x12c>
movslq -0x1394(%rbp),%rax
movsbl -0x1390(%rbp,%rax,1),%eax
ff
cmp    $0x62,%eax
jne    11db <main+0x9b>
movl   $0x1,-0x13a0(%rbp)
movslq -0x1394(%rbp),%rax
movsbl -0x1390(%rbp,%rax,1),%eax
ff
cmp    $0x63,%eax
jne    11fd <main+0xbd>
movl   $0x0,-0x13a0(%rbp)
mov    -0x13a0(%rbp),%edx
lea    -0x1398(%rbp),%rdi
lea    -0x139c(%rbp),%rsi
call   1050 <do_door@plt>
mov    %rax,%rsi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x1394(%rbp),%rax
movsbl -0x1390(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     1253 <main+0x113>
mov    -0x1394(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1394(%rbp)
jmp    1227 <main+0xe7>
jmp    1258 <main+0x118>
mov    -0x1394(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1394(%rbp)
jmp    1191 <main+0x51>
xor    %eax,%eax
add    $0x13b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1398,%rsp
lea    0xe98(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    122b <main+0xdb>
lea    0x8(%rsp),%r15
lea    0xe5c(%rip),%r12
lea    0x10(%rsp),%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
movslq %r13d,%rax
mov    0x10(%rsp,%rax,1),%cl
cmp    $0x62,%cl
mov    $0x1,%edx
cmove  %edx,%ebp
lea    (%rsp,%rax,1),%r14
add    $0x10,%r14
cmp    $0x63,%cl
mov    $0x0,%eax
cmove  %eax,%ebp
lea    0xc(%rsp),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <do_door@plt>
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
cmpb   $0xa,(%r14)
lea    0x1(%r14),%r14
jne    1210 <main+0xc0>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r13d
jl     11c0 <main+0x70>
xor    %eax,%eax
add    $0x1398,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%[^EOF]s\00"
@.str.1 = [14 x i8] c"Door: CLOSED\0A\00"
@.str.2 = [10 x i8] c"Door: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5000 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds [5000 x i8], [5000 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %10
10: ; preds = %46, %0
%11 = load i32, i32* %3
%12 = getelementptr inbounds [5000 x i8], [5000 x i8]* %2, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %49
15: ; preds = %10
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [5000 x i8], [5000 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 98
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 1, i32* %6
br label %23
23: ; preds = %22, %15
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [5000 x i8], [5000 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 99
br i1 %29, label %30, label %31
30: ; preds = %23
store i32 0, i32* %6
br label %31
31: ; preds = %30, %23
%32 = load i32, i32* %6
%33 = call i8* @do_door(i32* %4, i32* %5, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %42, %31
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [5000 x i8], [5000 x i8]* %2, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 10
br i1 %41, label %42, label %45
42: ; preds = %35
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %35
45: ; preds = %35
br label %46
46: ; preds = %45
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %10
49: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"%[^EOF]s\00"
@.str.2 = [10 x i8] c"Door: %s\0A\00"
@str = [13 x i8] c"Door: CLOSED\00"
define i32 @main() {
%1 = alloca [5000 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%7 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = call i32 @strlen(i8* %4)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %0, %29
%12 = phi i32 [ %20, %29 ], [ undef, %0 ]
%13 = phi i32 [ %31, %29 ], [ 0, %0 ]
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 98
%18 = select i1 %17, i32 1, i32 %12
%19 = icmp eq i8 %16, 99
%20 = select i1 %19, i32 0, i32 %18
%21 = call i8* @do_door(i32* %2, i32* %3, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %23, %11
%24 = phi i64 [ %28, %23 ], [ %14, %11 ]
%25 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
%28 = add i64 %24, 1
br i1 %27, label %29, label %23
29: ; preds = %23
%30 = trunc i64 %24 to i32
%31 = add nsw i32 %30, 1
%32 = call i32 @strlen(i8* %4)
%33 = icmp slt i32 %31, %32
br i1 %33, label %11, label %34
34: ; preds = %29, %0
ret i32 0
}