#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 strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int is_valid_action(char *action) {
  int rc, length;
  length = strlen(action);
  rc = -1;
  if (action == NULL || (length < 3 || length > 5))
    return rc;
  if (strncmp(action, "ipl", strlen("ipl")) == 0 && length == 3)
    rc = 0;
  if (strncmp(action, "reipl", strlen("reipl")) == 0 && length == 5)
    rc = 1;
  if (strncmp(action, "dump", strlen("dump")) == 0 && length == 4)
    rc = 2;
  if (strncmp(action, "stop", strlen("stop")) == 0 && length == 4)
    rc = 3;
  if (strncmp(action, "vmcmd", strlen("vmcmd")) == 0 && length == 5)
    rc = 4;
  return rc;
}


x86 assembly (clang, -O0):
<is_valid_action>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115e <is_valid_action+0x3e>
cmpl   $0x3,-0x18(%rbp)
jl     115e <is_valid_action+0x3e>
cmpl   $0x5,-0x18(%rbp)
jle    1169 <is_valid_action+0x49>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b4 <is_valid_action+0x194>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe78(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11aa <is_valid_action+0x8a>
cmpl   $0x3,-0x18(%rbp)
jne    11aa <is_valid_action+0x8a>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe47(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe35(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11eb <is_valid_action+0xcb>
cmpl   $0x5,-0x18(%rbp)
jne    11eb <is_valid_action+0xcb>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe0c(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xdfa(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    122c <is_valid_action+0x10c>
cmpl   $0x4,-0x18(%rbp)
jne    122c <is_valid_action+0x10c>
movl   $0x2,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xdd0(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xdbe(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    126d <is_valid_action+0x14d>
cmpl   $0x4,-0x18(%rbp)
jne    126d <is_valid_action+0x14d>
movl   $0x3,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xd94(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xd82(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ae <is_valid_action+0x18e>
cmpl   $0x5,-0x18(%rbp)
jne    12ae <is_valid_action+0x18e>
movl   $0x4,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_action>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    $0xffffffff,%ebx
test   %r14,%r14
je     1241 <is_valid_action+0x121>
mov    %eax,%r15d
cmp    $0x3,%eax
jl     1241 <is_valid_action+0x121>
cmp    $0x5,%r15d
jg     1241 <is_valid_action+0x121>
lea    0xea7(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
setne  %al
cmp    $0x3,%r15d
setne  %cl
or     %al,%cl
movzbl %cl,%ebp
neg    %ebp
lea    0xe75(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x5,%r15d
mov    $0x1,%ebx
cmovne %ebp,%ebx
test   %rax,%rax
cmovne %ebp,%ebx
lea    0xe4d(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x4,%r15d
mov    $0x2,%ebp
cmovne %ebx,%ebp
test   %rax,%rax
cmovne %ebx,%ebp
cmp    $0x4,%r15d
lea    0xe20(%rip),%rbx
mov    $0x3,%r12d
cmovne %ebp,%r12d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
cmovne %ebp,%r12d
cmp    $0x5,%r15d
lea    0xdf4(%rip),%r15
mov    $0x4,%ebx
cmovne %r12d,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
cmovne %r12d,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ipl\00"
@.str.1 = [6 x i8] c"reipl\00"
@.str.2 = [5 x i8] c"dump\00"
@.str.3 = [5 x i8] c"stop\00"
@.str.4 = [6 x i8] c"vmcmd\00"
define i32 @is_valid_action(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
store i32 -1, i32* %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %16, label %10
10: ; preds = %1
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 3
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 5
br i1 %15, label %16, label %18
16: ; preds = %13, %10, %1
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %65
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %4
br label %27
27: ; preds = %26, %23, %18
%28 = load i8*, i8** %3
%29 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%30 = call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 5
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 1, i32* %4
br label %36
36: ; preds = %35, %32, %27
%37 = load i8*, i8** %3
%38 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = load i32, i32* %5
%43 = icmp eq i32 %42, 4
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 2, i32* %4
br label %45
45: ; preds = %44, %41, %36
%46 = load i8*, i8** %3
%47 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%48 = call i64 @strncmp(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = load i32, i32* %5
%52 = icmp eq i32 %51, 4
br i1 %52, label %53, label %54
53: ; preds = %50
store i32 3, i32* %4
br label %54
54: ; preds = %53, %50, %45
%55 = load i8*, i8** %3
%56 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%57 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %54
%60 = load i32, i32* %5
%61 = icmp eq i32 %60, 5
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 4, i32* %4
br label %63
63: ; preds = %62, %59, %54
%64 = load i32, i32* %4
store i32 %64, i32* %2
br label %65
65: ; preds = %63, %16
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
@.str = [4 x i8] c"ipl\00"
@.str.1 = [6 x i8] c"reipl\00"
@.str.2 = [5 x i8] c"dump\00"
@.str.3 = [5 x i8] c"stop\00"
@.str.4 = [6 x i8] c"vmcmd\00"
define i32 @is_valid_action(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i8* %0, null
%4 = icmp slt i32 %2, 3
%5 = select i1 %3, i1 true, i1 %4
%6 = icmp sgt i32 %2, 5
%7 = select i1 %5, i1 true, i1 %6
br i1 %7, label %37, label %8
8: ; preds = %1
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp ne i64 %10, 0
%12 = icmp ne i32 %2, 3
%13 = select i1 %11, i1 true, i1 %12
%14 = sext i1 %13 to i32
%15 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp eq i64 %16, 0
%18 = icmp eq i32 %2, 5
%19 = select i1 %17, i1 %18, i1 false
%20 = select i1 %19, i32 1, i32 %14
%21 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %22, 0
%24 = icmp eq i32 %2, 4
%25 = select i1 %23, i1 %24, i1 false
%26 = select i1 %25, i32 2, i32 %20
%27 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i1 %24, i1 false
%31 = select i1 %30, i32 3, i32 %26
%32 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%33 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, i1 %18, i1 false
%36 = select i1 %35, i32 4, i32 %31
br label %37
37: ; preds = %1, %8
%38 = phi i32 [ %36, %8 ], [ -1, %1 ]
ret i32 %38
}