#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ hwloc_topology_t;
struct TYPE_2__ {
  int /*<<< orphan*/ *userdata;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
unsigned int hwloc_get_nbobjs_by_depth(int /*<<< orphan*/, unsigned int);
TYPE_1__ *hwloc_get_obj_by_depth(int /*<<< orphan*/, unsigned int,
                                 unsigned int);
unsigned int hwloc_topology_get_depth(int /*<<< orphan*/);
void check(hwloc_topology_t topology) {
  unsigned depth;
  unsigned i, j;
  depth = hwloc_topology_get_depth(topology);
  for (i = 0; i < depth; i++) {
    for (j = 0; j < hwloc_get_nbobjs_by_depth(topology, i); j++) {
      assert(hwloc_get_obj_by_depth(topology, i, j)->userdata == NULL);
    }
  }
}


x86 assembly (clang, -O0):
<check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <hwloc_topology_get_depth@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11ce <check+0x8e>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <hwloc_get_nbobjs_by_depth@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jae    11bb <check+0x7b>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <hwloc_get_obj_by_depth@plt>
cmpq   $0x0,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1170 <check+0x30>
jmp    11c0 <check+0x80>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <check+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
call   1040 <hwloc_topology_get_depth@plt>
test   %eax,%eax
je     11ae <check+0x6e>
mov    %eax,%r14d
xor    %ebp,%ebp
jmp    1168 <check+0x28>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %r14d,%ebp
je     11ae <check+0x6e>
mov    %r15d,%edi
mov    %ebp,%esi
call   1060 <hwloc_get_nbobjs_by_depth@plt>
test   %eax,%eax
je     1160 <check+0x20>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <hwloc_get_obj_by_depth@plt>
xor    %edi,%edi
cmpq   $0x0,(%rax)
sete   %dil
call   1050 <assert@plt>
add    $0x1,%ebx
mov    %r15d,%edi
mov    %ebp,%esi
call   1060 <hwloc_get_nbobjs_by_depth@plt>
cmp    %eax,%ebx
jb     1180 <check+0x40>
jmp    1160 <check+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32* }
define void @check(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @hwloc_topology_get_depth(i32 %6)
store i32 %7, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %33, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %36
12: ; preds = %8
store i32 0, i32* %5
br label %13
13: ; preds = %29, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %2
%16 = load i32, i32* %4
%17 = call i32 @hwloc_get_nbobjs_by_depth(i32 %15, i32 %16)
%18 = icmp ult i32 %14, %17
br i1 %18, label %19, label %32
19: ; preds = %13
%20 = load i32, i32* %2
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call %struct.TYPE_2__* @hwloc_get_obj_by_depth(i32 %20, i32 %21, i32 %22)
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
%25 = load i32*, i32** %24
%26 = icmp eq i32* %25, null
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
br label %29
29: ; preds = %19
%30 = load i32, i32* %5
%31 = add i32 %30, 1
store i32 %31, i32* %5
br label %13
32: ; preds = %13
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add i32 %34, 1
store i32 %35, i32* %4
br label %8
36: ; preds = %8
ret void
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i32* }
define void @check(i32 %0) {
%2 = tail call i32 @hwloc_topology_get_depth(i32 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1, %19
%5 = phi i32 [ %20, %19 ], [ 0, %1 ]
%6 = tail call i32 @hwloc_get_nbobjs_by_depth(i32 %0, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %4, %8
%9 = phi i32 [ %16, %8 ], [ 0, %4 ]
%10 = tail call %struct.TYPE_2__* @hwloc_get_obj_by_depth(i32 %0, i32 %5, i32 %9)
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i64 0, i32 0
%12 = load i32*, i32** %11
%13 = icmp eq i32* %12, null
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = add nuw i32 %9, 1
%17 = tail call i32 @hwloc_get_nbobjs_by_depth(i32 %0, i32 %5)
%18 = icmp ult i32 %16, %17
br i1 %18, label %8, label %19
19: ; preds = %8, %4
%20 = add nuw i32 %5, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %4
22: ; preds = %19, %1
ret void
}