#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*/ *strcasestr(char *, char *);
int parse(char *buff, int type) {
  char *KNOWN_LOGIN[3] = {"ogin:", "last login", "sername"};
  char *KNOWN_PSW[3] = {"asswor", "asscode", "ennwort"};
  char *KNOWN_PRT[6] = {"?", "/", ">", "%", "$", "#"};
  char *KNOWN_BAD[3] = {"incorrect", "bad log", "no log"};
  int i;
  int p_size[4];
  char **p_known[4];
  p_size[0] = 3;
  p_size[1] = 3;
  p_size[2] = 6;
  p_size[3] = 3;
  p_known[0] = (char **)&KNOWN_LOGIN;
  p_known[1] = (char **)&KNOWN_PSW;
  p_known[2] = (char **)&KNOWN_PRT;
  p_known[3] = (char **)&KNOWN_BAD;
  for (i = 0; i < p_size[type]; i++) {
    if (strcasestr(buff, p_known[type][i]) != NULL)
      return (type + 1);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2c87(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c84(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c81(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c86(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c83(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c80(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
lea    0xea5(%rip),%rax
mov    %rax,-0x80(%rbp)
lea    0xe9c(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe78(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c33(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2c2d(%rip),%rax
mov    %rax,-0x98(%rbp)
mov    0x2c27(%rip),%rax
mov    %rax,-0x90(%rbp)
movl   $0x3,-0xc0(%rbp)
movl   $0x3,-0xbc(%rbp)
movl   $0x6,-0xb8(%rbp)
movl   $0x3,-0xb4(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xd0(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
movslq -0x14(%rbp),%rcx
cmp    -0xc0(%rbp,%rcx,4),%eax
jge    12b9 <parse+0x199>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rax
ff
movslq -0xa4(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcasestr@plt>
cmp    $0x0,%rax
je     12a0 <parse+0x180>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12c0 <parse+0x1a0>
jmp    12a5 <parse+0x185>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    1251 <parse+0x131>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    0x2ca8(%rip),%rax
mov    %rax,0xb0(%rsp)
movaps 0x2c89(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
mov    0x2caa(%rip),%rax
mov    %rax,0x90(%rsp)
movaps 0x2c8b(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
lea    0xedc(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xed2(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xec8(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xebe(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xeb4(%rip),%rax
mov    %rax,0x40(%rsp)
lea    0xeaa(%rip),%rax
mov    %rax,0x48(%rsp)
mov    0x2c64(%rip),%rax
mov    %rax,0x70(%rsp)
movaps 0x2c48(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe3c(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
lea    0xa0(%rsp),%rax
mov    %rax,(%rsp)
lea    0x80(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0x60(%rsp),%rax
mov    %rax,0x18(%rsp)
movslq %esi,%rax
mov    0x50(%rsp,%rax,4),%r13d
mov    $0xffffffff,%r15d
test   %r13d,%r13d
jle    1243 <parse+0x133>
mov    %esi,%r14d
mov    %rdi,%r12
mov    (%rsp,%rax,8),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx,%rbp,8),%rsi
mov    %r12,%rdi
call   1030 <strcasestr@plt>
test   %rax,%rax
jne    123c <parse+0x12c>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1220 <parse+0x110>
jmp    1243 <parse+0x133>
add    $0x1,%r14d
mov    %r14d,%r15d
mov    %r15d,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"ogin:\00"
@.str.1 = [11 x i8] c"last login\00"
@.str.2 = [8 x i8] c"sername\00"
@__const.parse.KNOWN_LOGIN = [3 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [7 x i8] c"asswor\00"
@.str.4 = [8 x i8] c"asscode\00"
@.str.5 = [8 x i8] c"ennwort\00"
@__const.parse.KNOWN_PSW = [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0)]
@.str.6 = [2 x i8] c"?\00"
@.str.7 = [2 x i8] c"/\00"
@.str.8 = [2 x i8] c">\00"
@.str.9 = [2 x i8] c"%\00"
@.str.10 = [2 x i8] c"$\00"
@.str.11 = [2 x i8] c"#\00"
@.str.12 = [10 x i8] c"incorrect\00"
@.str.13 = [8 x i8] c"bad log\00"
@.str.14 = [7 x i8] c"no log\00"
@__const.parse.KNOWN_BAD = [3 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i32 0, i32 0)]
define i32 @parse(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [3 x i8*]
%7 = alloca [3 x i8*]
%8 = alloca [6 x i8*]
%9 = alloca [3 x i8*]
%10 = alloca i32
%11 = alloca [4 x i32]
%12 = alloca [4 x i8**]
store i8* %0, i8** %4
store i32 %1, i32* %5
%13 = bitcast [3 x i8*]* %6 to i8*
%14 = bitcast [3 x i8*]* %7 to i8*
%15 = bitcast [6 x i8*]* %8 to i8*
%16 = bitcast i8* %15 to [6 x i8*]*
%17 = getelementptr inbounds [6 x i8*], [6 x i8*]* %16, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [6 x i8*], [6 x i8*]* %16, i32 0, i32 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0), i8** %18
%19 = getelementptr inbounds [6 x i8*], [6 x i8*]* %16, i32 0, i32 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0), i8** %19
%20 = getelementptr inbounds [6 x i8*], [6 x i8*]* %16, i32 0, i32 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i32 0, i32 0), i8** %20
%21 = getelementptr inbounds [6 x i8*], [6 x i8*]* %16, i32 0, i32 4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i32 0, i32 0), i8** %21
%22 = getelementptr inbounds [6 x i8*], [6 x i8*]* %16, i32 0, i32 5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i32 0, i32 0), i8** %22
%23 = bitcast [3 x i8*]* %9 to i8*
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
store i32 3, i32* %24
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
store i32 3, i32* %25
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 2
store i32 6, i32* %26
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
store i32 3, i32* %27
%28 = bitcast [3 x i8*]* %6 to i8**
%29 = getelementptr inbounds [4 x i8**], [4 x i8**]* %12, i64 0, i64 0
store i8** %28, i8*** %29
%30 = bitcast [3 x i8*]* %7 to i8**
%31 = getelementptr inbounds [4 x i8**], [4 x i8**]* %12, i64 0, i64 1
store i8** %30, i8*** %31
%32 = bitcast [6 x i8*]* %8 to i8**
%33 = getelementptr inbounds [4 x i8**], [4 x i8**]* %12, i64 0, i64 2
store i8** %32, i8*** %33
%34 = bitcast [3 x i8*]* %9 to i8**
%35 = getelementptr inbounds [4 x i8**], [4 x i8**]* %12, i64 0, i64 3
store i8** %34, i8*** %35
store i32 0, i32* %10
br label %36
36: ; preds = %59, %2
%37 = load i32, i32* %10
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = icmp slt i32 %37, %41
br i1 %42, label %43, label %62
43: ; preds = %36
%44 = load i8*, i8** %4
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [4 x i8**], [4 x i8**]* %12, i64 0, i64 %46
%48 = load i8**, i8*** %47
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32* @strcasestr(i8* %44, i8* %52)
%54 = icmp ne i32* %53, null
br i1 %54, label %55, label %58
55: ; preds = %43
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %63
58: ; preds = %43
br label %59
59: ; preds = %58
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %36
62: ; preds = %36
store i32 -1, i32* %3
br label %63
63: ; preds = %62, %55
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [6 x i8] c"ogin:\00"
@.str.1 = [11 x i8] c"last login\00"
@.str.2 = [8 x i8] c"sername\00"
@__const.parse.KNOWN_LOGIN = [3 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [7 x i8] c"asswor\00"
@.str.4 = [8 x i8] c"asscode\00"
@.str.5 = [8 x i8] c"ennwort\00"
@__const.parse.KNOWN_PSW = [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0)]
@.str.6 = [2 x i8] c"?\00"
@.str.7 = [2 x i8] c"/\00"
@.str.8 = [2 x i8] c">\00"
@.str.9 = [2 x i8] c"%\00"
@.str.10 = [2 x i8] c"$\00"
@.str.11 = [2 x i8] c"#\00"
@.str.12 = [10 x i8] c"incorrect\00"
@.str.13 = [8 x i8] c"bad log\00"
@.str.14 = [7 x i8] c"no log\00"
@__const.parse.KNOWN_BAD = [3 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i32 0, i32 0)]
define i32 @parse(i8* %0, i32 %1) {
%3 = alloca [3 x i8*]
%4 = alloca [3 x i8*]
%5 = alloca [6 x i8*]
%6 = alloca [3 x i8*]
%7 = alloca <4 x i32>
%8 = alloca [4 x i8**]
%9 = bitcast [3 x i8*]* %3 to i8*
%10 = bitcast [3 x i8*]* %4 to i8*
%11 = bitcast [6 x i8*]* %5 to i8*
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8** %17
%18 = bitcast [3 x i8*]* %6 to i8*
%19 = bitcast <4 x i32>* %7 to i8*
%20 = bitcast [4 x i8**]* %8 to i8*
store <4 x i32> <i32 3, i32 3, i32 6, i32 3>, <4 x i32>* %7
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%22 = getelementptr inbounds [4 x i8**], [4 x i8**]* %8, i64 0, i64 0
store i8** %21, i8*** %22
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%24 = getelementptr inbounds [4 x i8**], [4 x i8**]* %8, i64 0, i64 1
store i8** %23, i8*** %24
%25 = getelementptr inbounds [4 x i8**], [4 x i8**]* %8, i64 0, i64 2
store i8** %12, i8*** %25
%26 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%27 = getelementptr inbounds [4 x i8**], [4 x i8**]* %8, i64 0, i64 3
store i8** %26, i8*** %27
%28 = sext i32 %1 to i64
%29 = getelementptr inbounds <4 x i32>, <4 x i32>* %7, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %47
32: ; preds = %2
%33 = getelementptr inbounds [4 x i8**], [4 x i8**]* %8, i64 0, i64 %28
%34 = load i8**, i8*** %33
%35 = zext i32 %30 to i64
br label %38
36: ; preds = %38
%37 = icmp eq i64 %44, %35
br i1 %37, label %47, label %38
38: ; preds = %32, %36
%39 = phi i64 [ 0, %32 ], [ %44, %36 ]
%40 = getelementptr inbounds i8*, i8** %34, i64 %39
%41 = load i8*, i8** %40
%42 = call i32* @strcasestr(i8* %0, i8* %41)
%43 = icmp eq i32* %42, null
%44 = add nuw nsw i64 %39, 1
br i1 %43, label %36, label %45
45: ; preds = %38
%46 = add nsw i32 %1, 1
br label %47
47: ; preds = %36, %2, %45
%48 = phi i32 [ %46, %45 ], [ -1, %2 ], [ -1, %36 ]
ret i32 %48
}