void find_two_squares(unsigned long int num) {
  unsigned long int i, j;
  short int found_flag = 0, permutation;
  int length_counter = 0;
  unsigned long int *array =
      (unsigned long int *)malloc(sizeof(unsigned long int) * 2);
  unsigned long int *array_frame_ptr;
  unsigned long int tmparray[2];
  if (num < 5) {
    printf("\n\nHow can a number be the sum of two squares if it is minor than "
           "5?\n");
    free(array);
    return;
  }
  for (i = 1; i <= (num - 4); i++) {
    if (is_square(i)) {
      if (is_square(num - i)) {
        permutation = 0;
        tmparray[0] = i;
        tmparray[1] = num - i;
        if (length_counter > 0) {
          for (j = 0; j < length_counter; j++) {
            array_frame_ptr = array + (j * 2);
            if (are_permutations(tmparray, array_frame_ptr, 2)) {
              goto next_square;
            }
          }
        }
        memcpy(array + (length_counter * 2), tmparray,
               sizeof(unsigned long int) * 2);
        length_counter++;
        realloc(array, (length_counter) * sizeof(unsigned long int) * 2);
        found_flag = 1;
        printf("\nI found a sum of square numbers: %lu + %lu = %lu", i, num - i,
               num);
      next_square:;
      }
    }
  }
  free(array);
  if (!found_flag) {
    printf("\nCouldn\'t find two square numbers that matched the requests\n");
  }
}


