#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_rs_status(int);
scalar_t__ resource_monitor(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char, int);
int /*<<< orphan*/ sys_handle(char *);
void *rs_monitor() {
  int status;
  int lrm_status = 0;
  char l_data[5];
  for (;;) {
    status = lrm_status;
    if (resource_monitor(lrm_status) == 0)
      lrm_status = 0;
    else
      lrm_status = 1;
    if (status != lrm_status) {
      print_rs_status(lrm_status);
      memset(l_data, 0, 5);
      if (lrm_status == 0)
        sprintf(l_data, "%c%d", '#', 2);
      else
        sprintf(l_data, "%c%d", '#', 3);
      sys_handle(l_data);
    }
    sleep(5);
  }
}


x86 assembly (clang, -O0):
<rs_monitor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <resource_monitor@plt>
cmp    $0x0,%rax
jne    1193 <rs_monitor+0x33>
movl   $0x0,-0x8(%rbp)
jmp    119a <rs_monitor+0x3a>
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     120a <rs_monitor+0xaa>
mov    -0x8(%rbp),%edi
call   1060 <print_rs_status@plt>
lea    -0xd(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1030 <memset@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11e7 <rs_monitor+0x87>
lea    -0xd(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x23,%edx
mov    $0x2,%ecx
call   1070 <sprintf@plt>
jmp    1201 <rs_monitor+0xa1>
lea    -0xd(%rbp),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x23,%edx
mov    $0x3,%ecx
call   1070 <sprintf@plt>
lea    -0xd(%rbp),%rdi
call   1050 <sys_handle@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
jmp    116f <rs_monitor+0xf>

x86 assembly (clang, -O2):
<rs_monitor>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
lea    0xb(%rsp),%r15
lea    0xe86(%rip),%r14
jmp    118a <rs_monitor+0x2a>
nopl   0x0(%rax)
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    %ebx,%ebp
mov    %ebx,%edi
call   1040 <resource_monitor@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
cmp    %ebx,%ebp
je     1180 <rs_monitor+0x20>
mov    %rax,%r12
mov    %ebx,%edi
call   1060 <print_rs_status@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1030 <memset@plt>
cmp    $0x1,%r12
mov    $0x3,%ecx
sbb    $0x0,%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x23,%edx
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1050 <sys_handle@plt>
jmp    1180 <rs_monitor+0x20>

LLVM IR (-O0):
@.str = [5 x i8] c"%c%d\00"
define i8* @rs_monitor() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5 x i8]
store i32 0, i32* %2
br label %4
4: ; preds = %31, %0
%5 = load i32, i32* %2
store i32 %5, i32* %1
%6 = load i32, i32* %2
%7 = call i64 @resource_monitor(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %4
store i32 0, i32* %2
br label %11
10: ; preds = %4
store i32 1, i32* %2
br label %11
11: ; preds = %10, %9
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load i32, i32* %2
%17 = call i32 @print_rs_status(i32 %16)
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 5)
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%24 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext 35, i32 2)
br label %28
25: ; preds = %15
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%27 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext 35, i32 3)
br label %28
28: ; preds = %25, %22
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%30 = call i32 @sys_handle(i8* %29)
br label %31
31: ; preds = %28, %11
%32 = call i32 @sleep(i32 5)
br label %4
}

LLVM IR (-O2):
@.str = [5 x i8] c"%c%d\00"
define noalias i8* @rs_monitor() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %16, %0
%4 = phi i32 [ 0, %0 ], [ %8, %16 ]
%5 = call i64 @resource_monitor(i32 %4)
%6 = icmp eq i64 %5, 0
%7 = xor i1 %6, true
%8 = zext i1 %7 to i32
%9 = icmp eq i32 %4, %8
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = call i32 @print_rs_status(i32 %8)
%12 = call i32 @memset(i8* %2, i32 0, i32 5)
%13 = select i1 %6, i32 2, i32 3
%14 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext 35, i32 %13)
%15 = call i32 @sys_handle(i8* %2)
br label %16
16: ; preds = %10, %3
%17 = call i32 @sleep(i32 5)
br label %3
}