#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*/ printf(char *, ...);
int main(void) {
  long int sum = 0;
  int i, j, a[1000 + 1];
  printf("Program that prints the sum of all prime numbers\n "
         "below %d and also prints thier sum\n",
         1000);
  printf("\n\nPrime Numbers below %d: ", 1000);
  for (a[1] = 0, i = 2; i <= 1000; i++)
    a[i] = 1;
  for (i = 2; i <= 1000 / 2; i++)
    for (j = 2; j <= 1000 / i; j++)
      a[i * j] = 0;
  for (i = 1; i <= 1000; i++) {
    if (a[i]) {
      printf("%4d", i);
      sum += i;
    }
  }
  printf("\n");
  printf("\nThe sum of all the prime numbers is: %ld\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xecf(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf12(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xfbc(%rbp)
movl   $0x2,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jg     118b <main+0x7b>
movslq -0x14(%rbp),%rax
movl   $0x1,-0xfc0(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <main+0x51>
movl   $0x2,-0x14(%rbp)
cmpl   $0x1f4,-0x14(%rbp)
jg     11fd <main+0xed>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xfc4(%rbp)
mov    $0x3e8,%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0xfc4(%rbp),%eax
cmp    %ecx,%eax
jg     11ea <main+0xda>
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
movl   $0x0,-0xfc0(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a6 <main+0x96>
jmp    11ef <main+0xdf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1192 <main+0x82>
movl   $0x1,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jg     1253 <main+0x143>
movslq -0x14(%rbp),%rax
cmpl   $0x0,-0xfc0(%rbp,%rax,4)
je     1240 <main+0x130>
mov    -0x14(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x14(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1245 <main+0x135>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1204 <main+0xf4>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xfb0,%rsp
lea    0xedd(%rip),%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf20(%rip),%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0x4(%rsp)
mov    $0x1e,%eax
movaps 0xe9a(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
movups %xmm0,-0x70(%rsp,%rax,4)
movups %xmm0,-0x60(%rsp,%rax,4)
movups %xmm0,-0x50(%rsp,%rax,4)
movups %xmm0,-0x40(%rsp,%rax,4)
movups %xmm0,-0x30(%rsp,%rax,4)
movups %xmm0,-0x20(%rsp,%rax,4)
movups %xmm0,-0x10(%rsp,%rax,4)
movups %xmm0,(%rsp,%rax,4)
add    $0x20,%rax
cmp    $0x3fe,%rax
jne    1170 <main+0x50>
movups %xmm0,0xf88(%rsp)
movabs $0x100000001,%rax
mov    %rax,0xf98(%rsp)
movl   $0x1,0xfa0(%rsp)
mov    $0x2,%r8d
mov    $0x18,%r9d
mov    $0x20,%edi
mov    $0x28,%r11d
mov    $0x10,%r14d
mov    $0x8,%r15d
mov    %rsp,%r10
jmp    1215 <main+0xf5>
add    $0x1,%r8
add    $0xc,%r9
add    $0x10,%rdi
add    $0x14,%r11
add    $0x8,%r14
add    $0x4,%r15
cmp    $0x1f5,%r8
je     12b7 <main+0x197>
mov    $0x3e8,%eax
xor    %edx,%edx
div    %r8d
lea    -0x1(%rax),%rdx
add    $0xfffffffffffffffe,%rax
mov    %edx,%ebx
and    $0x3,%ebx
mov    $0x2,%ecx
cmp    $0x3,%rax
jb     1282 <main+0x162>
and    $0xfffffffffffffffc,%rdx
mov    $0x2,%eax
mov    %r10,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x0,(%rsi,%r14,1)
movl   $0x0,(%rsi,%r9,1)
movl   $0x0,(%rsi,%rdi,1)
movl   $0x0,(%rsi,%r11,1)
add    %rdi,%rsi
lea    0x4(%rax),%rcx
add    $0x2,%rax
cmp    %rdx,%rax
mov    %rcx,%rax
jne    1250 <main+0x130>
test   %rbx,%rbx
je     11f0 <main+0xd0>
imul   %r15,%rcx
lea    (%rsp,%rcx,1),%rax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movl   $0x0,(%rax)
add    $0x1,%rcx
add    %r15,%rax
cmp    %rbx,%rcx
jne    12a0 <main+0x180>
jmp    11f0 <main+0xd0>
mov    $0x1,%ebx
lea    0xdbe(%rip),%r15
xor    %r14d,%r14d
jmp    12dd <main+0x1bd>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x3e9,%rbx
je     12f4 <main+0x1d4>
cmpl   $0x0,(%rsp,%rbx,4)
je     12d0 <main+0x1b0>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    %rbx,%r14
jmp    12d0 <main+0x1b0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd80(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xfb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [86 x i8] c"Program that prints the sum of all prime numbers\0A below %d and also prints thier sum\0A\00"
@.str.1 = [27 x i8] c"\0A\0APrime Numbers below %d: \00"
@.str.2 = [4 x i8] c"%4d\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [43 x i8] c"\0AThe sum of all the prime numbers is: %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1001 x i32]
store i32 0, i32* %1
store i64 0, i64* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0), i32 1000)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 1000)
%8 = getelementptr inbounds [1001 x i32], [1001 x i32]* %5, i64 0, i64 1
store i32 0, i32* %8
store i32 2, i32* %3
br label %9
9: ; preds = %16, %0
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 1000
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1001 x i32], [1001 x i32]* %5, i64 0, i64 %14
store i32 1, i32* %15
br label %16
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %9
19: ; preds = %9
store i32 2, i32* %3
br label %20
20: ; preds = %39, %19
%21 = load i32, i32* %3
%22 = icmp sle i32 %21, 500
br i1 %22, label %23, label %42
23: ; preds = %20
store i32 2, i32* %4
br label %24
24: ; preds = %35, %23
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = sdiv i32 1000, %26
%28 = icmp sle i32 %25, %27
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = mul nsw i32 %30, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1001 x i32], [1001 x i32]* %5, i64 0, i64 %33
store i32 0, i32* %34
br label %35
35: ; preds = %29
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %24
38: ; preds = %24
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %20
42: ; preds = %20
store i32 1, i32* %3
br label %43
43: ; preds = %60, %42
%44 = load i32, i32* %3
%45 = icmp sle i32 %44, 1000
br i1 %45, label %46, label %63
46: ; preds = %43
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1001 x i32], [1001 x i32]* %5, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %59
52: ; preds = %46
%53 = load i32, i32* %3
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = load i64, i64* %2
%58 = add nsw i64 %57, %56
store i64 %58, i64* %2
br label %59
59: ; preds = %52, %46
br label %60
60: ; preds = %59
%61 = load i32, i32* %3
%62 = add nsw i32 %61, 1
store i32 %62, i32* %3
br label %43
63: ; preds = %43
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%65 = load i64, i64* %2
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i64 %65)
ret i32 0
}

