#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;
typedef size_t uint16_t;
typedef int int8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ lfsr_calculate(size_t *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int8_t *numbers = (int8_t *)malloc(sizeof(int8_t) * 65535);
  if (numbers == NULL) {
    printf("Memory allocation failed!");
    exit(1);
  }
  memset(numbers, 0, sizeof(int8_t) * 65535);
  uint16_t reg = 0x1;
  uint32_t count = 0;
  int i;
  do {
    count++;
    numbers[reg] = 1;
    if (count < 24) {
      printf("My number is: %u\n", reg);
    } else if (count == 24) {
      printf(" ... etc etc ... \n");
    }
    for (i = 0; i < 32; i++)
      lfsr_calculate(&reg);
  } while (numbers[reg] != 1);
  printf("Got %u numbers before cycling!\n", count);
  if (count == 65535) {
    printf("Congratulations! It works!\n");
  } else {
    printf("Did I miss something?\n");
  }
  free(numbers);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3fffc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <main+0x40>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x3fffc,%edx
call   1050 <memset@plt>
movq   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
cmpl   $0x18,-0x1c(%rbp)
jge    11f8 <main+0x98>
mov    -0x18(%rbp),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1215 <main+0xb5>
cmpl   $0x18,-0x1c(%rbp)
jne    1210 <main+0xb0>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1215 <main+0xb5>
movl   $0x0,-0x20(%rbp)
cmpl   $0x20,-0x20(%rbp)
jge    123d <main+0xdd>
lea    -0x18(%rbp),%rdi
call   1070 <lfsr_calculate@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    121c <main+0xbc>
jmp    1242 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    11bf <main+0x5f>
mov    -0x1c(%rbp),%esi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xffff,-0x1c(%rbp)
jne    1285 <main+0x125>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1293 <main+0x133>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x3fffc,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1354 <main+0x1e4>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x3fffc,%edx
call   1060 <memset@plt>
movq   $0x1,0x8(%rsp)
mov    $0x1,%esi
lea    0xe64(%rip),%r14
lea    0x8(%rsp),%rbx
lea    0xebb(%rip),%r12
xor    %ebp,%ebp
jmp    12e9 <main+0x179>
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    %rbx,%rdi
call   1080 <lfsr_calculate@plt>
mov    0x8(%rsp),%rsi
add    $0x1,%ebp
cmpl   $0x1,(%r15,%rsi,4)
je     1310 <main+0x1a0>
movl   $0x1,(%r15,%rsi,4)
cmp    $0x16,%ebp
jbe    11d0 <main+0x60>
cmp    $0x17,%ebp
jne    11da <main+0x6a>
mov    %r12,%rdi
call   1040 <puts@plt>
jmp    11da <main+0x6a>
lea    0xd15(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffff,%ebp
lea    0xd35(%rip),%rax
lea    0xd18(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xca5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Memory allocation failed!\00"
@.str.1 = [18 x i8] c"My number is: %u\0A\00"
@.str.2 = [19 x i8] c" ... etc etc ... \0A\00"
@.str.3 = [32 x i8] c"Got %u numbers before cycling!\0A\00"
@.str.4 = [28 x i8] c"Congratulations! It works!\0A\00"
@.str.5 = [23 x i8] c"Did I miss something?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 @malloc(i32 262140)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32*, i32** %2
%15 = call i32 @memset(i32* %14, i32 0, i32 262140)
store i64 1, i64* %3
store i32 0, i32* %4
br label %16
16: ; preds = %43, %13
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = load i32*, i32** %2
%20 = load i64, i64* %3
%21 = getelementptr inbounds i32, i32* %19, i64 %20
store i32 1, i32* %21
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 24
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = load i64, i64* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %25)
br label %33
27: ; preds = %16
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 24
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
br label %33
33: ; preds = %32, %24
store i32 0, i32* %5
br label %34
34: ; preds = %39, %33
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 32
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = call i32 @lfsr_calculate(i64* %3)
br label %39
39: ; preds = %37
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %34
42: ; preds = %34
br label %43
43: ; preds = %42
%44 = load i32*, i32** %2
%45 = load i64, i64* %3
%46 = getelementptr inbounds i32, i32* %44, i64 %45
%47 = load i32, i32* %46
%48 = icmp ne i32 %47, 1
br i1 %48, label %16, label %49
49: ; preds = %43
%50 = load i32, i32* %4
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %4
%53 = icmp eq i32 %52, 65535
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %58
56: ; preds = %49
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %56, %54
%59 = load i32*, i32** %2
%60 = call i32 @free(i32* %59)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Memory allocation failed!\00"
@.str.1 = [18 x i8] c"My number is: %u\0A\00"
@.str.3 = [32 x i8] c"Got %u numbers before cycling!\0A\00"
@str = [22 x i8] c"Did I miss something?\00"
@str.6 = [27 x i8] c"Congratulations! It works!\00"
@str.7 = [18 x i8] c" ... etc etc ... \00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i64 @malloc(i32 262140)
%3 = inttoptr i64 %2 to i32*
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 @memset(i32* %3, i32 0, i32 262140)
%10 = bitcast i64* %1 to i8*
store i64 1, i64* %1
br label %11
11: ; preds = %23, %8
%12 = phi i64 [ 1, %8 ], [ %56, %23 ]
%13 = phi i32 [ 0, %8 ], [ %14, %23 ]
%14 = add nuw nsw i32 %13, 1
%15 = getelementptr inbounds i32, i32* %3, i64 %12
store i32 1, i32* %15
%16 = icmp ult i32 %13, 23
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %12)
br label %23
19: ; preds = %11
%20 = icmp eq i32 %14, 24
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
br label %23
23: ; preds = %19, %21, %17
%24 = call i32 @lfsr_calculate(i64* %1)
%25 = call i32 @lfsr_calculate(i64* %1)
%26 = call i32 @lfsr_calculate(i64* %1)
%27 = call i32 @lfsr_calculate(i64* %1)
%28 = call i32 @lfsr_calculate(i64* %1)
%29 = call i32 @lfsr_calculate(i64* %1)
%30 = call i32 @lfsr_calculate(i64* %1)
%31 = call i32 @lfsr_calculate(i64* %1)
%32 = call i32 @lfsr_calculate(i64* %1)
%33 = call i32 @lfsr_calculate(i64* %1)
%34 = call i32 @lfsr_calculate(i64* %1)
%35 = call i32 @lfsr_calculate(i64* %1)
%36 = call i32 @lfsr_calculate(i64* %1)
%37 = call i32 @lfsr_calculate(i64* %1)
%38 = call i32 @lfsr_calculate(i64* %1)
%39 = call i32 @lfsr_calculate(i64* %1)
%40 = call i32 @lfsr_calculate(i64* %1)
%41 = call i32 @lfsr_calculate(i64* %1)
%42 = call i32 @lfsr_calculate(i64* %1)
%43 = call i32 @lfsr_calculate(i64* %1)
%44 = call i32 @lfsr_calculate(i64* %1)
%45 = call i32 @lfsr_calculate(i64* %1)
%46 = call i32 @lfsr_calculate(i64* %1)
%47 = call i32 @lfsr_calculate(i64* %1)
%48 = call i32 @lfsr_calculate(i64* %1)
%49 = call i32 @lfsr_calculate(i64* %1)
%50 = call i32 @lfsr_calculate(i64* %1)
%51 = call i32 @lfsr_calculate(i64* %1)
%52 = call i32 @lfsr_calculate(i64* %1)
%53 = call i32 @lfsr_calculate(i64* %1)
%54 = call i32 @lfsr_calculate(i64* %1)
%55 = call i32 @lfsr_calculate(i64* %1)
%56 = load i64, i64* %1
%57 = getelementptr inbounds i32, i32* %3, i64 %56
%58 = load i32, i32* %57
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %11
60: ; preds = %23
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%62 = icmp eq i32 %14, 65535
%63 = select i1 %62, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0)
%64 = call i32 @puts(i8* dereferenceable(1) %63)
%65 = call i32 @free(i32* %3)
ret i32 0
}