x86 assembly (clang, -O0):
<find_two_squares>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movw   $0x0,-0x1a(%rbp)
movl   $0x0,-0x20(%rbp)
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x5,-0x8(%rbp)
jae    11ae <find_two_squares+0x4e>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    132a <find_two_squares+0x1ca>
movq   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    $0x4,%rcx
cmp    %rcx,%rax
ja     1308 <find_two_squares+0x1a8>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1060 <is_square@plt>
cmp    $0x0,%eax
je     12f2 <find_two_squares+0x192>
mov    -0x8(%rbp),%rdi
sub    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1060 <is_square@plt>
cmp    $0x0,%eax
je     12ed <find_two_squares+0x18d>
movw   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1288 <find_two_squares+0x128>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmp    %rcx,%rax
jae    1283 <find_two_squares+0x123>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x1,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1050 <are_permutations@plt>
cmp    $0x0,%eax
je     126d <find_two_squares+0x10d>
jmp    12e8 <find_two_squares+0x188>
jmp    1272 <find_two_squares+0x112>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1223 <find_two_squares+0xc3>
jmp    1288 <find_two_squares+0x128>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    -0x40(%rbp),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdx
mov    %rdx,0x8(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x20(%rbp),%rsi
shl    $0x3,%rsi
shl    $0x1,%rsi
call   1080 <realloc@plt>
movw   $0x1,-0x1a(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
sub    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ed <find_two_squares+0x18d>
jmp    12f2 <find_two_squares+0x192>
jmp    12f7 <find_two_squares+0x197>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b6 <find_two_squares+0x56>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpw   $0x0,-0x1a(%rbp)
jne    132a <find_two_squares+0x1ca>
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_two_squares>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
cmp    $0x5,%r14
jae    11b6 <find_two_squares+0x46>
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    %rbx,0x8(%rsp)
lea    -0x4(%r14),%r13
mov    $0x1,%ebx
lea    0x20(%rsp),%r12
xor    %r15d,%r15d
movl   $0x0,0x4(%rsp)
mov    %r14,0x18(%rsp)
mov    %r13,0x10(%rsp)
jmp    123a <find_two_squares+0xca>
lea    (%r15,%r15,1),%eax
cltq
movaps 0x20(%rsp),%xmm0
mov    0x8(%rsp),%rdi
movups %xmm0,(%rdi,%rax,8)
movslq %r15d,%rsi
add    $0x1,%r15d
shl    $0x4,%rsi
add    $0x10,%rsi
call   1090 <realloc@plt>
lea    0xdf1(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    0x18(%rsp),%r14
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ax
mov    %eax,0x4(%rsp)
mov    0x10(%rsp),%r13
add    $0x1,%rbx
cmp    %r13,%rbx
ja     12ac <find_two_squares+0x13c>
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <is_square@plt>
test   %eax,%eax
je     1231 <find_two_squares+0xc1>
mov    %r14,%rbp
sub    %rbx,%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <is_square@plt>
test   %eax,%eax
je     1231 <find_two_squares+0xc1>
mov    %rbx,0x20(%rsp)
mov    %rbp,0x28(%rsp)
test   %r15d,%r15d
jle    11e0 <find_two_squares+0x70>
mov    %r15d,%r13d
mov    0x8(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1060 <are_permutations@plt>
test   %eax,%eax
jne    12a5 <find_two_squares+0x135>
add    $0x10,%r14
add    $0xffffffffffffffff,%r13
jne    1280 <find_two_squares+0x110>
jmp    11e0 <find_two_squares+0x70>
mov    0x18(%rsp),%r14
jmp    122c <find_two_squares+0xbc>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
cmpw   $0x0,0x4(%rsp)
jne    12ca <find_two_squares+0x15a>
lea    0xd6d(%rip),%rdi
call   1040 <puts@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [69 x i8] c"\0A\0AHow can a number be the sum of two squares if it is minor than 5?\0A\00"
@.str.1 = [50 x i8] c"\0AI found a sum of square numbers: %lu + %lu = %lu\00"
@.str.2 = [61 x i8] c"\0ACouldn't find two square numbers that matched the requests\0A\00"
define void @find_two_squares(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i16
%6 = alloca i16
%7 = alloca i32
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca [2 x i64]
store i64 %0, i64* %2
store i16 0, i16* %5
store i32 0, i32* %7
%11 = call i8* @malloc(i64 16)
%12 = bitcast i8* %11 to i64*
store i64* %12, i64** %8
%13 = load i64, i64* %2
%14 = icmp ult i64 %13, 5
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0))
%17 = load i64*, i64** %8
%18 = bitcast i64* %17 to i8*
br label %102
19: ; preds = %1
store i64 1, i64* %3
br label %20
20: ; preds = %92, %19
%21 = load i64, i64* %3
%22 = load i64, i64* %2
%23 = sub i64 %22, 4
%24 = icmp ule i64 %21, %23
br i1 %24, label %25, label %95
25: ; preds = %20
%26 = load i64, i64* %3
%27 = call i32 (i64, ...) bitcast (i32 (...)* @is_square to i32 (i64, ...)*)(i64 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %91
29: ; preds = %25
%30 = load i64, i64* %2
%31 = load i64, i64* %3
%32 = sub i64 %30, %31
%33 = call i32 (i64, ...) bitcast (i32 (...)* @is_square to i32 (i64, ...)*)(i64 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %90
35: ; preds = %29
store i16 0, i16* %6
%36 = load i64, i64* %3
%37 = getelementptr inbounds [2 x i64], [2 x i64]* %10, i64 0, i64 0
store i64 %36, i64* %37
%38 = load i64, i64* %2
%39 = load i64, i64* %3
%40 = sub i64 %38, %39
%41 = getelementptr inbounds [2 x i64], [2 x i64]* %10, i64 0, i64 1
store i64 %40, i64* %41
%42 = load i32, i32* %7
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %65
44: ; preds = %35
store i64 0, i64* %4
br label %45
45: ; preds = %61, %44
%46 = load i64, i64* %4
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = icmp ult i64 %46, %48
br i1 %49, label %50, label %64
50: ; preds = %45
%51 = load i64*, i64** %8
%52 = load i64, i64* %4
%53 = mul i64 %52, 2
%54 = getelementptr inbounds i64, i64* %51, i64 %53
store i64* %54, i64** %9
%55 = getelementptr inbounds [2 x i64], [2 x i64]* %10, i64 0, i64 0
%56 = load i64*, i64** %9
%57 = call i32 (i64*, i64*, i32, ...) bitcast (i32 (...)* @are_permutations to i32 (i64*, i64*, i32, ...)*)(i64* %55, i64* %56, i32 2)
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %50
br label %89
60: ; preds = %50
br label %61
61: ; preds = %60
%62 = load i64, i64* %4
%63 = add i64 %62, 1
store i64 %63, i64* %4
br label %45
64: ; preds = %45
br label %65
65: ; preds = %64, %35
%66 = load i64*, i64** %8
%67 = load i32, i32* %7
%68 = mul nsw i32 %67, 2
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i64, i64* %66, i64 %69
%71 = bitcast i64* %70 to i8*
%72 = getelementptr inbounds [2 x i64], [2 x i64]* %10, i64 0, i64 0
%73 = bitcast i64* %72 to i8*
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
%76 = load i64*, i64** %8
%77 = bitcast i64* %76 to i8*
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = mul i64 %79, 8
%81 = mul i64 %80, 2
%82 = call i8* @realloc(i8* %77, i64 %81)
store i16 1, i16* %5
%83 = load i64, i64* %3
%84 = load i64, i64* %2
%85 = load i64, i64* %3
%86 = sub i64 %84, %85
%87 = load i64, i64* %2
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i64 %83, i64 %86, i64 %87)
br label %89
89: ; preds = %65, %59
br label %90
90: ; preds = %89, %29
br label %91
91: ; preds = %90, %25
br label %92
92: ; preds = %91
%93 = load i64, i64* %3
%94 = add i64 %93, 1
store i64 %94, i64* %3
br label %20
95: ; preds = %20
%96 = load i64*, i64** %8
%97 = bitcast i64* %96 to i8*
%98 = load i16, i16* %5
%99 = icmp ne i16 %98, 0
br i1 %99, label %102, label %100
100: ; preds = %95
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
br label %102
102: ; preds = %15, %100, %95
ret void
}

LLVM IR (-O2):
@.str.1 = [50 x i8] c"\0AI found a sum of square numbers: %lu + %lu = %lu\00"
@str = [60 x i8] c"\0ACouldn't find two square numbers that matched the requests\00"
@str.3 = [68 x i8] c"\0A\0AHow can a number be the sum of two squares if it is minor than 5?\00"
define void @find_two_squares(i64 %0) {
%2 = alloca [2 x i64]
%3 = tail call dereferenceable_or_null(16) i8* @malloc(i64 16)
%4 = bitcast i8* %3 to i64*
%5 = bitcast [2 x i64]* %2 to i8*
%6 = icmp ult i64 %0, 5
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = add i64 %0, -4
%9 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 0
%10 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 1
br label %13
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str.3, i64 0, i64 0))
tail call void @free(i8* %3)
br label %55
13: ; preds = %7, %46
%14 = phi i64 [ 1, %7 ], [ %49, %46 ]
%15 = phi i32 [ 0, %7 ], [ %48, %46 ]
%16 = phi i16 [ 0, %7 ], [ %47, %46 ]
%17 = call i32 (i64, ...) bitcast (i32 (...)* @is_square to i32 (i64, ...)*)(i64 %14)
%18 = icmp eq i32 %17, 0
br i1 %18, label %46, label %19
19: ; preds = %13
%20 = sub i64 %0, %14
%21 = call i32 (i64, ...) bitcast (i32 (...)* @is_square to i32 (i64, ...)*)(i64 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %46, label %23
23: ; preds = %19
store i64 %14, i64* %9
store i64 %20, i64* %10
%24 = icmp sgt i32 %15, 0
br i1 %24, label %25, label %36
25: ; preds = %23
%26 = zext i32 %15 to i64
br label %29
27: ; preds = %29
%28 = icmp eq i64 %35, %26
br i1 %28, label %36, label %29
29: ; preds = %25, %27
%30 = phi i64 [ 0, %25 ], [ %35, %27 ]
%31 = shl i64 %30, 1
%32 = getelementptr inbounds i64, i64* %4, i64 %31
%33 = call i32 (i64*, i64*, i32, ...) bitcast (i32 (...)* @are_permutations to i32 (i64*, i64*, i32, ...)*)(i64* %9, i64* %32, i32 2)
%34 = icmp eq i32 %33, 0
%35 = add nuw i64 %30, 1
br i1 %34, label %27, label %46
36: ; preds = %27, %23
%37 = shl nsw i32 %15, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i64, i64* %4, i64 %38
%40 = bitcast i64* %39 to i8*
%41 = add nsw i32 %15, 1
%42 = sext i32 %41 to i64
%43 = shl nsw i64 %42, 4
%44 = call i8* @realloc(i8* %3, i64 %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i64 %14, i64 %20, i64 %0)
br label %46
46: ; preds = %29, %13, %36, %19
%47 = phi i16 [ 1, %36 ], [ %16, %19 ], [ %16, %13 ], [ %16, %29 ]
%48 = phi i32 [ %41, %36 ], [ %15, %19 ], [ %15, %13 ], [ %15, %29 ]
%49 = add i64 %14, 1
%50 = icmp ugt i64 %49, %8
br i1 %50, label %51, label %13
51: ; preds = %46
%52 = icmp eq i16 %47, 0
br i1 %52, label %53, label %55
53: ; preds = %51
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
br label %55
55: ; preds = %51, %53, %11
ret void
}