#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 int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int next_seq(int);
void init_memory(void *addr, uint32_t numwords) {
  assert(numwords >= 1);
  uint32_t *wordaddr = (uint32_t *)addr;
  wordaddr[0] = numwords;
  for (int i = 1; i < numwords; i++) {
    wordaddr[i] =
        (i == 1) ? ((uint32_t)addr % 1000) : next_seq(wordaddr[i - 1]);
  }
}


x86 assembly (clang, -O0):
<init_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <init_memory+0x98>
cmpl   $0x1,-0x1c(%rbp)
jne    1184 <init_memory+0x64>
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    %eax,-0x20(%rbp)
jmp    119c <init_memory+0x7c>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <next_seq@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <init_memory+0x38>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_memory>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %edi,%edi
test   %esi,%esi
setg   %dil
call   1030 <assert@plt>
mov    %ebp,(%r14)
cmp    $0x2,%ebp
jl     1184 <init_memory+0x64>
movslq %r14d,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x4(%r14)
cmp    $0x2,%ebp
je     1184 <init_memory+0x64>
mov    %ebp,%ebp
mov    $0x2,%ebx
nopl   (%rax)
mov    %eax,%edi
call   1040 <next_seq@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <init_memory+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @init_memory(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 1
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %3
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %5
%13 = load i32, i32* %4
%14 = load i32*, i32** %5
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 %13, i32* %15
store i32 1, i32* %6
br label %16
16: ; preds = %41, %2
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %44
20: ; preds = %16
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = ptrtoint i8* %24 to i32
%26 = srem i32 %25, 1000
br label %35
27: ; preds = %20
%28 = load i32*, i32** %5
%29 = load i32, i32* %6
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %28, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @next_seq(i32 %33)
br label %35
35: ; preds = %27, %23
%36 = phi i32 [ %26, %23 ], [ %34, %27 ]
%37 = load i32*, i32** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 %36, i32* %40
br label %41
41: ; preds = %35
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %16
44: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @init_memory(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = bitcast i8* %0 to i32*
store i32 %1, i32* %6
%7 = icmp sgt i32 %1, 1
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = ptrtoint i8* %0 to i64
%10 = trunc i64 %9 to i32
%11 = srem i32 %10, 1000
%12 = zext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 4
%14 = bitcast i8* %13 to i32*
store i32 %11, i32* %14
%15 = icmp eq i32 %1, 2
br i1 %15, label %16, label %17
16: ; preds = %17, %8, %2
ret void
17: ; preds = %8, %17
%18 = phi i32 [ %20, %17 ], [ %11, %8 ]
%19 = phi i64 [ %22, %17 ], [ 2, %8 ]
%20 = tail call i32 @next_seq(i32 %18)
%21 = getelementptr inbounds i32, i32* %6, i64 %19
store i32 %20, i32* %21
%22 = add nuw nsw i64 %19, 1
%23 = icmp eq i64 %22, %12
br i1 %23, label %16, label %17
}