#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 */
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
struct timeval {
  int member_0;
  int /*<<< orphan*/ member_1;
};
struct TYPE_6__ {
  int /*<<< orphan*/ member_0;
};
typedef TYPE_1__ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_ISSET(unsigned int, TYPE_1__ *);
int /*<<< orphan*/ FD_SET(unsigned int, TYPE_1__ *);
int /*<<< orphan*/ FD_ZERO(TYPE_1__ *);
int /*<<< orphan*/ NW_DoInquire();
int /*<<< orphan*/ NW_GetConfigPara(int);
int /*<<< orphan*/ NW_ResetTimer(struct timeval *);
int /*<<< orphan*/ printf(char *);
int select(int, TYPE_1__ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           struct timeval *);
void NW_InquireProcess(int fd) {
  int ret = 0;
  fd_set fds = {0};
  struct timeval timeout = {(0x7FFFFFFF), 0};
  FD_SET((unsigned int)fd, &fds);
  for (;;) {
    FD_ZERO(&fds);
    FD_SET((unsigned int)fd, &fds);
    ret = select(fd + 1, &fds, NULL, NULL, &timeout);
    switch (ret) {
    case -1:
      printf("Error occur in NW_InquireProcess");
      break;
    case 0:
      NW_ResetTimer(&timeout);
      NW_DoInquire();
      break;
    default:
      if (FD_ISSET((unsigned int)fd, &fds)) {
        NW_GetConfigPara(fd);
        NW_ResetTimer(&timeout);
        NW_DoInquire();
      }
      break;
    }
  }
}


x86 assembly (clang, -O0):
<NW_InquireProcess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    0xe47(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10b0 <FD_SET@plt>
lea    -0x10(%rbp),%rdi
mov    %rdi,-0x28(%rbp)
call   1080 <FD_ZERO@plt>
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edi
call   10b0 <FD_SET@plt>
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1090 <select@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     1223 <NW_InquireProcess+0x93>
jmp    1213 <NW_InquireProcess+0x83>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     1234 <NW_InquireProcess+0xa4>
jmp    1249 <NW_InquireProcess+0xb9>
lea    0xdde(%rip),%rdi
call   1050 <printf@plt>
jmp    127b <NW_InquireProcess+0xeb>
lea    -0x18(%rbp),%rdi
call   10a0 <NW_ResetTimer@plt>
mov    $0x0,%al
call   1070 <NW_DoInquire@plt>
jmp    127b <NW_InquireProcess+0xeb>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%eax
je     1276 <NW_InquireProcess+0xe6>
mov    -0x4(%rbp),%edi
call   1040 <NW_GetConfigPara@plt>
lea    -0x18(%rbp),%rdi
call   10a0 <NW_ResetTimer@plt>
mov    $0x0,%al
call   1070 <NW_DoInquire@plt>
jmp    127b <NW_InquireProcess+0xeb>
jmp    11c9 <NW_InquireProcess+0x39>

x86 assembly (clang, -O2):
<NW_InquireProcess>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
movl   $0x0,(%rsp)
movq   $0x7fffffff,0x8(%rsp)
ff 7f
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10a0 <FD_SET@plt>
lea    0x1(%r14),%ebp
lea    0x8(%rsp),%r15
lea    0xe46(%rip),%r12
jmp    11e6 <NW_InquireProcess+0x66>
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %eax,%eax
je     11e6 <NW_InquireProcess+0x66>
mov    %r14d,%edi
call   1040 <NW_GetConfigPara@plt>
mov    %r15,%rdi
call   1090 <NW_ResetTimer@plt>
xor    %eax,%eax
call   1060 <NW_DoInquire@plt>
mov    %rbx,%rdi
call   1070 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   10a0 <FD_SET@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1080 <select@plt>
test   %eax,%eax
je     11d7 <NW_InquireProcess+0x57>
cmp    $0xffffffff,%eax
jne    11c0 <NW_InquireProcess+0x40>
mov    %r12,%rdi
call   1050 <printf@plt>
jmp    11e6 <NW_InquireProcess+0x66>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.TYPE_6__ = type { i32 }
@__const.NW_InquireProcess.timeout = %struct.timeval { i32 2147483647, i32 0 }
@.str = [33 x i8] c"Error occur in NW_InquireProcess\00"
define void @NW_InquireProcess(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.TYPE_6__
%5 = alloca %struct.timeval
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = bitcast %struct.TYPE_6__* %4 to i8*
%7 = bitcast %struct.timeval* %5 to i8*
%8 = load i32, i32* %2
%9 = call i32 @FD_SET(i32 %8, %struct.TYPE_6__* %4)
br label %10
10: ; preds = %33, %1
%11 = call i32 @FD_ZERO(%struct.TYPE_6__* %4)
%12 = load i32, i32* %2
%13 = call i32 @FD_SET(i32 %12, %struct.TYPE_6__* %4)
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
%16 = call i32 @select(i32 %15, %struct.TYPE_6__* %4, i32* null, i32* null, %struct.timeval* %5)
store i32 %16, i32* %3
%17 = load i32, i32* %3
switch i32 %17, label %23 [
i32 -1, label %18
i32 0, label %20
]
18: ; preds = %10
%19 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %33
20: ; preds = %10
%21 = call i32 @NW_ResetTimer(%struct.timeval* %5)
%22 = call i32 (...) @NW_DoInquire()
br label %33
23: ; preds = %10
%24 = load i32, i32* %2
%25 = call i32 @FD_ISSET(i32 %24, %struct.TYPE_6__* %4)
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* %2
%29 = call i32 @NW_GetConfigPara(i32 %28)
%30 = call i32 @NW_ResetTimer(%struct.timeval* %5)
%31 = call i32 (...) @NW_DoInquire()
br label %32
32: ; preds = %27, %23
br label %33
33: ; preds = %32, %20, %18
br label %10
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [33 x i8] c"Error occur in NW_InquireProcess\00"
define void @NW_InquireProcess(i32 %0) {
%2 = alloca %struct.TYPE_6__
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.timeval*
%5 = bitcast %struct.TYPE_6__* %2 to i8*
%6 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %2, i64 0, i32 0
store i32 0, i32* %6
%7 = bitcast i64* %3 to i8*
store i64 2147483647, i64* %3
%8 = call i32 @FD_SET(i32 %0, %struct.TYPE_6__* %2)
%9 = add nsw i32 %0, 1
br label %10
10: ; preds = %22, %1
%11 = call i32 @FD_ZERO(%struct.TYPE_6__* %2)
%12 = call i32 @FD_SET(i32 %0, %struct.TYPE_6__* %2)
%13 = call i32 @select(i32 %9, %struct.TYPE_6__* %2, i32* null, i32* null, %struct.timeval* %4)
switch i32 %13, label %19 [
i32 -1, label %14
i32 0, label %16
]
14: ; preds = %10
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %22
16: ; preds = %10
%17 = call i32 @NW_ResetTimer(%struct.timeval* %4)
%18 = call i32 (...) @NW_DoInquire()
br label %22
19: ; preds = %10
%20 = call i32 @FD_ISSET(i32 %0, %struct.TYPE_6__* %2)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19, %23, %16, %14
br label %10
23: ; preds = %19
%24 = call i32 @NW_GetConfigPara(i32 %0)
%25 = call i32 @NW_ResetTimer(%struct.timeval* %4)
%26 = call i32 (...) @NW_DoInquire()
br label %22
}