#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(void) {
  const int SQUARES = 64;
  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 < SQUARES) {
    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");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x40,-0x8(%rbp)
movsd  0xed2(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xe8e(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe81(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%esi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  0xe5a(%rip),%xmm3
divsd  %xmm3,%xmm2
lea    0xec8(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
cmpl   $0x40,-0x24(%rbp)
jge    121d <main+0x10d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  0xe3d(%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  0xdfa(%rip),%xmm3
divsd  %xmm3,%xmm2
lea    0xe68(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    11b8 <main+0xa8>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xeeb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf3d(%rip),%rdi
call   1030 <puts@plt>
lea    0xef4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf30(%rip),%rdi
call   1030 <puts@plt>
lea    0xefd(%rip),%rbx
movsd  0xe97(%rip),%xmm0
movsd  0xe97(%rip),%xmm2
mov    %rbx,%rdi
mov    $0x1,%esi
movapd %xmm0,%xmm1
mov    $0x3,%al
call   1040 <printf@plt>
mov    $0x2,%ebp
movsd  0xe6f(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe61(%rip),%xmm0
nop
addsd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm2
divsd  0xe50(%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    11a0 <main+0x80>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [35 x i8] c"square grains total \00"
@.str.2 = [35 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 = [12 x i8] c"That's all.\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 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 ([35 x i8], [35 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))
ret i32 0
}