#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*/ api_end();
int /*<<< orphan*/ api_initmalloc();
char *api_malloc(int);
int /*<<< orphan*/ api_putstr0(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void HariMain(void) {
  char *flag, s[8];
  int i, j;
  api_initmalloc();
  flag = api_malloc(10000);
  for (i = 0; i < 10000; i++) {
    flag[i] = 0;
  }
  for (i = 2; i < 10000; i++) {
    if (flag[i] == 0) {
      sprintf(s, "%d ", i);
      api_putstr0(s);
      for (j = i * 2; j < 10000; j += i) {
        flag[j] = 1;
      }
    }
  }
  api_end();
}


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <api_initmalloc@plt>
mov    $0x2710,%edi
call   1050 <api_malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jge    119b <HariMain+0x4b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1174 <HariMain+0x24>
movl   $0x2,-0x14(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jge    1228 <HariMain+0xd8>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1215 <HariMain+0xc5>
lea    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe2e(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x10(%rbp),%rdi
call   1060 <api_putstr0@plt>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2710,-0x18(%rbp)
jge    1210 <HariMain+0xc0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11e9 <HariMain+0x99>
jmp    1215 <HariMain+0xc5>
jmp    121a <HariMain+0xca>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a2 <HariMain+0x52>
mov    $0x0,%al
call   1030 <api_end@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HariMain>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <api_initmalloc@plt>
mov    $0x2710,%edi
call   1050 <api_malloc@plt>
mov    %rax,%r14
mov    $0x2710,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x4,%r13d
mov    $0x2,%ebx
lea    0xe5e(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11c1 <HariMain+0x61>
nopl   0x0(%rax)
add    $0x1,%rbx
add    $0x2,%r13
cmp    $0x2710,%rbx
je     1202 <HariMain+0xa2>
cmpb   $0x0,(%r14,%rbx,1)
jne    11b0 <HariMain+0x50>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1080 <sprintf@plt>
mov    %r12,%rdi
call   1070 <api_putstr0@plt>
cmp    $0x1387,%rbx
ja     11b0 <HariMain+0x50>
mov    %r13,%rax
nopl   0x0(%rax)
movb   $0x1,(%r14,%rax,1)
add    %rbx,%rax
cmp    $0x2710,%rax
jb     11f0 <HariMain+0x90>
jmp    11b0 <HariMain+0x50>
xor    %eax,%eax
call   1030 <api_end@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
define void @HariMain() {
%1 = alloca i8*
%2 = alloca [8 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @api_initmalloc()
%6 = call i8* @api_malloc(i32 10000)
store i8* %6, i8** %1
store i32 0, i32* %3
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 10000
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = load i8*, i8** %1
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 0, i8* %14
br label %15
15: ; preds = %10
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %7
18: ; preds = %7
store i32 2, i32* %3
br label %19
19: ; preds = %52, %18
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 10000
br i1 %21, label %22, label %55
22: ; preds = %19
%23 = load i8*, i8** %1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %51
30: ; preds = %22
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%32 = load i32, i32* %3
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%35 = call i32 @api_putstr0(i8* %34)
%36 = load i32, i32* %3
%37 = mul nsw i32 %36, 2
store i32 %37, i32* %4
br label %38
38: ; preds = %46, %30
%39 = load i32, i32* %4
%40 = icmp slt i32 %39, 10000
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i8*, i8** %1
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 1, i8* %45
br label %46
46: ; preds = %41
%47 = load i32, i32* %3
%48 = load i32, i32* %4
%49 = add nsw i32 %48, %47
store i32 %49, i32* %4
br label %38
50: ; preds = %38
br label %51
51: ; preds = %50, %22
br label %52
52: ; preds = %51
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %19
55: ; preds = %19
%56 = call i32 (...) @api_end()
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define void @HariMain() {
%1 = alloca [8 x i8]
%2 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @api_initmalloc()
%4 = tail call i8* @api_malloc(i32 10000)
br label %5
5: ; preds = %0, %21
%6 = phi i64 [ 2, %0 ], [ %22, %21 ]
%7 = phi i64 [ 4, %0 ], [ %23, %21 ]
%8 = getelementptr inbounds i8, i8* %4, i64 %6
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %5
%12 = trunc i64 %6 to i32
%13 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @api_putstr0(i8* %2)
%15 = icmp ult i64 %6, 5000
br i1 %15, label %16, label %21
16: ; preds = %11, %16
%17 = phi i64 [ %19, %16 ], [ %7, %11 ]
%18 = getelementptr inbounds i8, i8* %4, i64 %17
store i8 1, i8* %18
%19 = add nuw nsw i64 %17, %6
%20 = icmp ult i64 %19, 10000
br i1 %20, label %16, label %21
21: ; preds = %16, %11, %5
%22 = add nuw nsw i64 %6, 1
%23 = add nuw nsw i64 %7, 2
%24 = icmp eq i64 %22, 10000
br i1 %24, label %25, label %5
25: ; preds = %21
%26 = call i32 (...) @api_end()
ret void
}