#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*/ increase_count();
int /*<<< orphan*/ increase_step();
int /*<<< orphan*/ is_crash_keys(unsigned int);
scalar_t__ is_hold_key(unsigned int);
scalar_t__ is_hold_key_hold();
scalar_t__ is_key_matched_for_current_step(unsigned int);
scalar_t__ is_key_state_down(unsigned int);
scalar_t__ is_reaching_count_for_next_step();
int /*<<< orphan*/ pr_info(char *, char *);
int /*<<< orphan*/ reset_count();
int /*<<< orphan*/ reset_step();
int /*<<< orphan*/ set_hold_key_hold(int);
int /*<<< orphan*/ set_key_state_down(unsigned int);
int /*<<< orphan*/ set_key_state_up(unsigned int);
void check_crash_keys_in_user(unsigned int code, int state) {
  if (!is_crash_keys(code))
    return;
  if (state == 1) {
    if (is_key_state_down(code))
      return;
    set_key_state_down(code);
    if (is_hold_key(code)) {
      set_hold_key_hold(1);
      return;
    }
    if (is_hold_key_hold()) {
      if (is_key_matched_for_current_step(code)) {
        increase_count();
      } else {
        pr_info("%s: crash key reset\n", "sec_upload");
        reset_count();
        reset_step();
      }
      if (is_reaching_count_for_next_step())
        increase_step();
    }
  } else {
    set_key_state_up(code);
    if (is_hold_key(code)) {
      pr_info("%s: crash key reset\n", "sec_upload");
      set_hold_key_hold(0);
      reset_step();
      reset_count();
    }
  }
}


