#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*/ buildpacket(unsigned char *, int *, int, unsigned char *,
                               int);
int getint(unsigned char *);
int listen(int, unsigned char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
int checkidle(int fd) {
  unsigned char pak[1024];
  unsigned char buf[1024];
  int len, res;
  unsigned char p[2];
  p[0] = 0x01;
  p[1] = 0x00;
  buildpacket(pak, &len, 0x05, p, 2);
  write(fd, pak, len);
  res = listen(fd, buf);
  if (res > 1 && getint(&buf[4]) == 1 && getint(&buf[6]) == 0)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<checkidle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x8(%rbp)
movb   $0x1,-0x81a(%rbp)
movb   $0x0,-0x819(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x81a(%rbp),%rcx
lea    -0x814(%rbp),%rsi
mov    $0x5,%edx
mov    $0x2,%r8d
call   1050 <buildpacket@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1060 <listen@plt>
mov    %eax,-0x818(%rbp)
cmpl   $0x1,-0x818(%rbp)
jle    11f6 <checkidle+0xb6>
lea    -0x810(%rbp),%rdi
add    $0x4,%rdi
call   1040 <getint@plt>
cmp    $0x1,%eax
jne    11f6 <checkidle+0xb6>
lea    -0x810(%rbp),%rdi
add    $0x6,%rdi
call   1040 <getint@plt>
cmp    $0x0,%eax
jne    11f6 <checkidle+0xb6>
movl   $0x1,-0x4(%rbp)
jmp    11fd <checkidle+0xbd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkidle>:
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %edi,%ebx
movw   $0x1,0xa(%rsp)
lea    0x410(%rsp),%r14
lea    0xc(%rsp),%rsi
lea    0xa(%rsp),%rcx
mov    %r14,%rdi
mov    $0x5,%edx
mov    $0x2,%r8d
call   1050 <buildpacket@plt>
mov    0xc(%rsp),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <write@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
call   1060 <listen@plt>
cmp    $0x2,%eax
jl     11b4 <checkidle+0x74>
lea    0x14(%rsp),%rdi
call   1040 <getint@plt>
cmp    $0x1,%eax
jne    11b4 <checkidle+0x74>
lea    0x16(%rsp),%rdi
call   1040 <getint@plt>
test   %eax,%eax
je     11c1 <checkidle+0x81>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%eax
jmp    11b6 <checkidle+0x76>

LLVM IR (-O0):
define i32 @checkidle(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i8]
store i32 %0, i32* %3
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 1, i8* %9
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 0, i8* %10
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%13 = call i32 @buildpacket(i8* %11, i32* %6, i32 5, i8* %12, i32 2)
%14 = load i32, i32* %3
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = load i32, i32* %6
%17 = call i32 @write(i32 %14, i8* %15, i32 %16)
%18 = load i32, i32* %3
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = call i32 @listen(i32 %18, i8* %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, 1
br i1 %22, label %23, label %32
23: ; preds = %1
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 4
%25 = call i32 @getint(i8* %24)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 6
%29 = call i32 @getint(i8* %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 1, i32* %2
br label %33
32: ; preds = %27, %23, %1
store i32 0, i32* %2
br label %33
33: ; preds = %32, %31
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
define i32 @checkidle(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca [2 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 1, i8* %9
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 0, i8* %10
%11 = call i32 @buildpacket(i8* %6, i32* %4, i32 5, i8* %9, i32 2)
%12 = load i32, i32* %4
%13 = call i32 @write(i32 %0, i8* %6, i32 %12)
%14 = call i32 @listen(i32 %0, i8* %7)
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %24
16: ; preds = %1
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
%18 = call i32 @getint(i8* %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 6
%22 = call i32 @getint(i8* %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20, %16, %1
br label %25
25: ; preds = %20, %24
%26 = phi i32 [ 0, %24 ], [ 1, %20 ]
ret i32 %26
}