#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 next_lfg(int offset) {
  static int previous_values[55];
  static size_t cursor = 0;
  static int i = 1;
  int next_val = 0;
  if (i <= 55) {
    next_val = (100003L + i * (-200003L + 300007L * i * i)) % 1000000 - offset;
  } else {
    size_t i_24 = (cursor + 31) % 55;
    size_t i_55 = cursor;
    next_val =
        (previous_values[i_24] + previous_values[i_55] + 1000000) % 1000000 -
        offset;
  }
  previous_values[cursor++] = next_val;
  if (cursor >= 55)
    cursor = 0;
  i++;
  return next_val;
}


x86 assembly (clang, -O0):
<next_lfg>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x37,0x2f0b(%rip)
jg     1167 <next_lfg+0x67>
movslq 0x2efe(%rip),%rax
movslq 0x2ef7(%rip),%rcx
imul   $0x493e7,%rcx,%rcx
movslq 0x2ee9(%rip),%rdx
imul   %rdx,%rcx
add    $0xfffffffffffcf2bd,%rcx
imul   %rcx,%rax
add    $0x186a3,%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
movslq -0x4(%rbp),%rax
sub    %rax,%rdx
mov    %edx,%eax
mov    %eax,-0x8(%rbp)
jmp    11ba <next_lfg+0xba>
mov    0x2fb2(%rip),%rax
add    $0x1f,%rax
mov    $0x37,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x10(%rbp)
mov    0x2f99(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    0x2eaa(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rdx
lea    0x2e9c(%rip),%rcx
add    (%rcx,%rdx,4),%eax
add    $0xf4240,%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
sub    -0x4(%rbp),%edx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%edx
mov    0x2f5c(%rip),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rax,0x2f4e(%rip)
lea    0x2e67(%rip),%rax
mov    %edx,(%rax,%rcx,4)
cmpq   $0x37,0x2f3c(%rip)
37
jb     11f5 <next_lfg+0xf5>
movq   $0x0,0x2f2b(%rip)
mov    0x2e25(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e1c(%rip)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_lfg>:
movslq 0x2f19(%rip),%r8
cmp    $0x37,%r8
jg     115b <next_lfg+0x5b>
mov    %r8,%rax
imul   %r8,%rax
imul   $0x493e7,%rax,%rcx
add    $0xfffffffffffcf2bd,%rcx
imul   %r8,%rcx
add    $0x186a3,%rcx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x12,%rdx
add    %eax,%edx
imul   $0xf4240,%edx,%eax
sub    %eax,%ecx
mov    0x2fc7(%rip),%rsi
jmp    11c4 <next_lfg+0xc4>
mov    0x2fbe(%rip),%rsi
lea    0x1f(%rsi),%rcx
movabs $0x29e4129e4129e413,%rdx
12 e4 29
mov    %rcx,%rax
mul    %rdx
sub    %rdx,%rcx
shr    %rcx
add    %rdx,%rcx
shr    $0x5,%rcx
imul   $0x37,%rcx,%rax
neg    %rax
add    %rsi,%rax
add    $0x1f,%rax
lea    0x2ea8(%rip),%rcx
mov    (%rcx,%rax,4),%eax
mov    (%rcx,%rsi,4),%ecx
add    %ecx,%eax
add    $0xf4240,%eax
movslq %eax,%rcx
imul   $0x431bde83,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rax
add    %edx,%eax
imul   $0xf4240,%eax,%eax
sub    %eax,%ecx
sub    %edi,%ecx
lea    0x1(%rsi),%rax
mov    %rax,0x2f4f(%rip)
lea    0x2e68(%rip),%rdx
mov    %ecx,(%rdx,%rsi,4)
cmp    $0x37,%rax
jb     11ec <next_lfg+0xec>
movq   $0x0,0x2f34(%rip)
add    $0x1,%r8d
mov    %r8d,0x2e29(%rip)
mov    %ecx,%eax
ret

LLVM IR (-O0):
@next_lfg.previous_values = internal global [55 x i32] zeroinitializer
@next_lfg.cursor = internal global i64 0
@next_lfg.i = internal global i32 1
define i32 @next_lfg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* @next_lfg.i
%7 = icmp sle i32 %6, 55
br i1 %7, label %8, label %25
8: ; preds = %1
%9 = load i32, i32* @next_lfg.i
%10 = sext i32 %9 to i64
%11 = load i32, i32* @next_lfg.i
%12 = sext i32 %11 to i64
%13 = mul nsw i64 300007, %12
%14 = load i32, i32* @next_lfg.i
%15 = sext i32 %14 to i64
%16 = mul nsw i64 %13, %15
%17 = add nsw i64 -200003, %16
%18 = mul nsw i64 %10, %17
%19 = add nsw i64 100003, %18
%20 = srem i64 %19, 1000000
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = sub nsw i64 %20, %22
%24 = trunc i64 %23 to i32
store i32 %24, i32* %3
br label %41
25: ; preds = %1
%26 = load i64, i64* @next_lfg.cursor
%27 = add i64 %26, 31
%28 = urem i64 %27, 55
store i64 %28, i64* %4
%29 = load i64, i64* @next_lfg.cursor
store i64 %29, i64* %5
%30 = load i64, i64* %4
%31 = getelementptr inbounds [55 x i32], [55 x i32]* @next_lfg.previous_values, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = load i64, i64* %5
%34 = getelementptr inbounds [55 x i32], [55 x i32]* @next_lfg.previous_values, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = add nsw i32 %32, %35
%37 = add nsw i32 %36, 1000000
%38 = srem i32 %37, 1000000
%39 = load i32, i32* %2
%40 = sub nsw i32 %38, %39
store i32 %40, i32* %3
br label %41
41: ; preds = %25, %8
%42 = load i32, i32* %3
%43 = load i64, i64* @next_lfg.cursor
%44 = add i64 %43, 1
store i64 %44, i64* @next_lfg.cursor
%45 = getelementptr inbounds [55 x i32], [55 x i32]* @next_lfg.previous_values, i64 0, i64 %43
store i32 %42, i32* %45
%46 = load i64, i64* @next_lfg.cursor
%47 = icmp uge i64 %46, 55
br i1 %47, label %48, label %49
48: ; preds = %41
store i64 0, i64* @next_lfg.cursor
br label %49
49: ; preds = %48, %41
%50 = load i32, i32* @next_lfg.i
%51 = add nsw i32 %50, 1
store i32 %51, i32* @next_lfg.i
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@next_lfg.previous_values = internal unnamed_addr global [55 x i32] zeroinitializer
@next_lfg.cursor = internal unnamed_addr global i64 0
@next_lfg.i = internal unnamed_addr global i32 1
define i32 @next_lfg(i32 %0) {
%2 = load i32, i32* @next_lfg.i
%3 = icmp slt i32 %2, 56
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = mul nsw i64 %5, 300007
%7 = mul nsw i64 %6, %5
%8 = add nsw i64 %7, -200003
%9 = mul nsw i64 %8, %5
%10 = add nsw i64 %9, 100003
%11 = srem i64 %10, 1000000
%12 = trunc i64 %11 to i32
%13 = load i64, i64* @next_lfg.cursor
br label %25
14: ; preds = %1
%15 = load i64, i64* @next_lfg.cursor
%16 = add i64 %15, 31
%17 = urem i64 %16, 55
%18 = getelementptr inbounds [55 x i32], [55 x i32]* @next_lfg.previous_values, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = getelementptr inbounds [55 x i32], [55 x i32]* @next_lfg.previous_values, i64 0, i64 %15
%21 = load i32, i32* %20
%22 = add i32 %19, 1000000
%23 = add i32 %22, %21
%24 = srem i32 %23, 1000000
br label %25
25: ; preds = %14, %4
%26 = phi i64 [ %13, %4 ], [ %15, %14 ]
%27 = phi i32 [ %12, %4 ], [ %24, %14 ]
%28 = sub i32 %27, %0
%29 = add i64 %26, 1
store i64 %29, i64* @next_lfg.cursor
%30 = getelementptr inbounds [55 x i32], [55 x i32]* @next_lfg.previous_values, i64 0, i64 %26
store i32 %28, i32* %30
%31 = icmp ugt i64 %29, 54
br i1 %31, label %32, label %33
32: ; preds = %25
store i64 0, i64* @next_lfg.cursor
br label %33
33: ; preds = %32, %25
%34 = add nsw i32 %2, 1
store i32 %34, i32* @next_lfg.i
ret i32 %28
}