#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 */
struct dfi_cpu {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ dfi_cpu_list();
struct dfi_cpu *util_list_next(int /*<<< orphan*/, struct dfi_cpu *);
struct dfi_cpu *util_list_start(int /*<<< orphan*/);
struct dfi_cpu *dfi_cpu(unsigned int cpu_nr) {
  struct dfi_cpu *cpu;
  unsigned int i = 0;
  for (cpu = util_list_start(dfi_cpu_list()); cpu != NULL;
       cpu = util_list_next(dfi_cpu_list(), cpu)) {
    if (i == cpu_nr)
      return cpu;
    i++;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<dfi_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <dfi_cpu_list@plt>
mov    %eax,%edi
call   1050 <util_list_start@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119c <dfi_cpu+0x6c>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1178 <dfi_cpu+0x48>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a4 <dfi_cpu+0x74>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <dfi_cpu_list@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1030 <util_list_next@plt>
mov    %rax,-0x18(%rbp)
jmp    1154 <dfi_cpu+0x24>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dfi_cpu>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <dfi_cpu_list@plt>
mov    %eax,%edi
call   1050 <util_list_start@plt>
mov    %rax,%r14
test   %rax,%rax
je     1183 <dfi_cpu+0x53>
test   %ebx,%ebx
je     1183 <dfi_cpu+0x53>
add    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <dfi_cpu_list@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <util_list_next@plt>
mov    %rax,%r14
sub    $0x1,%ebx
setb   %al
test   %r14,%r14
je     1183 <dfi_cpu+0x53>
test   %al,%al
je     1160 <dfi_cpu+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dfi_cpu = type { i32 }
define %struct.dfi_cpu* @dfi_cpu(i32 %0) {
%2 = alloca %struct.dfi_cpu*
%3 = alloca i32
%4 = alloca %struct.dfi_cpu*
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%6 = call i32 (...) @dfi_cpu_list()
%7 = call %struct.dfi_cpu* @util_list_start(i32 %6)
store %struct.dfi_cpu* %7, %struct.dfi_cpu** %4
br label %8
8: ; preds = %20, %1
%9 = load %struct.dfi_cpu*, %struct.dfi_cpu** %4
%10 = icmp ne %struct.dfi_cpu* %9, null
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load %struct.dfi_cpu*, %struct.dfi_cpu** %4
store %struct.dfi_cpu* %16, %struct.dfi_cpu** %2
br label %25
17: ; preds = %11
%18 = load i32, i32* %5
%19 = add i32 %18, 1
store i32 %19, i32* %5
br label %20
20: ; preds = %17
%21 = call i32 (...) @dfi_cpu_list()
%22 = load %struct.dfi_cpu*, %struct.dfi_cpu** %4
%23 = call %struct.dfi_cpu* @util_list_next(i32 %21, %struct.dfi_cpu* %22)
store %struct.dfi_cpu* %23, %struct.dfi_cpu** %4
br label %8
24: ; preds = %8
store %struct.dfi_cpu* null, %struct.dfi_cpu** %2
br label %25
25: ; preds = %24, %15
%26 = load %struct.dfi_cpu*, %struct.dfi_cpu** %2
ret %struct.dfi_cpu* %26
}

LLVM IR (-O2):
%struct.dfi_cpu = type { i32 }
define %struct.dfi_cpu* @dfi_cpu(i32 %0) {
%2 = tail call i32 (...) @dfi_cpu_list()
%3 = tail call %struct.dfi_cpu* @util_list_start(i32 %2)
%4 = icmp eq %struct.dfi_cpu* %3, null
%5 = icmp eq i32 %0, 0
%6 = or i1 %4, %5
br i1 %6, label %16, label %7
7: ; preds = %1, %7
%8 = phi i32 [ %10, %7 ], [ 0, %1 ]
%9 = phi %struct.dfi_cpu* [ %12, %7 ], [ %3, %1 ]
%10 = add nuw i32 %8, 1
%11 = tail call i32 (...) @dfi_cpu_list()
%12 = tail call %struct.dfi_cpu* @util_list_next(i32 %11, %struct.dfi_cpu* %9)
%13 = icmp eq %struct.dfi_cpu* %12, null
%14 = icmp eq i32 %10, %0
%15 = select i1 %13, i1 true, i1 %14
br i1 %15, label %16, label %7
16: ; preds = %7, %1
%17 = phi %struct.dfi_cpu* [ %3, %1 ], [ %12, %7 ]
ret %struct.dfi_cpu* %17
}