#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*/ __sysattr_is_readable(char *, int);
scalar_t__ cpu_online(int);
int /*<<< orphan*/ perror(char *);
int __get_one_smt_state(int core, int threads_per_cpu) {
  int primary_thread = core * threads_per_cpu;
  int smt_state = 0;
  int i;
  if (!__sysattr_is_readable("online", threads_per_cpu)) {
    perror("Cannot retrieve smt state");
    return -2;
  }
  for (i = 0; i < threads_per_cpu; i++) {
    smt_state += cpu_online(primary_thread + i);
  }
  return smt_state;
}


x86 assembly (clang, -O0):
<__get_one_smt_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea7(%rip),%rdi
call   1030 <__sysattr_is_readable@plt>
cmp    $0x0,%eax
jne    117f <__get_one_smt_state+0x4f>
lea    0xe99(%rip),%rdi
call   1050 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11be <__get_one_smt_state+0x8e>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <__get_one_smt_state+0x88>
mov    -0x10(%rbp),%edi
add    -0x18(%rbp),%edi
call   1040 <cpu_online@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1186 <__get_one_smt_state+0x56>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__get_one_smt_state>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xec0(%rip),%rdi
call   1030 <__sysattr_is_readable@plt>
test   %eax,%eax
je     117d <__get_one_smt_state+0x4d>
test   %r14d,%r14d
jle    1174 <__get_one_smt_state+0x44>
imul   %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
call   1040 <cpu_online@plt>
add    %eax,%ebx
add    $0x1,%ebp
add    $0xffffffff,%r14d
jne    1160 <__get_one_smt_state+0x30>
jmp    1176 <__get_one_smt_state+0x46>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    $0xfffffffe,%ebx
jmp    1176 <__get_one_smt_state+0x46>

LLVM IR (-O0):
@.str = [7 x i8] c"online\00"
@.str.1 = [26 x i8] c"Cannot retrieve smt state\00"
define i32 @__get_one_smt_state(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = mul nsw i32 %9, %10
store i32 %11, i32* %6
store i32 0, i32* %7
%12 = load i32, i32* %5
%13 = call i32 @__sysattr_is_readable(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %36
17: ; preds = %2
store i32 0, i32* %8
br label %18
18: ; preds = %31, %17
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i32, i32* %6
%24 = load i32, i32* %8
%25 = add nsw i32 %23, %24
%26 = call i64 @cpu_online(i32 %25)
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %7
br label %31
31: ; preds = %22
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %18
34: ; preds = %18
%35 = load i32, i32* %7
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %15
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [7 x i8] c"online\00"
@.str.1 = [26 x i8] c"Cannot retrieve smt state\00"
define i32 @__get_one_smt_state(i32 %0, i32 %1) {
%3 = mul nsw i32 %1, %0
%4 = tail call i32 @__sysattr_is_readable(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = icmp sgt i32 %1, 0
br i1 %7, label %10, label %19
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %19
10: ; preds = %6, %10
%11 = phi i32 [ %17, %10 ], [ 0, %6 ]
%12 = phi i32 [ %16, %10 ], [ 0, %6 ]
%13 = add nsw i32 %11, %3
%14 = tail call i64 @cpu_online(i32 %13)
%15 = trunc i64 %14 to i32
%16 = add i32 %12, %15
%17 = add nuw nsw i32 %11, 1
%18 = icmp eq i32 %17, %1
br i1 %18, label %19, label %10
19: ; preds = %10, %6, %8
%20 = phi i32 [ -2, %8 ], [ 0, %6 ], [ %16, %10 ]
ret i32 %20
}