#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 */
scalar_t__ check_prime(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int x = 0;
  printf("find the summation of all the primes from zero to: ");
  scanf("%d", &x);
  int i = 0;
  long long sum = 0;
  for (i = 0; i < x; i++) {
    if (check_prime(i) > 0) {
      printf("%d is prime \n", i);
      sum += i;
    }
  }
  printf("%llu\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c8 <main+0x98>
mov    -0xc(%rbp),%edi
call   1030 <check_prime@plt>
cmp    $0x0,%rax
jle    11b5 <main+0x85>
mov    -0xc(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0xc(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ba <main+0x8a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117a <main+0x4a>
mov    -0x18(%rbp),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xeb8(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedb(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ab <main+0x7b>
lea    0xec6(%rip),%r14
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    118e <main+0x5e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jge    11ab <main+0x7b>
mov    %ebx,%edi
call   1030 <check_prime@plt>
test   %rax,%rax
jle    1180 <main+0x50>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    %rbx,%r15
jmp    1180 <main+0x50>
lea    0xe93(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [52 x i8] c"find the summation of all the primes from zero to: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [14 x i8] c"%d is prime \0A\00"
@.str.3 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
store i64 0, i64* %4
store i32 0, i32* %3
br label %7
7: ; preds = %23, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %2
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i32, i32* %3
%13 = call i64 @check_prime(i32 %12)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = load i64, i64* %4
%21 = add nsw i64 %20, %19
store i64 %21, i64* %4
br label %22
22: ; preds = %15, %11
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %7
26: ; preds = %7
%27 = load i64, i64* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [52 x i8] c"find the summation of all the primes from zero to: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [14 x i8] c"%d is prime \0A\00"
@.str.3 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %0, %16
%8 = phi i64 [ %18, %16 ], [ 0, %0 ]
%9 = phi i64 [ %17, %16 ], [ 0, %0 ]
%10 = trunc i64 %8 to i32
%11 = call i64 @check_prime(i32 %10)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%15 = add nsw i64 %9, %8
br label %16
16: ; preds = %7, %13
%17 = phi i64 [ %15, %13 ], [ %9, %7 ]
%18 = add nuw nsw i64 %8, 1
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %7, label %22
22: ; preds = %16, %0
%23 = phi i64 [ 0, %0 ], [ %17, %16 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %23)
ret i32 0
}