#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 */
struct Node {
  int dummy;
};

/* Variables and functions */
unsigned long add(struct Node *);
struct Node *cons(struct Node *, unsigned int);
int /*<<< orphan*/ printf(char *, unsigned long);
int main(int argc, char *argv[]) {
  struct Node *head = NULL;
  for (unsigned int i = 0; i < 400000000; ++i) {
    head = cons(head, i << 1);
  }
  unsigned long sum = add(head);
  printf("Sum of all elements was: %lu\n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x17d78400,-0x1c(%rbp)
jae    1183 <main+0x53>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
shl    $0x1,%esi
call   1050 <cons@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <main+0x25>
mov    -0x18(%rbp),%rdi
call   1030 <add@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rdi
mov    %ebx,%esi
call   1050 <cons@plt>
add    $0x2,%ebx
cmp    $0x2faf0800,%ebx
jne    1140 <main+0x10>
mov    %rax,%rdi
call   1030 <add@plt>
lea    0xe9c(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.Node = type { i32 }
@.str = [30 x i8] c"Sum of all elements was: %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.Node*
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.Node* null, %struct.Node** %6
store i32 0, i32* %7
br label %9
9: ; preds = %17, %2
%10 = load i32, i32* %7
%11 = icmp ult i32 %10, 400000000
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load %struct.Node*, %struct.Node** %6
%14 = load i32, i32* %7
%15 = shl i32 %14, 1
%16 = call %struct.Node* @cons(%struct.Node* %13, i32 %15)
store %struct.Node* %16, %struct.Node** %6
br label %17
17: ; preds = %12
%18 = load i32, i32* %7
%19 = add i32 %18, 1
store i32 %19, i32* %7
br label %9
20: ; preds = %9
%21 = load %struct.Node*, %struct.Node** %6
%22 = call i64 @add(%struct.Node* %21)
store i64 %22, i64* %8
%23 = load i64, i64* %8
%24 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.Node = type { i32 }
@.str = [30 x i8] c"Sum of all elements was: %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %6
3: ; preds = %6
%4 = tail call i64 @add(%struct.Node* %10)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %4)
ret i32 0
6: ; preds = %2, %6
%7 = phi %struct.Node* [ null, %2 ], [ %10, %6 ]
%8 = phi i32 [ 0, %2 ], [ %11, %6 ]
%9 = shl nuw nsw i32 %8, 1
%10 = tail call %struct.Node* @cons(%struct.Node* %7, i32 %9)
%11 = add nuw nsw i32 %8, 1
%12 = icmp eq i32 %11, 400000000
br i1 %12, label %3, label %6
}