#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 /*<<< orphan*/ printf(char *, long long, long long, long long);
long long naive_matrix_multiply_estimated_flops(int quiet) {
  long long muls, divs, adds;
  muls = 512 * 512;
  divs = 512 * 512;
  adds = 512 * 512;
  muls += 512 * 512 * 512;
  adds += 512 * 512 * 512;
  adds += 512 * 512;
  if (!quiet) {
    printf("Estimated flops: adds: %lld muls: %lld divs: %lld\n", adds, muls,
           divs);
  }
  return adds + muls + divs;
}


x86 assembly (clang, -O0):
<naive_matrix_multiply_estimated_flops>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x40000,-0x10(%rbp)
movq   $0x40000,-0x18(%rbp)
movq   $0x40000,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8000000,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8000000,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x40000,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    117f <naive_matrix_multiply_estimated_flops+0x6f>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<naive_matrix_multiply_estimated_flops>:
test   %edi,%edi
je     111a <naive_matrix_multiply_estimated_flops+0xa>
mov    $0x10100000,%eax
ret
push   %rax
lea    0xede(%rip),%rdi
mov    $0x8080000,%esi
mov    $0x8040000,%edx
mov    $0x40000,%ecx
call   1030 <printf@plt>
add    $0x8,%rsp
mov    $0x10100000,%eax
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Estimated flops: adds: %lld muls: %lld divs: %lld\0A\00"
define i64 @naive_matrix_multiply_estimated_flops(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %2
store i64 262144, i64* %3
store i64 262144, i64* %4
store i64 262144, i64* %5
%6 = load i64, i64* %3
%7 = add nsw i64 %6, 134217728
store i64 %7, i64* %3
%8 = load i64, i64* %5
%9 = add nsw i64 %8, 134217728
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = add nsw i64 %10, 262144
store i64 %11, i64* %5
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %1
%15 = load i64, i64* %5
%16 = load i64, i64* %3
%17 = load i64, i64* %4
%18 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %15, i64 %16, i64 %17)
br label %19
19: ; preds = %14, %1
%20 = load i64, i64* %5
%21 = load i64, i64* %3
%22 = add nsw i64 %20, %21
%23 = load i64, i64* %4
%24 = add nsw i64 %22, %23
ret i64 %24
}

LLVM IR (-O2):
@.str = [51 x i8] c"Estimated flops: adds: %lld muls: %lld divs: %lld\0A\00"
define i64 @naive_matrix_multiply_estimated_flops(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 134742016, i64 134479872, i64 262144)
br label %5
5: ; preds = %3, %1
ret i64 269484032
}