LLVM IR (-O2):
@.str = [86 x i8] c"Program that prints the sum of all prime numbers\0A below %d and also prints thier sum\0A\00"
@.str.1 = [27 x i8] c"\0A\0APrime Numbers below %d: \00"
@.str.2 = [4 x i8] c"%4d\00"
@.str.4 = [43 x i8] c"\0AThe sum of all the prime numbers is: %ld\0A\00"
define i32 @main() {
%1 = alloca [1001 x i32]
%2 = bitcast [1001 x i32]* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0), i32 1000)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 1000)
%5 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 1
store i32 0, i32* %5
br label %6
6: ; preds = %6, %0
%7 = phi i64 [ 0, %0 ], [ %28, %6 ]
%8 = or i64 %7, 2
%9 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %8
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %9, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %12
%13 = or i64 %7, 10
%14 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %13
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %14, i64 4
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %17
%18 = or i64 %7, 18
%19 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %18
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %20
%21 = getelementptr inbounds i32, i32* %19, i64 4
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %22
%23 = or i64 %7, 26
%24 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %23
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %25
%26 = getelementptr inbounds i32, i32* %24, i64 4
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %27
%28 = add nuw nsw i64 %7, 32
%29 = icmp eq i64 %28, 992
br i1 %29, label %30, label %6
30: ; preds = %6
%31 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 994
store i32 1, i32* %31
%32 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 995
store i32 1, i32* %32
%33 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 996
store i32 1, i32* %33
%34 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 997
store i32 1, i32* %34
%35 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 998
store i32 1, i32* %35
%36 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 999
store i32 1, i32* %36
%37 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 1000
store i32 1, i32* %37
br label %38
38: ; preds = %30, %77
%39 = phi i64 [ %78, %77 ], [ 2, %30 ]
%40 = trunc i64 %39 to i32
%41 = udiv i32 1000, %40
%42 = zext i32 %41 to i64
%43 = add nsw i64 %42, -1
%44 = add nsw i64 %42, -2
%45 = and i64 %43, 3
%46 = icmp ult i64 %44, 3
br i1 %46, label %66, label %47
47: ; preds = %38
%48 = and i64 %43, -4
br label %49
49: ; preds = %49, %47
%50 = phi i64 [ 2, %47 ], [ %63, %49 ]
%51 = phi i64 [ 0, %47 ], [ %64, %49 ]
%52 = mul nuw nsw i64 %50, %39
%53 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %52
store i32 0, i32* %53
%54 = or i64 %50, 1
%55 = mul nuw nsw i64 %54, %39
%56 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %55
store i32 0, i32* %56
%57 = add nuw nsw i64 %50, 2
%58 = mul nuw nsw i64 %57, %39
%59 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %58
store i32 0, i32* %59
%60 = add nuw nsw i64 %50, 3
%61 = mul nuw nsw i64 %60, %39
%62 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %61
store i32 0, i32* %62
%63 = add nuw nsw i64 %50, 4
%64 = add i64 %51, 4
%65 = icmp eq i64 %64, %48
br i1 %65, label %66, label %49
66: ; preds = %49, %38
%67 = phi i64 [ 2, %38 ], [ %63, %49 ]
%68 = icmp eq i64 %45, 0
br i1 %68, label %77, label %69
69: ; preds = %66, %69
%70 = phi i64 [ %74, %69 ], [ %67, %66 ]
%71 = phi i64 [ %75, %69 ], [ 0, %66 ]
%72 = mul nuw nsw i64 %70, %39
%73 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %72
store i32 0, i32* %73
%74 = add nuw nsw i64 %70, 1
%75 = add i64 %71, 1
%76 = icmp eq i64 %75, %45
br i1 %76, label %77, label %69
77: ; preds = %69, %66
%78 = add nuw nsw i64 %39, 1
%79 = icmp eq i64 %78, 501
br i1 %79, label %80, label %38
80: ; preds = %77, %90
%81 = phi i64 [ %92, %90 ], [ 1, %77 ]
%82 = phi i64 [ %91, %90 ], [ 0, %77 ]
%83 = getelementptr inbounds [1001 x i32], [1001 x i32]* %1, i64 0, i64 %81
%84 = load i32, i32* %83
%85 = icmp eq i32 %84, 0
br i1 %85, label %90, label %86
86: ; preds = %80
%87 = trunc i64 %81 to i32
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %87)
%89 = add nsw i64 %82, %81
br label %90
90: ; preds = %80, %86
%91 = phi i64 [ %89, %86 ], [ %82, %80 ]
%92 = add nuw nsw i64 %81, 1
%93 = icmp eq i64 %92, 1001
br i1 %93, label %94, label %80
94: ; preds = %90
%95 = tail call i32 @putchar(i32 10)
%96 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i64 %91)
ret i32 0
}