#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 *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ version0(int, int, double *, double *);
int /*<<< orphan*/ version1(int, int, double *, double *);
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "USAGE: %s SIZE\n", argv[0]);
    exit(1);
  }
  int n = atoi(argv[1]);
  int size = n * n * n;
  int nloops = 20;
  double x0, x1, time_spent0, time_spent1;
  version0(size, nloops, &x0, &time_spent0);
  version1(size, nloops, &x1, &time_spent1);
  if (x0 != x1) {
    printf("Error: x0 != x1\n");
    exit(1);
  }
  printf("%d %.6g %.6g\n", size, time_spent0, time_spent1);
  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     11a6 <main+0x46>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x14,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
lea    -0x28(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1080 <version0@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1040 <version1@plt>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jne    120c <main+0xac>
jp     120c <main+0xac>
jmp    1224 <main+0xc4>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%esi
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
lea    0xde9(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
cmp    $0x2,%edi
jne    11e8 <main+0x78>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
imul   %eax,%ebx
imul   %eax,%ebx
lea    0x18(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x14,%esi
call   1090 <version0@plt>
lea    0x10(%rsp),%rdx
mov    %rsp,%rcx
mov    %ebx,%edi
mov    $0x14,%esi
call   1050 <version1@plt>
movsd  0x18(%rsp),%xmm0
ucomisd 0x10(%rsp),%xmm0
jne    120a <main+0x9a>
jp     120a <main+0x9a>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
lea    0xe39(%rip),%rdi
mov    %ebx,%esi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe05(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"USAGE: %s SIZE\0A\00"
@.str.1 = [17 x i8] c"Error: x0 != x1\0A\00"
@.str.2 = [14 x i8] c"%d %.6g %.6g\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 double
%11 = alloca double
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = load i32, i32* %6
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %6
%31 = mul nsw i32 %29, %30
store i32 %31, i32* %7
store i32 20, i32* %8
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = call i32 @version0(i32 %32, i32 %33, double* %9, double* %11)
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = call i32 @version1(i32 %35, i32 %36, double* %10, double* %12)
%38 = load double, double* %9
%39 = load double, double* %10
%40 = fcmp une double %38, %39
br i1 %40, label %41, label %44
41: ; preds = %22
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %22
%45 = load i32, i32* %7
%46 = load double, double* %11
%47 = load double, double* %12
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %45, double %46, double %47)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"USAGE: %s SIZE\0A\00"
@.str.2 = [14 x i8] c"%d %.6g %.6g\0A\00"
@str = [16 x i8] c"Error: x0 != x1\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = mul nsw i32 %16, %16
%18 = mul nsw i32 %17, %16
%19 = bitcast double* %3 to i8*
%20 = bitcast double* %4 to i8*
%21 = bitcast double* %5 to i8*
%22 = bitcast double* %6 to i8*
%23 = call i32 @version0(i32 %18, i32 20, double* %3, double* %5)
%24 = call i32 @version1(i32 %18, i32 20, double* %4, double* %6)
%25 = load double, double* %3
%26 = load double, double* %4
%27 = fcmp une double %25, %26
br i1 %27, label %28, label %31
28: ; preds = %13
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %13
%32 = load double, double* %5
%33 = load double, double* %6
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %18, double %32, double %33)
ret i32 0
}