#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 */
struct timeval {
  scalar_t__ tv_sec;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *malloc(long);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ strrev(char *);
int main(int argc, char *argv[]) {
  FILE *tfile;
  tfile = fopen("random.txt", "rb");
  clock_t begin, end;
  double time_spent;
  fseek(tfile, 0, SEEK_END);
  long pos = ftell(tfile);
  fseek(tfile, 0, SEEK_SET);
  char *bytes = malloc(pos);
  fread(bytes, pos, 1, tfile);
  fclose(tfile);
  struct timeval tv1, tv2;
  gettimeofday(&tv1, NULL);
  strrev(bytes);
  gettimeofday(&tv2, NULL);
  printf("Total time = %f seconds\n",
         (double)(tv2.tv_usec - tv1.tv_usec) / 1000000 +
             (double)(tv2.tv_sec - tv1.tv_sec));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe5b(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <strrev@plt>
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x50(%rbp),%rax
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xdaa(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x58(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
lea    0xda4(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe68(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r14
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %r15,%rdi
call   10a0 <strrev@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    (%rsp),%rax
mov    0x8(%rsp),%rcx
sub    0x18(%rsp),%rcx
cvtsi2sd %rcx,%xmm1
divsd  0xdc1(%rip),%xmm1
sub    0x10(%rsp),%rax
cvtsi2sd %rax,%xmm0
addsd  %xmm1,%xmm0
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [11 x i8] c"random.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [25 x i8] c"Total time = %f seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i64
%11 = alloca i8*
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %6
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %10
%20 = load i32*, i32** %6
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
%23 = load i64, i64* %10
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %11
%25 = load i8*, i8** %11
%26 = load i64, i64* %10
%27 = load i32*, i32** %6
%28 = call i32 @fread(i8* %25, i64 %26, i32 1, i32* %27)
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
%31 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%32 = load i8*, i8** %11
%33 = call i32 @strrev(i8* %32)
%34 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%38 = load i64, i64* %37
%39 = sub nsw i64 %36, %38
%40 = sitofp i64 %39 to double
%41 = fdiv double %40, 1.000000e+06
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%43 = load i64, i64* %42
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%45 = load i64, i64* %44
%46 = sub nsw i64 %43, %45
%47 = sitofp i64 %46 to double
%48 = fadd double %41, %47
%49 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), double %48)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [11 x i8] c"random.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [25 x i8] c"Total time = %f seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %5, i32 0, i32 %6)
%8 = tail call i64 @ftell(i32* %5)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %5, i32 0, i32 %9)
%11 = tail call i8* @malloc(i64 %8)
%12 = tail call i32 @fread(i8* %11, i64 %8, i32 1, i32* %5)
%13 = tail call i32 @fclose(i32* %5)
%14 = bitcast %struct.timeval* %3 to i8*
%15 = bitcast %struct.timeval* %4 to i8*
%16 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = tail call i32 @strrev(i8* %11)
%18 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%22 = load i64, i64* %21
%23 = sub nsw i64 %20, %22
%24 = sitofp i64 %23 to double
%25 = fdiv double %24, 1.000000e+06
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%27 = load i64, i64* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%29 = load i64, i64* %28
%30 = sub nsw i64 %27, %29
%31 = sitofp i64 %30 to double
%32 = fadd double %25, %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), double %32)
ret i32 0
}