#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 */
unsigned int apparent_processors();
int is_hyperthreaded_x86();
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int, char *);
int main(void) {
  int hyperthreaded;
  unsigned apparent, physical;
  apparent = apparent_processors();
  hyperthreaded = is_hyperthreaded_x86();
  physical = hyperthreaded ? (apparent / 2) : apparent;
  printf("CPUs: %u, physical: %u, hyperthreaded: %s\n", apparent, physical,
         hyperthreaded ? "yes" : "no");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <apparent_processors@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <is_hyperthreaded_x86@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     116b <main+0x3b>
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <main+0x41>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%edi
lea    0xea8(%rip),%rcx
lea    0xe9d(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <apparent_processors@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <is_hyperthreaded_x86@plt>
test   %eax,%eax
lea    0xee5(%rip),%rcx
lea    0xeda(%rip),%rax
cmove  %rcx,%rax
setne  %cl
mov    %ebx,%edx
shr    %cl,%edx
lea    0xe9d(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rcx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"CPUs: %u, physical: %u, hyperthreaded: %s\0A\00"
@.str.1 = [4 x i8] c"yes\00"
@.str.2 = [3 x i8] c"no\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @apparent_processors()
store i32 %5, i32* %3
%6 = call i32 (...) @is_hyperthreaded_x86()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* %3
%11 = udiv i32 %10, 2
br label %14
12: ; preds = %0
%13 = load i32, i32* %3
br label %14
14: ; preds = %12, %9
%15 = phi i32 [ %11, %9 ], [ %13, %12 ]
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%22 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17, i8* %21)
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [43 x i8] c"CPUs: %u, physical: %u, hyperthreaded: %s\0A\00"
@.str.1 = [4 x i8] c"yes\00"
@.str.2 = [3 x i8] c"no\00"
define i32 @main() {
%1 = tail call i32 (...) @apparent_processors()
%2 = tail call i32 (...) @is_hyperthreaded_x86()
%3 = icmp eq i32 %2, 0
%4 = select i1 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%5 = xor i1 %3, true
%6 = zext i1 %5 to i32
%7 = lshr i32 %1, %6
%8 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %7, i8* %4)
ret i32 0
}