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


x86 assembly (clang, -O0):
<HariMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x3fc(%rbp)
cmpl   $0x3e8,-0x3fc(%rbp)
jge    1178 <HariMain+0x48>
movslq -0x3fc(%rbp),%rax
movb   $0x0,-0x3f0(%rbp,%rax,1)
mov    -0x3fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3fc(%rbp)
jmp    1145 <HariMain+0x15>
movl   $0x2,-0x3fc(%rbp)
cmpl   $0x3e8,-0x3fc(%rbp)
jge    1232 <HariMain+0x102>
movslq -0x3fc(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    1219 <HariMain+0xe9>
lea    -0x3f8(%rbp),%rdi
mov    -0x3fc(%rbp),%edx
lea    0xe42(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x3f8(%rbp),%rdi
call   1040 <api_putstr0@plt>
mov    -0x3fc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x400(%rbp)
cmpl   $0x3e8,-0x400(%rbp)
jge    1214 <HariMain+0xe4>
movslq -0x400(%rbp),%rax
movb   $0x1,-0x3f0(%rbp,%rax,1)
01
mov    -0x3fc(%rbp),%eax
add    -0x400(%rbp),%eax
mov    %eax,-0x400(%rbp)
jmp    11de <HariMain+0xae>
jmp    1219 <HariMain+0xe9>
jmp    121e <HariMain+0xee>
mov    -0x3fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3fc(%rbp)
jmp    1182 <HariMain+0x52>
mov    $0x0,%al
call   1030 <api_end@plt>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HariMain>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f8,%rsp
lea    0x10(%rsp),%rdi
mov    $0x3e8,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0x4,%r12d
mov    $0x2,%ebx
lea    0xe8f(%rip),%r14
lea    0x8(%rsp),%r15
jmp    1191 <HariMain+0x51>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0x2,%r12
cmp    $0x3e8,%rbx
je     11d2 <HariMain+0x92>
cmpb   $0x0,0x10(%rsp,%rbx,1)
jne    1180 <HariMain+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1050 <api_putstr0@plt>
cmp    $0x1f3,%rbx
ja     1180 <HariMain+0x40>
mov    %r12,%rax
nopl   0x0(%rax)
movb   $0x1,0x10(%rsp,%rax,1)
add    %rbx,%rax
cmp    $0x3e8,%rax
jb     11c0 <HariMain+0x80>
jmp    1180 <HariMain+0x40>
xor    %eax,%eax
call   1030 <api_end@plt>
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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