#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__ isPrime(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int stevilo = 2;
  long vsota = 0;
  int meja;
  printf("Please insert upper bound:\n");
  scanf("%d", &meja);
  while (stevilo < meja) {
    if (isPrime(stevilo)) {
      vsota += stevilo;
    }
    stevilo++;
  }
  printf("The sum of the primes below %d is:\n", meja);
  printf("%ld\n", vsota);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a4 <main+0x74>
mov    -0x8(%rbp),%edi
call   1040 <isPrime@plt>
cmp    $0x0,%rax
je     1196 <main+0x66>
movslq -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116c <main+0x3c>
mov    -0x14(%rbp),%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
cmp    $0x3,%esi
jl     11a1 <main+0x61>
mov    $0x2,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
call   1050 <isPrime@plt>
test   %rax,%rax
cmovne %rbx,%rax
add    %rax,%r14
add    $0x1,%rbx
movslq 0x4(%rsp),%rsi
cmp    %rsi,%rbx
jl     1180 <main+0x40>
jmp    11a4 <main+0x64>
xor    %r14d,%r14d
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Please insert upper bound:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [36 x i8] c"The sum of the primes below %d is:\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %2
store i64 0, i64* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 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* %4)
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load i32, i32* %2
%13 = call i64 @isPrime(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = load i64, i64* %3
%19 = add nsw i64 %18, %17
store i64 %19, i64* %3
br label %20
20: ; preds = %15, %11
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %7
23: ; preds = %7
%24 = load i32, i32* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i64, i64* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %26)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [36 x i8] c"The sum of the primes below %d is:\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@str = [27 x i8] c"Please insert upper bound:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 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, 2
br i1 %6, label %7, label %19
7: ; preds = %0, %7
%8 = phi i64 [ %15, %7 ], [ 2, %0 ]
%9 = phi i64 [ %14, %7 ], [ 0, %0 ]
%10 = trunc i64 %8 to i32
%11 = call i64 @isPrime(i32 %10)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i64 0, i64 %8
%14 = add nuw nsw i64 %13, %9
%15 = add nuw nsw i64 %8, 1
%16 = load i32, i32* %1
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %7, label %19
19: ; preds = %7, %0
%20 = phi i64 [ 0, %0 ], [ %14, %7 ]
%21 = phi i32 [ %5, %0 ], [ %16, %7 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %20)
ret i32 0
}