#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 *, ...);
int main() {
  const double CROP = 2E16;
  double current, total;
  int count = 1;
  printf("squares         grains         total      ");
  printf("fraction of \n");
  printf("               added         grains      ");
  printf("world total\n");
  total = current = 1.0;
  while (count <= 64) {
    printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total / CROP);
    current = 2.0 * current;
    total = total + current;
    count = count + 1;
  }
  printf("That is all.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xee1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xe8d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe80(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x40,-0x24(%rbp)
jg     11ea <main+0xda>
mov    -0x24(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  0xe5f(%rip),%xmm3
divsd  %xmm3,%xmm2
lea    0xed4(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movsd  0xe4d(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1185 <main+0x75>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf43(%rip),%rdi
call   1030 <puts@plt>
lea    0xef3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf36(%rip),%rdi
call   1030 <puts@plt>
movsd  0xe9d(%rip),%xmm2
mov    $0x1,%ebx
lea    0xef6(%rip),%r14
movapd %xmm2,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
divsd  0xe74(%rip),%xmm2
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    $0x3,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm0
addsd  %xmm0,%xmm2
add    $0x1,%ebx
cmp    $0x41,%ebx
jne    1180 <main+0x60>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [43 x i8] c"squares grains total \00"
@.str.1 = [14 x i8] c"fraction of \0A\00"
@.str.2 = [42 x i8] c" added grains \00"
@.str.3 = [13 x i8] c"world total\0A\00"
@.str.4 = [26 x i8] c"%4d %13.2e %12.2e %12.2e\0A\00"
@.str.5 = [14 x i8] c"That is all.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 0, i32* %1
store double 2.000000e+16, double* %2
store i32 1, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store double 1.000000e+00, double* %3
store double 1.000000e+00, double* %4
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 64
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load i32, i32* %5
%15 = load double, double* %3
%16 = load double, double* %4
%17 = load double, double* %4
%18 = fdiv double %17, 2.000000e+16
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %14, double %15, double %16, double %18)
%20 = load double, double* %3
%21 = fmul double 2.000000e+00, %20
store double %21, double* %3
%22 = load double, double* %4
%23 = load double, double* %3
%24 = fadd double %22, %23
store double %24, double* %4
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %10
27: ; preds = %10
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"squares grains total \00"
@.str.2 = [42 x i8] c" added grains \00"
@.str.4 = [26 x i8] c"%4d %13.2e %12.2e %12.2e\0A\00"
@str = [13 x i8] c"fraction of \00"
@str.6 = [12 x i8] c"world total\00"
@str.7 = [13 x i8] c"That is all.\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 1, %0 ], [ %13, %5 ]
%7 = phi double [ 1.000000e+00, %0 ], [ %12, %5 ]
%8 = phi double [ 1.000000e+00, %0 ], [ %11, %5 ]
%9 = fdiv double %7, 2.000000e+16
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %6, double %8, double %7, double %9)
%11 = fmul double %8, 2.000000e+00
%12 = fadd double %7, %11
%13 = add nuw nsw i32 %6, 1
%14 = icmp eq i32 %13, 65
br i1 %14, label %15, label %5
15: ; preds = %5
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}