#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 atoi(char *);
scalar_t__ find_multiple(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(int *);
int *primes_under(int /*<<< orphan*/ *, int, size_t *);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: %s <N>\n", argv[0]);
    return 1;
  }
  int N = atoi(argv[1]);
  if (N < 7)
    return 1;
  size_t primes_count = 0;
  int *primes = primes_under(NULL, N + 1, &primes_count);
  long sum = 0;
  for (size_t i = 2; i < primes_count - 1; i++)
    sum += find_multiple(primes[i], primes[i + 1]);
  printf("%ld\n", sum);
  free(primes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x48>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1267 <main+0x107>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x7,-0x14(%rbp)
jge    11ce <main+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    1267 <main+0x107>
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%esi
add    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rdx
call   1040 <primes_under@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x2,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1247 <main+0xe7>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    0x4(%rax,%rcx,4),%esi
call   1080 <find_multiple@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11fd <main+0x9d>
mov    -0x30(%rbp),%rsi
lea    0xdbd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11fe <main+0x9e>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    $0x1,%r14d
cmp    $0x7,%eax
jl     121c <main+0xbc>
movq   $0x0,(%rsp)
add    $0x1,%eax
xor    %r14d,%r14d
mov    %rsp,%rdx
xor    %edi,%edi
mov    %eax,%esi
call   1040 <primes_under@plt>
mov    %rax,%r15
mov    (%rsp),%rax
add    $0xfffffffffffffffc,%rax
mov    $0x0,%ebx
cmp    $0xfffffffffffffffc,%rax
ja     11e5 <main+0x85>
mov    $0x2,%eax
xor    %ebx,%ebx
lea    0x1(%rax),%r12
mov    (%r15,%rax,4),%edi
mov    0x4(%r15,%rax,4),%esi
call   1080 <find_multiple@plt>
add    %rax,%rbx
mov    (%rsp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %r12,%rax
cmp    %rcx,%r12
jb     11c0 <main+0x60>
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    121c <main+0xbc>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdef(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %57
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 7
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 1, i32* %3
br label %57
27: ; preds = %19
store i64 0, i64* %7
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
%30 = call i32* @primes_under(i32* null, i32 %29, i64* %7)
store i32* %30, i32** %8
store i64 0, i64* %9
store i64 2, i64* %10
br label %31
31: ; preds = %49, %27
%32 = load i64, i64* %10
%33 = load i64, i64* %7
%34 = sub i64 %33, 1
%35 = icmp ult i64 %32, %34
br i1 %35, label %36, label %52
36: ; preds = %31
%37 = load i32*, i32** %8
%38 = load i64, i64* %10
%39 = getelementptr inbounds i32, i32* %37, i64 %38
%40 = load i32, i32* %39
%41 = load i32*, i32** %8
%42 = load i64, i64* %10
%43 = add i64 %42, 1
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = call i64 @find_multiple(i32 %40, i32 %45)
%47 = load i64, i64* %9
%48 = add nsw i64 %47, %46
store i64 %48, i64* %9
br label %49
49: ; preds = %36
%50 = load i64, i64* %10
%51 = add i64 %50, 1
store i64 %51, i64* %10
br label %31
52: ; preds = %31
%53 = load i64, i64* %9
%54 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %53)
%55 = load i32*, i32** %8
%56 = call i32 @free(i32* %55)
store i32 0, i32* %3
br label %57
57: ; preds = %52, %26, %13
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"usage: %s <N>\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %38
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp slt i32 %12, 7
br i1 %13, label %38, label %14
14: ; preds = %9
%15 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%16 = add nuw nsw i32 %12, 1
%17 = call i32* @primes_under(i32* null, i32 %16, i64* %3)
%18 = load i64, i64* %3
%19 = add i64 %18, -4
%20 = icmp ult i64 %19, -3
br i1 %20, label %25, label %21
21: ; preds = %25, %14
%22 = phi i64 [ 0, %14 ], [ %34, %25 ]
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %22)
%24 = call i32 @free(i32* %17)
br label %38
25: ; preds = %14, %25
%26 = phi i64 [ %30, %25 ], [ 2, %14 ]
%27 = phi i64 [ %34, %25 ], [ 0, %14 ]
%28 = getelementptr inbounds i32, i32* %17, i64 %26
%29 = load i32, i32* %28
%30 = add nuw i64 %26, 1
%31 = getelementptr inbounds i32, i32* %17, i64 %30
%32 = load i32, i32* %31
%33 = call i64 @find_multiple(i32 %29, i32 %32)
%34 = add nsw i64 %33, %27
%35 = load i64, i64* %3
%36 = add i64 %35, -1
%37 = icmp ult i64 %30, %36
br i1 %37, label %25, label %21
38: ; preds = %21, %9, %5
%39 = phi i32 [ 1, %5 ], [ 0, %21 ], [ 1, %9 ]
ret i32 %39
}