x86 assembly (clang, -O0):
<check_crash_keys_in_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <is_crash_keys@plt>
cmp    $0x0,%eax
jne    1204 <check_crash_keys_in_user+0x24>
jmp    1307 <check_crash_keys_in_user+0x127>
cmpl   $0x1,-0x8(%rbp)
jne    12c0 <check_crash_keys_in_user+0xe0>
mov    -0x4(%rbp),%edi
call   10c0 <is_key_state_down@plt>
cmp    $0x0,%rax
je     1225 <check_crash_keys_in_user+0x45>
jmp    1307 <check_crash_keys_in_user+0x127>
mov    -0x4(%rbp),%edi
call   10e0 <set_key_state_down@plt>
mov    -0x4(%rbp),%edi
call   1100 <is_hold_key@plt>
cmp    $0x0,%rax
je     124e <check_crash_keys_in_user+0x6e>
mov    $0x1,%edi
call   1040 <set_hold_key_hold@plt>
jmp    1307 <check_crash_keys_in_user+0x127>
mov    $0x0,%al
call   1080 <is_hold_key_hold@plt>
cmp    $0x0,%rax
je     12bb <check_crash_keys_in_user+0xdb>
mov    -0x4(%rbp),%edi
call   10a0 <is_key_matched_for_current_step@plt>
cmp    $0x0,%rax
je     127d <check_crash_keys_in_user+0x9d>
mov    $0x0,%al
call   10b0 <increase_count@plt>
jmp    129e <check_crash_keys_in_user+0xbe>
lea    0xd7c(%rip),%rdi
lea    0xd8a(%rip),%rsi
call   1030 <pr_info@plt>
mov    $0x0,%al
call   1050 <reset_count@plt>
mov    $0x0,%al
call   10f0 <reset_step@plt>
mov    $0x0,%al
call   1090 <is_reaching_count_for_next_step@plt>
cmp    $0x0,%rax
je     12b6 <check_crash_keys_in_user+0xd6>
mov    $0x0,%al
call   10d0 <increase_step@plt>
jmp    12bb <check_crash_keys_in_user+0xdb>
jmp    1307 <check_crash_keys_in_user+0x127>
mov    -0x4(%rbp),%edi
call   1060 <set_key_state_up@plt>
mov    -0x4(%rbp),%edi
call   1100 <is_hold_key@plt>
cmp    $0x0,%rax
je     1302 <check_crash_keys_in_user+0x122>
lea    0xd1f(%rip),%rdi
lea    0xd2d(%rip),%rsi
call   1030 <pr_info@plt>
xor    %edi,%edi
call   1040 <set_hold_key_hold@plt>
mov    $0x0,%al
call   10f0 <reset_step@plt>
mov    $0x0,%al
call   1050 <reset_count@plt>
jmp    1307 <check_crash_keys_in_user+0x127>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_crash_keys_in_user>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
call   1070 <is_crash_keys@plt>
test   %eax,%eax
je     12ca <check_crash_keys_in_user+0xea>
mov    %ebx,%edi
cmp    $0x1,%ebp
jne    122c <check_crash_keys_in_user+0x4c>
call   10c0 <is_key_state_down@plt>
test   %rax,%rax
jne    12ca <check_crash_keys_in_user+0xea>
mov    %ebx,%edi
call   10e0 <set_key_state_down@plt>
mov    %ebx,%edi
call   1100 <is_hold_key@plt>
test   %rax,%rax
je     126f <check_crash_keys_in_user+0x8f>
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <set_hold_key_hold@plt>
call   1060 <set_key_state_up@plt>
mov    %ebx,%edi
call   1100 <is_hold_key@plt>
test   %rax,%rax
je     12ca <check_crash_keys_in_user+0xea>
lea    0xdb8(%rip),%rdi
lea    0xdc6(%rip),%rsi
call   1030 <pr_info@plt>
xor    %edi,%edi
call   1040 <set_hold_key_hold@plt>
xor    %eax,%eax
call   10f0 <reset_step@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <reset_count@plt>
xor    %eax,%eax
call   1080 <is_hold_key_hold@plt>
test   %rax,%rax
je     12ca <check_crash_keys_in_user+0xea>
mov    %ebx,%edi
call   10a0 <is_key_matched_for_current_step@plt>
test   %rax,%rax
je     1290 <check_crash_keys_in_user+0xb0>
xor    %eax,%eax
call   10b0 <increase_count@plt>
jmp    12b1 <check_crash_keys_in_user+0xd1>
lea    0xd69(%rip),%rdi
lea    0xd77(%rip),%rsi
call   1030 <pr_info@plt>
xor    %eax,%eax
call   1050 <reset_count@plt>
xor    %eax,%eax
call   10f0 <reset_step@plt>
xor    %eax,%eax
call   1090 <is_reaching_count_for_next_step@plt>
test   %rax,%rax
je     12ca <check_crash_keys_in_user+0xea>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    10d0 <increase_step@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%s: crash key reset\0A\00"
@.str.1 = [11 x i8] c"sec_upload\00"
define void @check_crash_keys_in_user(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = call i32 @is_crash_keys(i32 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %2
br label %57
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %45
12: ; preds = %9
%13 = load i32, i32* %3
%14 = call i64 @is_key_state_down(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
br label %57
17: ; preds = %12
%18 = load i32, i32* %3
%19 = call i32 @set_key_state_down(i32 %18)
%20 = load i32, i32* %3
%21 = call i64 @is_hold_key(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @set_hold_key_hold(i32 1)
br label %57
25: ; preds = %17
%26 = call i64 (...) @is_hold_key_hold()
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %25
%29 = load i32, i32* %3
%30 = call i64 @is_key_matched_for_current_step(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (...) @increase_count()
br label %38
34: ; preds = %28
%35 = call i32 @pr_info(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 (...) @reset_count()
%37 = call i32 (...) @reset_step()
br label %38
38: ; preds = %34, %32
%39 = call i64 (...) @is_reaching_count_for_next_step()
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (...) @increase_step()
br label %43
43: ; preds = %41, %38
br label %44
44: ; preds = %43, %25
br label %57
45: ; preds = %9
%46 = load i32, i32* %3
%47 = call i32 @set_key_state_up(i32 %46)
%48 = load i32, i32* %3
%49 = call i64 @is_hold_key(i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %45
%52 = call i32 @pr_info(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @set_hold_key_hold(i32 0)
%54 = call i32 (...) @reset_step()
%55 = call i32 (...) @reset_count()
br label %56
56: ; preds = %51, %45
br label %57
57: ; preds = %8, %16, %23, %56, %44
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"%s: crash key reset\0A\00"
@.str.1 = [11 x i8] c"sec_upload\00"
define void @check_crash_keys_in_user(i32 %0, i32 %1) {
%3 = tail call i32 @is_crash_keys(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %42, label %5
5: ; preds = %2
%6 = icmp eq i32 %1, 1
br i1 %6, label %7, label %33
7: ; preds = %5
%8 = tail call i64 @is_key_state_down(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %42
10: ; preds = %7
%11 = tail call i32 @set_key_state_down(i32 %0)
%12 = tail call i64 @is_hold_key(i32 %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @set_hold_key_hold(i32 1)
br label %42
16: ; preds = %10
%17 = tail call i64 (...) @is_hold_key_hold()
%18 = icmp eq i64 %17, 0
br i1 %18, label %42, label %19
19: ; preds = %16
%20 = tail call i64 @is_key_matched_for_current_step(i32 %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 (...) @increase_count()
br label %28
24: ; preds = %19
%25 = tail call i32 @pr_info(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 (...) @reset_count()
%27 = tail call i32 (...) @reset_step()
br label %28
28: ; preds = %24, %22
%29 = tail call i64 (...) @is_reaching_count_for_next_step()
%30 = icmp eq i64 %29, 0
br i1 %30, label %42, label %31
31: ; preds = %28
%32 = tail call i32 (...) @increase_step()
br label %42
33: ; preds = %5
%34 = tail call i32 @set_key_state_up(i32 %0)
%35 = tail call i64 @is_hold_key(i32 %0)
%36 = icmp eq i64 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %33
%38 = tail call i32 @pr_info(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%39 = tail call i32 @set_hold_key_hold(i32 0)
%40 = tail call i32 (...) @reset_step()
%41 = tail call i32 (...) @reset_count()
br label %42
42: ; preds = %33, %37, %16, %31, %28, %7, %2, %14
ret void
}