#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 unsigned int time_t;
typedef int /*<<< orphan*/ __u64;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ bpf_map_lookup_elem(unsigned int, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(unsigned int);
unsigned int time(int /*<<< orphan*/ *);
void poll_stats(unsigned int map_fd, unsigned int kill_after_s) {
  time_t started_at = time(NULL);
  __u64 value = 0;
  int key = 0;
  while (!kill_after_s || time(NULL) - started_at <= kill_after_s) {
    sleep(2U);
    assert(bpf_map_lookup_elem(map_fd, &key, &value) == 0);
    printf("icmp \"packet too big\" sent: %10llu pkts\n", value);
  }
}


x86 assembly (clang, -O0):
<poll_stats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x15(%rbp)
je     119c <poll_stats+0x4c>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
sub    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
setbe  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11ac <poll_stats+0x5c>
jmp    11eb <poll_stats+0x9b>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <bpf_map_lookup_elem@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%esi
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
jmp    1178 <poll_stats+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poll_stats>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%r14d
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%r15
mov    %rsp,%r12
lea    0xe79(%rip),%r13
jmp    11c0 <poll_stats+0x70>
nopl   0x0(%rax)
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <bpf_map_lookup_elem@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%esi
mov    %r13,%rdi
call   1030 <printf@plt>
test   %ebx,%ebx
je     1190 <poll_stats+0x40>
xor    %edi,%edi
call   1060 <time@plt>
sub    %r14d,%eax
cmp    %ebx,%eax
jbe    1190 <poll_stats+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"icmp \22packet too big\22 sent: %10llu pkts\0A\00"
define void @poll_stats(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = call i32 @time(i32* null)
store i32 %8, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %20, %2
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = call i32 @time(i32* null)
%14 = load i32, i32* %5
%15 = sub i32 %13, %14
%16 = load i32, i32* %4
%17 = icmp ule i32 %15, %16
br label %18
18: ; preds = %12, %9
%19 = phi i1 [ true, %9 ], [ %17, %12 ]
br i1 %19, label %20, label %29
20: ; preds = %18
%21 = call i32 @sleep(i32 2)
%22 = load i32, i32* %3
%23 = call i64 @bpf_map_lookup_elem(i32 %22, i32* %7, i32* %6)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* %6
%28 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %9
29: ; preds = %18
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"icmp \22packet too big\22 sent: %10llu pkts\0A\00"
define void @poll_stats(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32 @time(i32* null)
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = icmp eq i32 %1, 0
br label %9
9: ; preds = %14, %2
br i1 %8, label %14, label %10
10: ; preds = %9
%11 = call i32 @time(i32* null)
%12 = sub i32 %11, %5
%13 = icmp ugt i32 %12, %1
br i1 %13, label %22, label %14
14: ; preds = %9, %10
%15 = call i32 @sleep(i32 2)
%16 = call i64 @bpf_map_lookup_elem(i32 %0, i32* %4, i32* %3)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %9
22: ; preds = %10
ret void
}