#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 *getField(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
char *performAction(char *line) {
  char action;
  scanf(" %c", &action);
  char *action_key;
  char *action_room;
  int i = 3;
  while (1) {
    action_key = getField(line, i);
    action_room = getField(line, i + 1);
    i = i + 2;
    if (!action_key || !action_room) {
      printf("Sorry, I didn't understand that.\n");
      return performAction(line);
    }
    if (action != action_key[0])
      continue;
    return action_room;
  }
  return 0;
}


x86 assembly (clang, -O0):
<performAction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x3,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <getField@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
call   1030 <getField@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a5 <performAction+0x65>
cmpq   $0x0,-0x28(%rbp)
jne    11c3 <performAction+0x83>
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <performAction@plt>
mov    %rax,-0x8(%rbp)
jmp    11e3 <performAction+0xa3>
movsbl -0x11(%rbp),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11db <performAction+0x9b>
jmp    1163 <performAction+0x23>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<performAction>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xeae(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <getField@plt>
mov    %rax,%rbx
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <getField@plt>
test   %rbx,%rbx
je     11a2 <performAction+0x62>
test   %rax,%rax
je     11a2 <performAction+0x62>
movzbl 0xf(%rsp),%ecx
add    $0x1,%ebp
cmp    (%rbx),%cl
jne    1170 <performAction+0x30>
jmp    11b6 <performAction+0x76>
lea    0xe5b(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <performAction@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" %c\00"
@.str.1 = [34 x i8] c"Sorry, I didn't understand that.\0A\00"
define i8* @performAction(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
store i32 3, i32* %7
br label %9
9: ; preds = %1, %36
%10 = load i8*, i8** %3
%11 = load i32, i32* %7
%12 = call i8* @getField(i8* %10, i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %3
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
%16 = call i8* @getField(i8* %13, i32 %15)
store i8* %16, i8** %6
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 2
store i32 %18, i32* %7
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %9
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %21, %9
%25 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%26 = load i8*, i8** %3
%27 = call i8* @performAction(i8* %26)
store i8* %27, i8** %2
br label %39
28: ; preds = %21
%29 = load i8, i8* %4
%30 = sext i8 %29 to i32
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %30, %34
br i1 %35, label %36, label %37
36: ; preds = %28
br label %9
37: ; preds = %28
%38 = load i8*, i8** %6
store i8* %38, i8** %2
br label %39
39: ; preds = %37, %24
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
@.str = [4 x i8] c" %c\00"
@str = [33 x i8] c"Sorry, I didn't understand that.\00"
define i8* @performAction(i8* %0) {
%2 = alloca i8
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %4
4: ; preds = %15, %1
%5 = phi i32 [ 3, %1 ], [ %16, %15 ]
%6 = call i8* @getField(i8* %0, i32 %5)
%7 = add nuw nsw i32 %5, 1
%8 = call i8* @getField(i8* %0, i32 %7)
%9 = icmp ne i8* %6, null
%10 = icmp ne i8* %8, null
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %15, label %12
12: ; preds = %4
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%14 = call i8* @performAction(i8* %0)
br label %20
15: ; preds = %4
%16 = add nuw nsw i32 %5, 2
%17 = load i8, i8* %2
%18 = load i8, i8* %6
%19 = icmp eq i8 %17, %18
br i1 %19, label %20, label %4
20: ; preds = %15, %12
%21 = phi i8* [ %14, %12 ], [ %8, %15 ]
ret i8* %21
}