#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 */
scalar_t__ ENOENT;
scalar_t__ errno;
int get_attribute(char *, char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int cpu_online(int thread) {
  char path[128];
  int rc, online;
  sprintf(path,
          "/sys/devices/system/cpu/cpu%d"
          "/online",
          thread);
  rc = get_attribute(path, "%d", &online);
  if (rc && errno == ENOENT)
    return 1;
  if (rc || !online)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<cpu_online>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xec1(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xed3(%rip),%rsi
lea    -0x98(%rbp),%rdx
call   1030 <get_attribute@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
je     1197 <cpu_online+0x77>
mov    0x2e68(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <cpu_online+0x77>
movl   $0x1,-0x4(%rbp)
jmp    11c4 <cpu_online+0xa4>
cmpl   $0x0,-0x94(%rbp)
jne    11b1 <cpu_online+0x91>
cmpl   $0x0,-0x98(%rbp)
jne    11bd <cpu_online+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <cpu_online+0xa4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_online>:
push   %rbx
sub    $0x90,%rsp
mov    %edi,%edx
lea    0xecf(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
lea    0xee0(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <get_attribute@plt>
test   %eax,%eax
je     1171 <cpu_online+0x51>
mov    0x2e83(%rip),%rcx
mov    (%rcx),%rdx
mov    0x2e69(%rip),%rsi
mov    $0x1,%ecx
cmp    (%rsi),%rdx
je     1183 <cpu_online+0x63>
test   %eax,%eax
sete   %al
cmpl   $0x0,0xc(%rsp)
setne  %cl
and    %al,%cl
movzbl %cl,%ecx
mov    %ecx,%eax
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"/sys/devices/system/cpu/cpu%d/online\00"
@.str.1 = [3 x i8] c"%d\00"
@errno = global i64 0
@ENOENT = global i64 0
define i32 @cpu_online(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = call i32 @get_attribute(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOENT
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 1, i32* %2
br label %27
19: ; preds = %14, %1
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22, %19
store i32 0, i32* %2
br label %27
26: ; preds = %22
store i32 1, i32* %2
br label %27
27: ; preds = %26, %25, %18
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [37 x i8] c"/sys/devices/system/cpu/cpu%d/online\00"
@.str.1 = [3 x i8] c"%d\00"
@errno = global i64 0
@ENOENT = global i64 0
define i32 @cpu_online(i32 %0) {
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = call i32 @get_attribute(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp eq i64 %10, %11
br i1 %12, label %18, label %13
13: ; preds = %9, %1
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
%16 = select i1 %8, i1 %15, i1 false
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %13, %9
%19 = phi i32 [ 1, %9 ], [ %17, %13 ]
ret i32 %19
}