#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_WARNING;
int stat(char *, struct stat *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int is_cluster_up(void) {
  struct stat buf;
  int status;
  static int warn_count = 0;
  status = stat("/sys/kernel/config"
                "/cluster",
                &buf);
  if (status)
    return 0;
  status = stat("/sys/kernel/debug"
                "/o2hb",
                &buf);
  if (status) {
    if (!(warn_count++ % 10))
      syslog(LOG_WARNING, "mount debugfs at /sys/kernel/debug");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_cluster_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1151 <is_cluster_up+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <is_cluster_up+0x98>
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b1 <is_cluster_up+0x91>
mov    0x2ec0(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2eb5(%rip)
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a5 <is_cluster_up+0x85>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1040 <syslog@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <is_cluster_up+0x98>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_cluster_up>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1144 <is_cluster_up+0x24>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xed0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %eax,%eax
je     1193 <is_cluster_up+0x73>
mov    0x2ed5(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2ecc(%rip)
imul   $0xcccccccd,%eax,%eax
add    $0x19999998,%eax
ror    %eax
cmp    $0x19999998,%eax
ja     113c <is_cluster_up+0x1c>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
call   1040 <syslog@plt>
jmp    113c <is_cluster_up+0x1c>
mov    $0x1,%ebx
jmp    113c <is_cluster_up+0x1c>

LLVM IR (-O0):
%struct.stat = type { i32 }
@is_cluster_up.warn_count = internal global i32 0
@.str = [27 x i8] c"/sys/kernel/config/cluster\00"
@.str.1 = [23 x i8] c"/sys/kernel/debug/o2hb\00"
@LOG_WARNING = global i32 0
@.str.2 = [35 x i8] c"mount debugfs at /sys/kernel/debug\00"
define i32 @is_cluster_up() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i32
%4 = call i32 @stat(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 0, i32* %1
br label %22
8: ; preds = %0
%9 = call i32 @stat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i32, i32* @is_cluster_up.warn_count
%14 = add nsw i32 %13, 1
store i32 %14, i32* @is_cluster_up.warn_count
%15 = srem i32 %13, 10
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = load i32, i32* @LOG_WARNING
%19 = call i32 @syslog(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %17, %12
store i32 0, i32* %1
br label %22
21: ; preds = %8
store i32 1, i32* %1
br label %22
22: ; preds = %21, %20, %7
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@is_cluster_up.warn_count = internal unnamed_addr global i32 0
@.str = [27 x i8] c"/sys/kernel/config/cluster\00"
@.str.1 = [23 x i8] c"/sys/kernel/debug/o2hb\00"
@LOG_WARNING = global i32 0
@.str.2 = [35 x i8] c"mount debugfs at /sys/kernel/debug\00"
define i32 @is_cluster_up() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %0
%6 = call i32 @stat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = load i32, i32* @is_cluster_up.warn_count
%10 = add nsw i32 %9, 1
store i32 %10, i32* @is_cluster_up.warn_count
%11 = srem i32 %9, 10
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @LOG_WARNING
%15 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %5, %8, %13, %0
%17 = phi i32 [ 0, %0 ], [ 0, %13 ], [ 0, %8 ], [ 1, %5 ]
ret i32 %17
}