#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*/ brk(int *);
int isprimer(int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int *sbrk(int /*<<< orphan*/);
int main() {
  int *p = sbrk(0);
  int i;
  int r = 0;
  int *q = p;
  for (i = 2; i < 100; i++) {
    r = isprimer(i);
    if (r == 0) {
      brk(q + 1);
      *q = i;
      q = sbrk(0);
    }
  }
  i = 0;
  q = p;
  while (q != sbrk(0)) {
    printf("%d\n", *q++);
  }
  brk(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x2,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11c3 <main+0x83>
mov    -0x14(%rbp),%edi
call   1060 <isprimer@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11b0 <main+0x70>
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   1040 <brk@plt>
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,-0x20(%rbp)
jmp    11b5 <main+0x75>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <main+0x30>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1213 <main+0xd3>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%esi
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <main+0x92>
mov    -0x10(%rbp),%rdi
call   1040 <brk@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,%r14
mov    $0x2,%ebp
mov    %rax,%rbx
jmp    1168 <main+0x28>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x64,%ebp
je     118a <main+0x4a>
mov    %ebp,%edi
call   1060 <isprimer@plt>
test   %eax,%eax
jne    1160 <main+0x20>
lea    0x4(%rbx),%rdi
call   1040 <brk@plt>
mov    %ebp,(%rbx)
xor    %edi,%edi
call   1050 <sbrk@plt>
mov    %rax,%rbx
jmp    1160 <main+0x20>
xor    %edi,%edi
call   1050 <sbrk@plt>
cmp    %rax,%r14
je     11bb <main+0x7b>
lea    0xe63(%rip),%rbx
mov    %r14,%rbp
mov    0x0(%rbp),%esi
add    $0x4,%rbp
mov    %rbx,%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <sbrk@plt>
cmp    %rax,%rbp
jne    11a0 <main+0x60>
mov    %r14,%rdi
call   1040 <brk@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32* @sbrk(i32 0)
store i32* %6, i32** %2
store i32 0, i32* %4
%7 = load i32*, i32** %2
store i32* %7, i32** %5
store i32 2, i32* %3
br label %8
8: ; preds = %24, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i32, i32* %3
%13 = call i32 @isprimer(i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i64 1
%19 = call i32 @brk(i32* %18)
%20 = load i32, i32* %3
%21 = load i32*, i32** %5
store i32 %20, i32* %21
%22 = call i32* @sbrk(i32 0)
store i32* %22, i32** %5
br label %23
23: ; preds = %16, %11
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %8
27: ; preds = %8
store i32 0, i32* %3
%28 = load i32*, i32** %2
store i32* %28, i32** %5
br label %29
29: ; preds = %33, %27
%30 = load i32*, i32** %5
%31 = call i32* @sbrk(i32 0)
%32 = icmp ne i32* %30, %31
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i32*, i32** %5
%35 = getelementptr inbounds i32, i32* %34, i32 1
store i32* %35, i32** %5
%36 = load i32, i32* %34
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %29
38: ; preds = %29
%39 = load i32*, i32** %2
%40 = call i32 @brk(i32* %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32* @sbrk(i32 0)
br label %5
2: ; preds = %14
%3 = tail call i32* @sbrk(i32 0)
%4 = icmp eq i32* %1, %3
br i1 %4, label %25, label %18
5: ; preds = %0, %14
%6 = phi i32* [ %1, %0 ], [ %15, %14 ]
%7 = phi i32 [ 2, %0 ], [ %16, %14 ]
%8 = tail call i32 @isprimer(i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = getelementptr inbounds i32, i32* %6, i64 1
%12 = tail call i32 @brk(i32* %11)
store i32 %7, i32* %6
%13 = tail call i32* @sbrk(i32 0)
br label %14
14: ; preds = %5, %10
%15 = phi i32* [ %13, %10 ], [ %6, %5 ]
%16 = add nuw nsw i32 %7, 1
%17 = icmp eq i32 %16, 100
br i1 %17, label %2, label %5
18: ; preds = %2, %18
%19 = phi i32* [ %20, %18 ], [ %1, %2 ]
%20 = getelementptr inbounds i32, i32* %19, i64 1
%21 = load i32, i32* %19
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = tail call i32* @sbrk(i32 0)
%24 = icmp eq i32* %20, %23
br i1 %24, label %25, label %18
25: ; preds = %18, %2
%26 = tail call i32 @brk(i32* %1)
ret i32 0
}