#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);
void main() {
  long sum = 0, s = 1;
  int j;
  for (j = 1; j <= 8; j++) {
    printf("\n%ld", sum);
    if (j < 2)
      s *= 4;
    else
      s *= 8;
    sum += s;
  }
  printf("\nsum = %ld\n", s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jg     118a <main+0x7a>
mov    -0x8(%rbp),%rsi
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0x14(%rbp)
jge    1164 <main+0x54>
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    1170 <main+0x60>
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <main+0x1f>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xee8(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    $0x4,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    $0x24,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    $0x124,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    $0x924,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    $0x4924,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    $0x24924,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    $0x124924,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
lea    0xe81(%rip),%rdi
mov    $0x800000,%esi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"\0A%ld\00"
@.str.1 = [12 x i8] c"\0Asum = %ld\0A\00"
define void @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i32
store i64 0, i64* %1
store i64 1, i64* %2
store i32 1, i32* %3
br label %4
4: ; preds = %22, %0
%5 = load i32, i32* %3
%6 = icmp sle i32 %5, 8
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = load i64, i64* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i64, i64* %2
%14 = mul nsw i64 %13, 4
store i64 %14, i64* %2
br label %18
15: ; preds = %7
%16 = load i64, i64* %2
%17 = mul nsw i64 %16, 8
store i64 %17, i64* %2
br label %18
18: ; preds = %15, %12
%19 = load i64, i64* %2
%20 = load i64, i64* %1
%21 = add nsw i64 %20, %19
store i64 %21, i64* %1
br label %22
22: ; preds = %18
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %4
25: ; preds = %4
%26 = load i64, i64* %2
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %26)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\0A%ld\00"
@.str.1 = [12 x i8] c"\0Asum = %ld\0A\00"
define void @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 0)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 36)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 292)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 2340)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 18724)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 149796)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 1198372)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 8388608)
ret void
}