#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ destroy_store();
int exists(int);
int /*<<< orphan*/ expire_slots();
long get(int);
int get_deadline(int);
int /*<<< orphan*/ init_store();
int /*<<< orphan*/ set(int, long, int, int);
int /*<<< orphan*/ usleep(int);
void test_lots_of_stuff() {
  init_store();
  int count = 1000;
  while (count-- > 0) {
    long t = get_deadline(0);
    int slot = (int)(t % (count + 1));
    if ((t % 2) == 0) {
      set(slot, t, -1, 0);
      assert(exists(slot));
      assert(get(slot) == t);
    } else {
      set(slot, t, get_deadline(slot), 2);
      assert(exists(slot));
      assert(get(slot) == t);
      usleep(1000 * (slot + 1));
      expire_slots();
      assert(!exists(slot));
      assert(get(slot) == 0);
    }
  }
  destroy_store();
}


x86 assembly (clang, -O0):
<test_lots_of_stuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1090 <init_store@plt>
movl   $0x3e8,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
jle    12d7 <test_lots_of_stuff+0x147>
xor    %edi,%edi
call   1070 <get_deadline@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1236 <test_lots_of_stuff+0xa6>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   10a0 <set@plt>
mov    -0x14(%rbp),%edi
call   1080 <exists@plt>
mov    %eax,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%edi
call   1050 <get@plt>
cmp    -0x10(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    12d2 <test_lots_of_stuff+0x142>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <get_deadline@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%ecx
call   10a0 <set@plt>
mov    -0x14(%rbp),%edi
call   1080 <exists@plt>
mov    %eax,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%edi
call   1050 <get@plt>
cmp    -0x10(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
imul   $0x3e8,%eax,%edi
call   10b0 <usleep@plt>
mov    $0x0,%al
call   1060 <expire_slots@plt>
mov    -0x14(%rbp),%edi
call   1080 <exists@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%edi
call   1050 <get@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    11a6 <test_lots_of_stuff+0x16>
mov    $0x0,%al
call   1040 <destroy_store@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_lots_of_stuff>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1090 <init_store@plt>
mov    $0x3e8,%r14d
jmp    1232 <test_lots_of_stuff+0xa2>
cs nopw 0x0(%rax,%rax,1)
call   1070 <get_deadline@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
mov    $0x2,%ecx
call   10a0 <set@plt>
mov    %ebp,%edi
call   1080 <exists@plt>
mov    %eax,%edi
call   1030 <assert@plt>
mov    %ebp,%edi
call   1050 <get@plt>
xor    %edi,%edi
cmp    %rbx,%rax
sete   %dil
call   1030 <assert@plt>
imul   $0x3e8,%ebp,%edi
add    $0x3e8,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1060 <expire_slots@plt>
mov    %ebp,%edi
call   1080 <exists@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
xor    %ebx,%ebx
call   1030 <assert@plt>
mov    %ebp,%edi
call   1050 <get@plt>
xor    %edi,%edi
cmp    %rbx,%rax
sete   %dil
call   1030 <assert@plt>
add    $0xffffffff,%r14d
je     1269 <test_lots_of_stuff+0xd9>
xor    %edi,%edi
call   1070 <get_deadline@plt>
movslq %eax,%rbx
mov    %ebx,%eax
cltd
idiv   %r14d
mov    %edx,%ebp
mov    %edx,%edi
test   $0x1,%bl
jne    11b0 <test_lots_of_stuff+0x20>
mov    %rbx,%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   10a0 <set@plt>
mov    %ebp,%edi
call   1080 <exists@plt>
mov    %eax,%edi
jmp    1212 <test_lots_of_stuff+0x82>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <destroy_store@plt>

LLVM IR (-O0):
define void @test_lots_of_stuff() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = call i32 (...) @init_store()
store i32 1000, i32* %1
br label %5
5: ; preds = %65, %0
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp sgt i32 %6, 0
br i1 %8, label %9, label %66
9: ; preds = %5
%10 = call i32 @get_deadline(i32 0)
%11 = sext i32 %10 to i64
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = load i32, i32* %1
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = srem i64 %12, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %3
%18 = load i64, i64* %2
%19 = srem i64 %18, 2
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %9
%22 = load i32, i32* %3
%23 = load i64, i64* %2
%24 = call i32 @set(i32 %22, i64 %23, i32 -1, i32 0)
%25 = load i32, i32* %3
%26 = call i32 @exists(i32 %25)
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* %3
%29 = call i64 @get(i32 %28)
%30 = load i64, i64* %2
%31 = icmp eq i64 %29, %30
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
br label %65
34: ; preds = %9
%35 = load i32, i32* %3
%36 = load i64, i64* %2
%37 = load i32, i32* %3
%38 = call i32 @get_deadline(i32 %37)
%39 = call i32 @set(i32 %35, i64 %36, i32 %38, i32 2)
%40 = load i32, i32* %3
%41 = call i32 @exists(i32 %40)
%42 = call i32 @assert(i32 %41)
%43 = load i32, i32* %3
%44 = call i64 @get(i32 %43)
%45 = load i64, i64* %2
%46 = icmp eq i64 %44, %45
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
%51 = mul nsw i32 1000, %50
%52 = call i32 @usleep(i32 %51)
%53 = call i32 (...) @expire_slots()
%54 = load i32, i32* %3
%55 = call i32 @exists(i32 %54)
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = load i32, i32* %3
%61 = call i64 @get(i32 %60)
%62 = icmp eq i64 %61, 0
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
br label %65
65: ; preds = %34, %21
br label %5
66: ; preds = %5
%67 = call i32 (...) @destroy_store()
ret void
}

LLVM IR (-O2):
define void @test_lots_of_stuff() {
%1 = tail call i32 (...) @init_store()
br label %2
2: ; preds = %0, %29
%3 = phi i32 [ 999, %0 ], [ %37, %29 ]
%4 = phi i32 [ 1000, %0 ], [ %3, %29 ]
%5 = tail call i32 @get_deadline(i32 0)
%6 = sext i32 %5 to i64
%7 = srem i32 %5, %4
%8 = and i64 %6, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @set(i32 %7, i64 %6, i32 -1, i32 0)
%12 = tail call i32 @exists(i32 %7)
br label %29
13: ; preds = %2
%14 = tail call i32 @get_deadline(i32 %7)
%15 = tail call i32 @set(i32 %7, i64 %6, i32 %14, i32 2)
%16 = tail call i32 @exists(i32 %7)
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i64 @get(i32 %7)
%19 = icmp eq i64 %18, %6
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = mul i32 %7, 1000
%23 = add i32 %22, 1000
%24 = tail call i32 @usleep(i32 %23)
%25 = tail call i32 (...) @expire_slots()
%26 = tail call i32 @exists(i32 %7)
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %13, %10
%30 = phi i32 [ %28, %13 ], [ %12, %10 ]
%31 = phi i64 [ 0, %13 ], [ %6, %10 ]
%32 = tail call i32 @assert(i32 %30)
%33 = tail call i64 @get(i32 %7)
%34 = icmp eq i64 %33, %31
%35 = zext i1 %34 to i32
%36 = tail call i32 @assert(i32 %35)
%37 = add nsw i32 %3, -1
%38 = icmp eq i32 %3, 0
br i1 %38, label %39, label %2
39: ; preds = %29
%40 = tail call i32 (...) @destroy_store()
ret void
}