#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint64_t;
typedef int uint32_t;
struct timeval {
  int dummy;
};
typedef size_t int8_t;

/* Variables and functions */
double getTimeElapsed(struct timeval *);
int /*<<< orphan*/ printf(char *, ...);
void printResults(struct timeval *begTime, volatile uint8_t *isComposite) {
  uint32_t numOfPrimes = 0;
  uint64_t sumOfPrimes = 0;
  uint32_t maxPrimes[10];
  for (uint32_t i = 100000001 - 2; i > 1; i -= 2) {
    if (!isComposite[i]) {
      if (numOfPrimes < 10)
        maxPrimes[numOfPrimes] = i;
      numOfPrimes++;
      sumOfPrimes += i;
    }
  }
  sumOfPrimes += 2;
  numOfPrimes++;
  printf("Execution time: %fs\n", getTimeElapsed(begTime));
  printf("Found %u primes.\n", numOfPrimes);
  printf("Sum of primes = %lu\n", sumOfPrimes);
  printf("Top ten maximum primes: ");
  for (int8_t i = 9; i >= 0; i--)
    printf("%u%s", maxPrimes[i], i ? ", " : "\n");
}


x86 assembly (clang, -O0):
<printResults>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x5f5e0ff,-0x44(%rbp)
cmpl   $0x1,-0x44(%rbp)
jle    119d <printResults+0x7d>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    $0x0,%eax
jne    118a <printResults+0x6a>
cmpl   $0xa,-0x14(%rbp)
jge    1178 <printResults+0x58>
mov    -0x44(%rbp),%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x44(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    118f <printResults+0x6f>
mov    -0x44(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x44(%rbp)
jmp    1145 <printResults+0x25>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getTimeElapsed@plt>
lea    0xe41(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x9,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jb     124a <printResults+0x12a>
mov    -0x50(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
mov    -0x50(%rbp),%rcx
lea    0xe09(%rip),%rdx
lea    0xe37(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x50(%rbp)
jmp    11fe <printResults+0xde>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printResults>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
xor    %ebx,%ebx
mov    $0x5f5e0ff,%eax
xor    %ebp,%ebp
jmp    1152 <printResults+0x32>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
add    %eax,%ebx
lea    -0x2(%rax),%rcx
cmp    $0x3,%rax
mov    %rcx,%rax
jbe    1165 <printResults+0x45>
cmpl   $0x0,(%rsi,%rax,4)
jne    1145 <printResults+0x25>
cmp    $0xa,%ebp
jge    1140 <printResults+0x20>
movslq %ebp,%rcx
mov    %eax,(%rsp,%rcx,4)
jmp    1140 <printResults+0x20>
add    $0x2,%ebx
add    $0x1,%ebp
call   1040 <getTimeElapsed@plt>
lea    0xe89(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe90(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe92(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x9,%ebp
lea    0xe6d(%rip),%r14
lea    0xe9b(%rip),%r15
lea    0xe8f(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp,%rbp,4),%esi
sub    $0x1,%rbp
mov    %r15,%rdx
cmovb  %r14,%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11d0 <printResults+0xb0>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [21 x i8] c"Execution time: %fs\0A\00"
@.str.1 = [18 x i8] c"Found %u primes.\0A\00"
@.str.2 = [21 x i8] c"Sum of primes = %lu\0A\00"
@.str.3 = [25 x i8] c"Top ten maximum primes: \00"
@.str.4 = [5 x i8] c"%u%s\00"
@.str.5 = [3 x i8] c", \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @printResults(%struct.timeval* %0, i32* %1) {
%3 = alloca %struct.timeval*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [10 x i32]
%8 = alloca i32
%9 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 99999999, i32* %8
br label %10
10: ; preds = %35, %2
%11 = load i32, i32* %8
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %38
13: ; preds = %10
%14 = load i32*, i32** %4
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load volatile i32, i32* %17
%19 = icmp ne i32 %18, 0
br i1 %19, label %34, label %20
20: ; preds = %13
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* %8
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %26
store i32 %24, i32* %27
br label %28
28: ; preds = %23, %20
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
%31 = load i32, i32* %8
%32 = load i32, i32* %6
%33 = add nsw i32 %32, %31
store i32 %33, i32* %6
br label %34
34: ; preds = %28, %13
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = sub nsw i32 %36, 2
store i32 %37, i32* %8
br label %10
38: ; preds = %10
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 2
store i32 %40, i32* %6
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
%43 = load %struct.timeval*, %struct.timeval** %3
%44 = call double @getTimeElapsed(%struct.timeval* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %44)
%46 = load i32, i32* %5
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %6
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i64 9, i64* %9
br label %51
51: ; preds = %63, %38
%52 = load i64, i64* %9
%53 = icmp uge i64 %52, 0
br i1 %53, label %54, label %66
54: ; preds = %51
%55 = load i64, i64* %9
%56 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = load i64, i64* %9
%59 = icmp ne i64 %58, 0
%60 = zext i1 %59 to i64
%61 = select i1 %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %57, i8* %61)
br label %63
63: ; preds = %54
%64 = load i64, i64* %9
%65 = add i64 %64, -1
store i64 %65, i64* %9
br label %51
66: ; preds = %51
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [21 x i8] c"Execution time: %fs\0A\00"
@.str.1 = [18 x i8] c"Found %u primes.\0A\00"
@.str.2 = [21 x i8] c"Sum of primes = %lu\0A\00"
@.str.3 = [25 x i8] c"Top ten maximum primes: \00"
@.str.4 = [5 x i8] c"%u%s\00"
@.str.5 = [3 x i8] c", \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @printResults(%struct.timeval* %0, i32* %1) {
%3 = alloca [10 x i32]
%4 = bitcast [10 x i32]* %3 to i8*
br label %13
5: ; preds = %32
%6 = add nsw i32 %34, 2
%7 = add nsw i32 %33, 1
%8 = tail call double @getTimeElapsed(%struct.timeval* %0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %37
13: ; preds = %2, %32
%14 = phi i64 [ 99999999, %2 ], [ %35, %32 ]
%15 = phi i32 [ 0, %2 ], [ %34, %32 ]
%16 = phi i32 [ 0, %2 ], [ %33, %32 ]
%17 = getelementptr inbounds i32, i32* %1, i64 %14
%18 = load volatile i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %13
%21 = icmp slt i32 %16, 10
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = trunc i64 %14 to i32
br label %28
24: ; preds = %20
%25 = sext i32 %16 to i64
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %25
%27 = trunc i64 %14 to i32
store i32 %27, i32* %26
br label %28
28: ; preds = %22, %24
%29 = phi i32 [ %23, %22 ], [ %27, %24 ]
%30 = add nsw i32 %16, 1
%31 = add nsw i32 %29, %15
br label %32
32: ; preds = %13, %28
%33 = phi i32 [ %16, %13 ], [ %30, %28 ]
%34 = phi i32 [ %15, %13 ], [ %31, %28 ]
%35 = add nsw i64 %14, -2
%36 = icmp ugt i64 %14, 3
br i1 %36, label %13, label %5
37: ; preds = %37, %5
%38 = phi i64 [ 9, %5 ], [ %44, %37 ]
%39 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = icmp eq i64 %38, 0
%42 = select i1 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %40, i8* %42)
%44 = add i64 %38, -1
br label %37
}