#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*/ EXIT_FAILURE;
scalar_t__ atoll(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ is_prime(long long);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("Usage: ./bin [number]\n");
    exit(EXIT_FAILURE);
  }
  long long int num = (long long int)atoll(argv[1]);
  long long int sum = 0;
  for (long long int i = 2; i < num; i++) {
    if (is_prime(i)) {
      sum += i;
    }
  }
  printf("The sum of primes below %llu is %llu.\n", num, sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117c <main+0x3c>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoll@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11e0 <main+0xa0>
mov    -0x28(%rbp),%rdi
call   1050 <is_prime@plt>
cmp    $0x0,%rax
je     11ca <main+0x8a>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11cf <main+0x8f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    119d <main+0x5d>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x1,%edi
jle    11bc <main+0x6c>
mov    0x8(%rsi),%rdi
call   1050 <atoll@plt>
mov    %rax,%r14
cmp    $0x3,%rax
jl     119d <main+0x4d>
mov    $0x2,%ebx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <is_prime@plt>
test   %rax,%rax
cmovne %rbx,%rax
add    %rax,%r15
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <main+0x30>
jmp    11a0 <main+0x50>
xor    %r15d,%r15d
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Usage: ./bin [number]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"The sum of primes below %llu is %llu.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @atoll(i8* %18)
store i64 %19, i64* %6
store i64 0, i64* %7
store i64 2, i64* %8
br label %20
20: ; preds = %33, %15
%21 = load i64, i64* %8
%22 = load i64, i64* %6
%23 = icmp slt i64 %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i64, i64* %8
%26 = call i64 @is_prime(i64 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i64, i64* %8
%30 = load i64, i64* %7
%31 = add nsw i64 %30, %29
store i64 %31, i64* %7
br label %32
32: ; preds = %28, %24
br label %33
33: ; preds = %32
%34 = load i64, i64* %8
%35 = add nsw i64 %34, 1
store i64 %35, i64* %8
br label %20
36: ; preds = %20
%37 = load i64, i64* %6
%38 = load i64, i64* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i64 %37, i64 %38)
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"The sum of primes below %llu is %llu.\0A\00"
@str = [22 x i8] c"Usage: ./bin [number]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atoll(i8* %10)
%12 = icmp sgt i64 %11, 2
br i1 %12, label %16, label %13
13: ; preds = %16, %8
%14 = phi i64 [ 0, %8 ], [ %22, %16 ]
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i64 %11, i64 %14)
ret i32 0
16: ; preds = %8, %16
%17 = phi i64 [ %23, %16 ], [ 2, %8 ]
%18 = phi i64 [ %22, %16 ], [ 0, %8 ]
%19 = tail call i64 @is_prime(i64 %17)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i64 0, i64 %17
%22 = add nuw nsw i64 %21, %18
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %11
br i1 %24, label %13, label %16
}