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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe78(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  0xe51(%rip),%xmm3
divsd  %xmm3,%xmm2
lea    0xea0(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
cmpl   $0x40,-0x24(%rbp)
jge    1226 <main+0x106>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  0xe34(%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),%esi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  0xdf1(%rip),%xmm3
divsd  %xmm3,%xmm2
lea    0xe40(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    11c1 <main+0xa1>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf0e(%rip),%rdi
call   1030 <puts@plt>
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf01(%rip),%rdi
call   1030 <puts@plt>
lea    0xece(%rip),%rbx
movsd  0xe87(%rip),%xmm0
movsd  0xe87(%rip),%xmm2
mov    %rbx,%rdi
mov    $0x1,%esi
movapd %xmm0,%xmm1
mov    $0x3,%al
call   1040 <printf@plt>
mov    $0x2,%ebp
movsd  0xe5f(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe51(%rip),%xmm0
nop
addsd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm2
divsd  0xe40(%rip),%xmm2
mov    %rbx,%rdi
mov    %ebp,%esi
movsd  0x10(%rsp),%xmm0
movsd  %xmm1,0x8(%rsp)
mov    $0x3,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
add    $0x1,%ebp
cmp    $0x41,%ebp
jne    11b0 <main+0x80>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"square\09\09grains\09\09total\09\00"
@.str.1 = [14 x i8] c"fraction of \0A\00"
@.str.2 = [16 x i8] c"\09added 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 = [13 x i8] c"That's 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 ([23 x i8], [23 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 ([16 x i8], [16 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
%10 = load i32, i32* %5
%11 = load double, double* %3
%12 = load double, double* %4
%13 = load double, double* %4
%14 = fdiv double %13, 2.000000e+16
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %10, double %11, double %12, double %14)
br label %16
16: ; preds = %19, %0
%17 = load i32, i32* %5
%18 = icmp slt i32 %17, 64
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
%22 = load double, double* %3
%23 = fmul double 2.000000e+00, %22
store double %23, double* %3
%24 = load double, double* %4
%25 = load double, double* %3
%26 = fadd double %24, %25
store double %26, double* %4
%27 = load i32, i32* %5
%28 = load double, double* %3
%29 = load double, double* %4
%30 = load double, double* %4
%31 = fdiv double %30, 2.000000e+16
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %27, double %28, double %29, double %31)
br label %16
33: ; preds = %16
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"square\09\09grains\09\09total\09\00"
@.str.2 = [16 x i8] c"\09added 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 = [12 x i8] c"That's all.\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 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 ([16 x i8], [16 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))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 1, double 1.000000e+00, double 1.000000e+00, double 5.000000e-17)
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ 1, %0 ], [ %10, %6 ]
%8 = phi double [ 1.000000e+00, %0 ], [ %12, %6 ]
%9 = phi double [ 1.000000e+00, %0 ], [ %11, %6 ]
%10 = add nuw nsw i32 %7, 1
%11 = fmul double %9, 2.000000e+00
%12 = fadd double %8, %11
%13 = fdiv double %12, 2.000000e+16
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %10, double %11, double %12, double %13)
%15 = icmp eq i32 %10, 64
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
%18 = tail call i32 (...) @getchar()
ret i32 0
}