#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 scalar_t__ clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
float CLOCKS_PER_SEC;
int /*<<< orphan*/ SEEK_END;
scalar_t__ clock();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int frequency_of_primes(int);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(void) {
  fprintf(stdout, "clocks_per_sec=%lu\n", CLOCKS_PER_SEC);
  clock_t t;
  int f;
  t = clock();
  printf("Calculating...\n");
  f = frequency_of_primes(999);
  printf("The number of primes lower than 100,000 is: %d\n", f);
  t = clock() - t;
  printf("It took me %lu clicks (%f seconds).\n", (long int)t,
         ((float)t) / CLOCKS_PER_SEC);
  FILE *test;
  long lSize;
  char *buffer;
  size_t result;
  test = fopen("/sys/bus/i2c/devices/0-0054/eeprom", "rb");
  if (test == NULL) {
    fprintf(stderr, "Failed to open file\n");
    exit(-1);
  }
  fseek(test, 0, SEEK_END);
  lSize = ftell(test);
  rewind(test);
  fprintf(stdout, "Filesize: %lu\n", lSize);
  buffer = (char *)malloc(sizeof(char) * lSize);
  if (buffer == NULL) {
    fprintf(stderr, "Memory error\n");
    exit(-1);
  }
  result = fread(buffer, 1, lSize, test);
  fprintf(stdout, "%s\n", buffer);
  fclose(test);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe12(%rip),%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x10(%rbp)
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3e7,%edi
call   10b0 <frequency_of_primes@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
cvtsi2ssq -0x10(%rbp),%xmm0
mov    0x2d94(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf9(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe10(%rip),%rdi
lea    0xe2c(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a5 <main+0xe5>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <rewind@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1329 <main+0x169>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2de9(%rip),%r12
mov    (%r12),%edi
mov    0x2df6(%rip),%r14
movss  (%r14),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe06(%rip),%rsi
mov    $0x1,%al
call   1090 <fprintf@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%rbx
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3e7,%edi
call   10c0 <frequency_of_primes@plt>
lea    0xdec(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%r14),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf1(%rip),%rdi
mov    %rax,%rsi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xe05(%rip),%rdi
lea    0xe21(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1305 <main+0x135>
mov    %rax,%r15
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %r15,%rdi
call   10a0 <ftell@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1080 <rewind@plt>
mov    (%r12),%edi
lea    0xdf7(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14d,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1317 <main+0x147>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    (%r12),%edi
lea    0xddc(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
jmp    1327 <main+0x157>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [20 x i8] c"clocks_per_sec=%lu\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.1 = [16 x i8] c"Calculating...\0A\00"
@.str.2 = [48 x i8] c"The number of primes lower than 100,000 is: %d\0A\00"
@.str.3 = [37 x i8] c"It took me %lu clicks (%f seconds).\0A\00"
@.str.4 = [35 x i8] c"/sys/bus/i2c/devices/0-0054/eeprom\00"
@.str.5 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.6 = [21 x i8] c"Failed to open file\0A\00"
@SEEK_END = global i32 0
@.str.7 = [15 x i8] c"Filesize: %lu\0A\00"
@.str.8 = [14 x i8] c"Memory error\0A\00"
@.str.9 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %1
%8 = load i32, i32* @stdout
%9 = load float, float* @CLOCKS_PER_SEC
%10 = fpext float %9 to double
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %10)
%12 = call i64 (...) @clock()
store i64 %12, i64* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @frequency_of_primes(i32 999)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i64 (...) @clock()
%18 = load i64, i64* %2
%19 = sub nsw i64 %17, %18
store i64 %19, i64* %2
%20 = load i64, i64* %2
%21 = load i64, i64* %2
%22 = sitofp i64 %21 to float
%23 = load float, float* @CLOCKS_PER_SEC
%24 = fdiv float %22, %23
%25 = fpext float %24 to double
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %20, double %25)
%27 = call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %27, i32** %4
%28 = load i32*, i32** %4
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %34
30: ; preds = %0
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %0
%35 = load i32*, i32** %4
%36 = load i32, i32* @SEEK_END
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32*, i32** %4
%39 = call i64 @ftell(i32* %38)
store i64 %39, i64* %5
%40 = load i32*, i32** %4
%41 = call i32 @rewind(i32* %40)
%42 = load i32, i32* @stdout
%43 = load i64, i64* %5
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i64 %43)
%45 = load i64, i64* %5
%46 = mul i64 1, %45
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %6
%50 = load i8*, i8** %6
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %56
52: ; preds = %34
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%55 = call i32 @exit(i32 -1)
unreachable
56: ; preds = %34
%57 = load i8*, i8** %6
%58 = load i64, i64* %5
%59 = load i32*, i32** %4
%60 = call i64 @fread(i8* %57, i32 1, i64 %58, i32* %59)
store i64 %60, i64* %7
%61 = load i32, i32* @stdout
%62 = load i8*, i8** %6
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %62)
%64 = load i32*, i32** %4
%65 = call i32 @fclose(i32* %64)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [20 x i8] c"clocks_per_sec=%lu\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.2 = [48 x i8] c"The number of primes lower than 100,000 is: %d\0A\00"
@.str.3 = [37 x i8] c"It took me %lu clicks (%f seconds).\0A\00"
@.str.4 = [35 x i8] c"/sys/bus/i2c/devices/0-0054/eeprom\00"
@.str.5 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.6 = [21 x i8] c"Failed to open file\0A\00"
@SEEK_END = global i32 0
@.str.7 = [15 x i8] c"Filesize: %lu\0A\00"
@.str.8 = [14 x i8] c"Memory error\0A\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@str = [15 x i8] c"Calculating...\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = load float, float* @CLOCKS_PER_SEC
%3 = fpext float %2 to double
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %3)
%5 = tail call i64 (...) @clock()
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @frequency_of_primes(i32 999)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i64 (...) @clock()
%10 = sub nsw i64 %9, %5
%11 = sitofp i64 %10 to float
%12 = load float, float* @CLOCKS_PER_SEC
%13 = fdiv float %11, %12
%14 = fpext float %13 to double
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %10, double %14)
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %0
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %0
%23 = load i32, i32* @SEEK_END
%24 = tail call i32 @fseek(i32* %16, i32 0, i32 %23)
%25 = tail call i64 @ftell(i32* %16)
%26 = tail call i32 @rewind(i32* %16)
%27 = load i32, i32* @stdout
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i64 %25)
%29 = trunc i64 %25 to i32
%30 = tail call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i8*
%32 = icmp eq i64 %30, 0
br i1 %32, label %33, label %37
33: ; preds = %22
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%36 = tail call i32 @exit(i32 -1)
unreachable
37: ; preds = %22
%38 = tail call i64 @fread(i8* %31, i32 1, i64 %25, i32* %16)
%39 = load i32, i32* @stdout
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %31)
%41 = tail call i32 @fclose(i32* %16)
ret i32 0
}