#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int, unsigned char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ usleep(int);
int check_reset_button() {
  int fd;
  unsigned char btn_status;
  int time_count = 0;
  int ret;
  fd = open("/proc/jz_gpio", O_RDWR);
  if (fd == -1)
    return -1;
  ioctl(fd, 0x30, &btn_status);
  if (btn_status == 1) {
    close(fd);
    return 0;
  }
  usleep(10000);
  do {
    sleep(1);
    time_count++;
    ioctl(fd, 0x30, &btn_status);
  } while (btn_status != 1);
  usleep(10000);
  if (time_count > 3)
    ret = 2;
  else
    ret = 1;
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<check_reset_button>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    118d <check_reset_button+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <check_reset_button+0xdf>
mov    -0x8(%rbp),%edi
mov    $0x30,%esi
lea    -0x9(%rbp),%rdx
call   1030 <ioctl@plt>
movzbl -0x9(%rbp),%eax
cmp    $0x1,%eax
jne    11bf <check_reset_button+0x6f>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    122f <check_reset_button+0xdf>
mov    $0x2710,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x30,%esi
lea    -0x9(%rbp),%rdx
call   1030 <ioctl@plt>
movzbl -0x9(%rbp),%eax
cmp    $0x1,%eax
jne    11c9 <check_reset_button+0x79>
mov    $0x2710,%edi
call   1070 <usleep@plt>
cmpl   $0x3,-0x10(%rbp)
jle    121a <check_reset_button+0xca>
movl   $0x2,-0x14(%rbp)
jmp    1221 <check_reset_button+0xd1>
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_reset_button>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11f1 <check_reset_button+0xa1>
mov    %eax,%ebx
lea    0xf(%rsp),%rdx
mov    %eax,%edi
mov    $0x30,%esi
call   1030 <ioctl@plt>
xor    %ebp,%ebp
cmpb   $0x1,0xf(%rsp)
je     11e8 <check_reset_button+0x98>
mov    $0x2710,%edi
call   1070 <usleep@plt>
mov    $0xffffffff,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %ebx,%edi
mov    $0x30,%esi
mov    %r14,%rdx
call   1030 <ioctl@plt>
add    $0x1,%ebp
cmpb   $0x1,0xf(%rsp)
jne    11b0 <check_reset_button+0x60>
mov    $0x2710,%edi
call   1070 <usleep@plt>
cmp    $0x3,%ebp
mov    $0x1,%ebp
sbb    $0xffffffff,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11f6 <check_reset_button+0xa6>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/jz_gpio\00"
@O_RDWR = global i32 0
define i32 @check_reset_button() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %4
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %42
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @ioctl(i32 %12, i32 48, i8* %3)
%14 = load i8, i8* %3
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* %2
%19 = call i32 @close(i32 %18)
store i32 0, i32* %1
br label %42
20: ; preds = %11
%21 = call i32 @usleep(i32 10000)
br label %22
22: ; preds = %28, %20
%23 = call i32 @sleep(i32 1)
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
%26 = load i32, i32* %2
%27 = call i32 @ioctl(i32 %26, i32 48, i8* %3)
br label %28
28: ; preds = %22
%29 = load i8, i8* %3
%30 = zext i8 %29 to i32
%31 = icmp ne i32 %30, 1
br i1 %31, label %22, label %32
32: ; preds = %28
%33 = call i32 @usleep(i32 10000)
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 3
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 2, i32* %5
br label %38
37: ; preds = %32
store i32 1, i32* %5
br label %38
38: ; preds = %37, %36
%39 = load i32, i32* %2
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %5
store i32 %41, i32* %1
br label %42
42: ; preds = %38, %17, %10
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/jz_gpio\00"
@O_RDWR = global i32 0
define i32 @check_reset_button() {
%1 = alloca i8
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %25, label %5
5: ; preds = %0
%6 = call i32 @ioctl(i32 %3, i32 48, i8* %1)
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 1
br i1 %8, label %22, label %9
9: ; preds = %5
%10 = call i32 @usleep(i32 10000)
br label %11
11: ; preds = %11, %9
%12 = phi i32 [ 0, %9 ], [ %14, %11 ]
%13 = call i32 @sleep(i32 1)
%14 = add nuw nsw i32 %12, 1
%15 = call i32 @ioctl(i32 %3, i32 48, i8* %1)
%16 = load i8, i8* %1
%17 = icmp eq i8 %16, 1
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = call i32 @usleep(i32 10000)
%20 = icmp ugt i32 %12, 2
%21 = select i1 %20, i32 2, i32 1
br label %22
22: ; preds = %5, %18
%23 = phi i32 [ %21, %18 ], [ 0, %5 ]
%24 = call i32 @close(i32 %3)
br label %25
25: ; preds = %22, %0
%26 = phi i32 [ -1, %0 ], [ %23, %22 ]
ret i32 %26
}