#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 abs(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int meja;
  printf("Please insert the upper bound:\n");
  scanf("%d", &meja);
  int i;
  int sumOfSquares = 0;
  int squareOfSum = 0;
  for (i = 1; i <= meja; i++) {
    sumOfSquares += i * i;
    squareOfSum += i;
  }
  squareOfSum *= squareOfSum;
  printf("The difference between the sum of the squares of the first %d "
         "natural numbers and the square of the sum is:\n",
         meja);
  printf("%d\n", abs(sumOfSquares - squareOfSum));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11a2 <main+0x72>
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1172 <main+0x42>
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
sub    -0x14(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xf38(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    118a <main+0x5a>
lea    -0x1(%rsi),%eax
lea    -0x2(%rsi),%ecx
imul   %rax,%rcx
lea    -0x3(%rsi),%eax
imul   %rcx,%rax
shr    %rax
imul   $0x55555556,%eax,%eax
shr    %rcx
lea    (%rcx,%rcx,4),%edx
add    %eax,%edx
lea    (%rdx,%rsi,4),%ebx
add    $0xfffffffd,%ebx
lea    (%rcx,%rsi,2),%eax
add    $0xffffffff,%eax
jmp    118e <main+0x5e>
xor    %ebx,%ebx
xor    %eax,%eax
imul   %eax,%eax
sub    %eax,%ebx
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%esi
neg    %esi
cmovs  %ebx,%esi
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [109 x i8] c"The difference between the sum of the squares of the first %d natural numbers and the square of the sum is:\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [31 x i8] c"Please insert the upper bound:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %29, label %7
7: ; preds = %0
%8 = add nsw i32 %5, -1
%9 = zext i32 %8 to i33
%10 = add nsw i32 %5, -2
%11 = zext i32 %10 to i33
%12 = mul i33 %9, %11
%13 = add nsw i32 %5, -3
%14 = zext i32 %13 to i33
%15 = mul i33 %12, %14
%16 = lshr i33 %15, 1
%17 = trunc i33 %16 to i32
%18 = mul i32 %17, 1431655766
%19 = lshr i33 %12, 1
%20 = trunc i33 %19 to i32
%21 = mul i32 %20, 5
%22 = add i32 %18, %21
%23 = shl i32 %5, 2
%24 = add i32 %22, %23
%25 = shl nuw i32 %5, 1
%26 = add i32 %25, %20
%27 = add i32 %24, -3
%28 = add i32 %26, -1
br label %29
29: ; preds = %7, %0
%30 = phi i32 [ 0, %0 ], [ %27, %7 ]
%31 = phi i32 [ 0, %0 ], [ %28, %7 ]
%32 = mul nsw i32 %31, %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([109 x i8], [109 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%34 = sub nsw i32 %30, %32
%35 = call i32 @llvm.abs.i32(i32 %34, i1 true)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %35)
ret i32 0
}