#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 */
typedef int /*<<< orphan*/ hwloc_topology_t;

/* Variables and functions */
int /*<<< orphan*/ HWLOC_TYPE_DEPTH_PCI_DEVICE;
int hwloc_get_nbobjs_by_depth(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ hwloc_topology_destroy(int /*<<< orphan*/);
int /*<<< orphan*/ hwloc_topology_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ hwloc_topology_load(int /*<<< orphan*/);
int /*<<< orphan*/ hwloc_topology_set_flags(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ hwloc_topology_set_xmlbuffer(int /*<<< orphan*/,
                                                char const *, int);
int /*<<< orphan*/ putenv(char *);
int get_nb_pcidev(unsigned long flags, int thissystem, const char *xmlbuf,
                  int xmlbuflen) {
  int nb;
  hwloc_topology_t topology;
  if (thissystem)
    putenv("HWLOC_THISSYSTEM=1");
  else
    putenv("HWLOC_THISSYSTEM=0");
  hwloc_topology_init(&topology);
  hwloc_topology_set_flags(topology, flags);
  if (xmlbuf)
    hwloc_topology_set_xmlbuffer(topology, xmlbuf, xmlbuflen);
  hwloc_topology_load(topology);
  nb = hwloc_get_nbobjs_by_depth(topology, HWLOC_TYPE_DEPTH_PCI_DEVICE);
  hwloc_topology_destroy(topology);
  return nb;
}


x86 assembly (clang, -O0):
<get_nb_pcidev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a1 <get_nb_pcidev+0x31>
lea    0xe69(%rip),%rdi
call   1050 <putenv@plt>
jmp    11ad <get_nb_pcidev+0x3d>
lea    0xe6b(%rip),%rdi
call   1050 <putenv@plt>
lea    -0x24(%rbp),%rdi
call   1030 <hwloc_topology_init@plt>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1070 <hwloc_topology_set_flags@plt>
cmpq   $0x0,-0x18(%rbp)
je     11dc <get_nb_pcidev+0x6c>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1090 <hwloc_topology_set_xmlbuffer@plt>
mov    -0x24(%rbp),%edi
call   1040 <hwloc_topology_load@plt>
mov    -0x24(%rbp),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
call   1060 <hwloc_get_nbobjs_by_depth@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <hwloc_topology_destroy@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nb_pcidev>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rdi,%rbp
test   %esi,%esi
lea    0xe89(%rip),%rax
lea    0xe6f(%rip),%rdi
cmove  %rax,%rdi
call   1050 <putenv@plt>
lea    0xc(%rsp),%rdi
call   1030 <hwloc_topology_init@plt>
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
call   1070 <hwloc_topology_set_flags@plt>
test   %rbx,%rbx
je     11c4 <get_nb_pcidev+0x54>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1090 <hwloc_topology_set_xmlbuffer@plt>
mov    0xc(%rsp),%edi
call   1040 <hwloc_topology_load@plt>
mov    0xc(%rsp),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
call   1060 <hwloc_get_nbobjs_by_depth@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1080 <hwloc_topology_destroy@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"HWLOC_THISSYSTEM=1\00"
@.str.1 = [19 x i8] c"HWLOC_THISSYSTEM=0\00"
@HWLOC_TYPE_DEPTH_PCI_DEVICE = global i32 0
define i32 @get_nb_pcidev(i64 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i64 %0, i64* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = call i32 @putenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %17
15: ; preds = %4
%16 = call i32 @putenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
%18 = call i32 @hwloc_topology_init(i32* %10)
%19 = load i32, i32* %10
%20 = load i64, i64* %5
%21 = call i32 @hwloc_topology_set_flags(i32 %19, i64 %20)
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i32, i32* %10
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = call i32 @hwloc_topology_set_xmlbuffer(i32 %25, i8* %26, i32 %27)
br label %29
29: ; preds = %24, %17
%30 = load i32, i32* %10
%31 = call i32 @hwloc_topology_load(i32 %30)
%32 = load i32, i32* %10
%33 = load i32, i32* @HWLOC_TYPE_DEPTH_PCI_DEVICE
%34 = call i32 @hwloc_get_nbobjs_by_depth(i32 %32, i32 %33)
store i32 %34, i32* %9
%35 = load i32, i32* %10
%36 = call i32 @hwloc_topology_destroy(i32 %35)
%37 = load i32, i32* %9
ret i32 %37
}

LLVM IR (-O2):
@.str = [19 x i8] c"HWLOC_THISSYSTEM=1\00"
@.str.1 = [19 x i8] c"HWLOC_THISSYSTEM=0\00"
@HWLOC_TYPE_DEPTH_PCI_DEVICE = global i32 0
define i32 @get_nb_pcidev(i64 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp eq i32 %1, 0
%8 = select i1 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0)
%9 = tail call i32 @putenv(i8* %8)
%10 = call i32 @hwloc_topology_init(i32* %5)
%11 = load i32, i32* %5
%12 = call i32 @hwloc_topology_set_flags(i32 %11, i64 %0)
%13 = icmp eq i8* %2, null
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i32, i32* %5
%16 = call i32 @hwloc_topology_set_xmlbuffer(i32 %15, i8* %2, i32 %3)
br label %17
17: ; preds = %14, %4
%18 = load i32, i32* %5
%19 = call i32 @hwloc_topology_load(i32 %18)
%20 = load i32, i32* %5
%21 = load i32, i32* @HWLOC_TYPE_DEPTH_PCI_DEVICE
%22 = call i32 @hwloc_get_nbobjs_by_depth(i32 %20, i32 %21)
%23 = load i32, i32* %5
%24 = call i32 @hwloc_topology_destroy(i32 %23)
ret i32 %22
}