#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 stats_record {
  int dummy;
};
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
struct stats_record *alloc_stats_record();
int /*<<< orphan*/ free_stats_record(struct stats_record *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stats_collect(struct stats_record *);
int /*<<< orphan*/ stats_print(struct stats_record *, struct stats_record *,
                               int, int /*<<< orphan*/);
int /*<<< orphan*/ swap(struct stats_record **, struct stats_record **);
void stats_poll(int interval, int action, __u32 cfg_opt) {
  struct stats_record *record, *prev;
  record = alloc_stats_record();
  prev = alloc_stats_record();
  stats_collect(record);
  while (1) {
    swap(&prev, &record);
    stats_collect(record);
    stats_print(record, prev, action, cfg_opt);
    sleep(interval);
  }
  free_stats_record(record);
  free_stats_record(prev);
}


x86 assembly (clang, -O0):
<stats_poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1040 <alloc_stats_record@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <alloc_stats_record@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <stats_collect@plt>
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <swap@plt>
mov    -0x18(%rbp),%rdi
call   1030 <stats_collect@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1050 <stats_print@plt>
mov    -0x4(%rbp),%edi
call   1070 <sleep@plt>
jmp    1180 <stats_poll+0x30>

x86 assembly (clang, -O2):
<stats_poll>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <alloc_stats_record@plt>
mov    %rax,%r15
mov    %rax,(%rsp)
xor    %eax,%eax
call   1040 <alloc_stats_record@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
call   1030 <stats_collect@plt>
lea    0x8(%rsp),%r15
mov    %rsp,%r12
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <swap@plt>
mov    (%rsp),%rdi
call   1030 <stats_collect@plt>
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1050 <stats_print@plt>
mov    %ebx,%edi
call   1070 <sleep@plt>
jmp    1190 <stats_poll+0x40>

LLVM IR (-O0):
%struct.stats_record = type { i32 }
define void @stats_poll(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stats_record*
%8 = alloca %struct.stats_record*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call %struct.stats_record* (...) @alloc_stats_record()
store %struct.stats_record* %9, %struct.stats_record** %7
%10 = call %struct.stats_record* (...) @alloc_stats_record()
store %struct.stats_record* %10, %struct.stats_record** %8
%11 = load %struct.stats_record*, %struct.stats_record** %7
%12 = call i32 @stats_collect(%struct.stats_record* %11)
br label %13
13: ; preds = %3, %13
%14 = call i32 @swap(%struct.stats_record** %8, %struct.stats_record** %7)
%15 = load %struct.stats_record*, %struct.stats_record** %7
%16 = call i32 @stats_collect(%struct.stats_record* %15)
%17 = load %struct.stats_record*, %struct.stats_record** %7
%18 = load %struct.stats_record*, %struct.stats_record** %8
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @stats_print(%struct.stats_record* %17, %struct.stats_record* %18, i32 %19, i32 %20)
%22 = load i32, i32* %4
%23 = call i32 @sleep(i32 %22)
br label %13
}

LLVM IR (-O2):
%struct.stats_record = type { i32 }
define void @stats_poll(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.stats_record*
%5 = alloca %struct.stats_record*
%6 = bitcast %struct.stats_record** %4 to i8*
%7 = bitcast %struct.stats_record** %5 to i8*
%8 = tail call %struct.stats_record* (...) @alloc_stats_record()
store %struct.stats_record* %8, %struct.stats_record** %4
%9 = tail call %struct.stats_record* (...) @alloc_stats_record()
store %struct.stats_record* %9, %struct.stats_record** %5
%10 = tail call i32 @stats_collect(%struct.stats_record* %8)
br label %11
11: ; preds = %11, %3
%12 = call i32 @swap(%struct.stats_record** %5, %struct.stats_record** %4)
%13 = load %struct.stats_record*, %struct.stats_record** %4
%14 = call i32 @stats_collect(%struct.stats_record* %13)
%15 = load %struct.stats_record*, %struct.stats_record** %4
%16 = load %struct.stats_record*, %struct.stats_record** %5
%17 = call i32 @stats_print(%struct.stats_record* %15, %struct.stats_record* %16, i32 %1, i32 %2)
%18 = call i32 @sleep(i32 %0)
br label %11
}