#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 *, unsigned int, unsigned int);
void problem6(unsigned limit) {
  unsigned sumOfSquares = 0;
  unsigned squareOfSums = 0;
  for (int i = 1; i <= limit; ++i)
    sumOfSquares += i * i;
  for (int i = 1; i <= limit; ++i)
    squareOfSums += i;
  squareOfSums *= squareOfSums;
  printf("Problem 6: The difference between the sum of the squares of the "
         "first %u natural numbers and the square of their sum is %u.\n",
         limit, squareOfSums - sumOfSquares);
}


x86 assembly (clang, -O0):
<problem6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     1157 <problem6+0x47>
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <problem6+0x20>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     1181 <problem6+0x71>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <problem6+0x4e>
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    -0x8(%rbp),%edx
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<problem6>:
mov    %edi,%esi
test   %edi,%edi
je     114c <problem6+0x3c>
lea    -0x1(%rsi),%eax
lea    -0x2(%rsi),%ecx
imul   %rax,%rcx
lea    -0x3(%rsi),%eax
imul   %rcx,%rax
shr    %rax
imul   $0xaaaaaaaa,%eax,%eax
shr    %rcx
lea    (%rcx,%rcx,4),%edx
sub    %edx,%eax
lea    0x0(,%rsi,4),%edx
sub    %edx,%eax
add    $0x3,%eax
lea    (%rcx,%rsi,2),%edx
add    $0xffffffff,%edx
jmp    1150 <problem6+0x40>
xor    %eax,%eax
xor    %edx,%edx
imul   %edx,%edx
add    %eax,%edx
lea    0xea4(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [125 x i8] c"Problem 6: The difference between the sum of the squares of the first %u natural numbers and the square of their sum is %u.\0A\00"
define void @problem6(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 1, i32* %5
br label %7
7: ; preds = %17, %1
%8 = load i32, i32* %5
%9 = load i32, i32* %2
%10 = icmp ule i32 %8, %9
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i32, i32* %5
%13 = load i32, i32* %5
%14 = mul nsw i32 %12, %13
%15 = load i32, i32* %3
%16 = add i32 %15, %14
store i32 %16, i32* %3
br label %17
17: ; preds = %11
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %7
20: ; preds = %7
store i32 1, i32* %6
br label %21
21: ; preds = %29, %20
%22 = load i32, i32* %6
%23 = load i32, i32* %2
%24 = icmp ule i32 %22, %23
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i32, i32* %6
%27 = load i32, i32* %4
%28 = add i32 %27, %26
store i32 %28, i32* %4
br label %29
29: ; preds = %25
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %21
32: ; preds = %21
%33 = load i32, i32* %4
%34 = load i32, i32* %4
%35 = mul i32 %34, %33
store i32 %35, i32* %4
%36 = load i32, i32* %2
%37 = load i32, i32* %4
%38 = load i32, i32* %3
%39 = sub i32 %37, %38
%40 = call i32 @printf(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %39)
ret void
}

LLVM IR (-O2):
@.str = [125 x i8] c"Problem 6: The difference between the sum of the squares of the first %u natural numbers and the square of their sum is %u.\0A\00"
define void @problem6(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %32, label %3
3: ; preds = %1
%4 = add i32 %0, -1
%5 = zext i32 %4 to i33
%6 = add i32 %0, -2
%7 = zext i32 %6 to i33
%8 = mul i33 %5, %7
%9 = add i32 %0, -3
%10 = zext i32 %9 to i33
%11 = mul i33 %8, %10
%12 = lshr i33 %11, 1
%13 = trunc i33 %12 to i32
%14 = mul i32 %13, -1431655766
%15 = lshr i33 %8, 1
%16 = trunc i33 %15 to i32
%17 = mul i32 %16, -5
%18 = add i32 %14, %17
%19 = mul i32 %0, -4
%20 = add i32 %18, %19
%21 = add i32 %20, 3
%22 = shl i32 %0, 1
%23 = add i32 %0, -1
%24 = zext i32 %23 to i33
%25 = add i32 %0, -2
%26 = zext i32 %25 to i33
%27 = mul i33 %24, %26
%28 = lshr i33 %27, 1
%29 = trunc i33 %28 to i32
%30 = add i32 %22, %29
%31 = add i32 %30, -1
br label %32
32: ; preds = %1, %3
%33 = phi i32 [ %21, %3 ], [ 0, %1 ]
%34 = phi i32 [ %31, %3 ], [ 0, %1 ]
%35 = mul i32 %34, %34
%36 = add i32 %33, %35
%37 = tail call i32 @printf(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %36)
ret void
}