#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 generic_num_packages();
int /*<<< orphan*/ has_htt();
int num_cpus();
int num_threads_per_package();
int num_packages() {
  if ((num_cpus() == -1) || (num_threads_per_package() == -1))
    return generic_num_packages();
  else if (!has_htt())
    return num_cpus();
  else
    return num_cpus() / num_threads_per_package();
}


x86 assembly (clang, -O0):
<num_packages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <num_cpus@plt>
cmp    $0xffffffff,%eax
je     1168 <num_packages+0x28>
mov    $0x0,%al
call   1050 <num_threads_per_package@plt>
cmp    $0xffffffff,%eax
jne    1177 <num_packages+0x37>
mov    $0x0,%al
call   1030 <generic_num_packages@plt>
mov    %eax,-0x4(%rbp)
jmp    11b2 <num_packages+0x72>
mov    $0x0,%al
call   1040 <has_htt@plt>
cmp    $0x0,%eax
jne    1196 <num_packages+0x56>
mov    $0x0,%al
call   1060 <num_cpus@plt>
mov    %eax,-0x4(%rbp)
jmp    11b2 <num_packages+0x72>
mov    $0x0,%al
call   1060 <num_cpus@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <num_threads_per_package@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_packages>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <num_cpus@plt>
cmp    $0xffffffff,%eax
je     118a <num_packages+0x4a>
xor    %eax,%eax
call   1050 <num_threads_per_package@plt>
cmp    $0xffffffff,%eax
je     118a <num_packages+0x4a>
xor    %eax,%eax
call   1040 <has_htt@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <num_cpus@plt>
mov    %eax,%ebx
test   %ebp,%ebp
je     1181 <num_packages+0x41>
xor    %eax,%eax
call   1050 <num_threads_per_package@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <generic_num_packages@plt>

LLVM IR (-O0):
define i32 @num_packages() {
%1 = alloca i32
%2 = call i32 (...) @num_cpus()
%3 = icmp eq i32 %2, -1
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = call i32 (...) @num_threads_per_package()
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %4, %0
%8 = call i32 (...) @generic_num_packages()
store i32 %8, i32* %1
br label %18
9: ; preds = %4
%10 = call i32 (...) @has_htt()
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 (...) @num_cpus()
store i32 %13, i32* %1
br label %18
14: ; preds = %9
%15 = call i32 (...) @num_cpus()
%16 = call i32 (...) @num_threads_per_package()
%17 = sdiv i32 %15, %16
store i32 %17, i32* %1
br label %18
18: ; preds = %14, %12, %7
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
define i32 @num_packages() {
%1 = tail call i32 (...) @num_cpus()
%2 = icmp eq i32 %1, -1
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32 (...) @num_threads_per_package()
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %3, %0
%7 = tail call i32 (...) @generic_num_packages()
br label %15
8: ; preds = %3
%9 = tail call i32 (...) @has_htt()
%10 = icmp eq i32 %9, 0
%11 = tail call i32 (...) @num_cpus()
br i1 %10, label %15, label %12
12: ; preds = %8
%13 = tail call i32 (...) @num_threads_per_package()
%14 = sdiv i32 %11, %13
br label %15
15: ; preds = %8, %12, %6
%16 = phi i32 [ %7, %6 ], [ %14, %12 ], [ %11, %8 ]
ret i32 %16
}