#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 /*<<< orphan*/ isPrimer(int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int *sbrk(int /*<<< orphan*/);
int main() {
  int *p = (int *)sbrk(0);
  int *r = p;
  int i = 2;
  for (; i < 100; i++) {
    if (!isPrimer(i)) {
      brk(r + 1);
      *r = i;
      r = sbrk(0);
    }
  }
  r = p;
  while (r != sbrk(0)) {
    printf("%d\n", *r++);
  }
  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   1060 <sbrk@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    11b8 <main+0x78>
mov    -0x1c(%rbp),%edi
call   1030 <isPrimer@plt>
cmp    $0x0,%eax
jne    11a5 <main+0x65>
mov    -0x18(%rbp),%rdi
add    $0x4,%rdi
call   1050 <brk@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %edi,%edi
call   1060 <sbrk@plt>
mov    %rax,-0x18(%rbp)
jmp    11aa <main+0x6a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <main+0x29>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
xor    %edi,%edi
call   1060 <sbrk@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1201 <main+0xc1>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%esi
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
jmp    11c0 <main+0x80>
mov    -0x10(%rbp),%rdi
call   1050 <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   1060 <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   1030 <isPrimer@plt>
test   %eax,%eax
jne    1160 <main+0x20>
lea    0x4(%rbx),%rdi
call   1050 <brk@plt>
mov    %ebp,(%rbx)
xor    %edi,%edi
call   1060 <sbrk@plt>
mov    %rax,%rbx
jmp    1160 <main+0x20>
xor    %edi,%edi
call   1060 <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   1040 <printf@plt>
xor    %edi,%edi
call   1060 <sbrk@plt>
cmp    %rax,%rbp
jne    11a0 <main+0x60>
mov    %r14,%rdi
call   1050 <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
store i32 0, i32* %1
%5 = call i32* @sbrk(i32 0)
store i32* %5, i32** %2
%6 = load i32*, i32** %2
store i32* %6, i32** %3
store i32 2, i32* %4
br label %7
7: ; preds = %22, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 100
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32, i32* %4
%12 = call i32 @isPrimer(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 1
%17 = call i32 @brk(i32* %16)
%18 = load i32, i32* %4
%19 = load i32*, i32** %3
store i32 %18, i32* %19
%20 = call i32* @sbrk(i32 0)
store i32* %20, i32** %3
br label %21
21: ; preds = %14, %10
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %7
25: ; preds = %7
%26 = load i32*, i32** %2
store i32* %26, i32** %3
br label %27
27: ; preds = %31, %25
%28 = load i32*, i32** %3
%29 = call i32* @sbrk(i32 0)
%30 = icmp ne i32* %28, %29
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i32 1
store i32* %33, i32** %3
%34 = load i32, i32* %32
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %27
36: ; preds = %27
%37 = load i32*, i32** %2
%38 = call i32 @brk(i32* %37)
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 [ 2, %0 ], [ %16, %14 ]
%7 = phi i32* [ %1, %0 ], [ %15, %14 ]
%8 = tail call i32 @isPrimer(i32 %6)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = getelementptr inbounds i32, i32* %7, i64 1
%12 = tail call i32 @brk(i32* %11)
store i32 %6, i32* %7
%13 = tail call i32* @sbrk(i32 0)
br label %14
14: ; preds = %5, %10
%15 = phi i32* [ %7, %5 ], [ %13, %10 ]
%16 = add nuw nsw i32 %6, 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
}