#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 *malloc(int);
int /*<<< orphan*/ pythagorean(int, int, int);
int searchmax(int *);
int maxsolutions(int max) {
  int *maxarr = malloc(max * sizeof(int));
  for (int a = 1; a < max; a++) {
    for (int b = 1; (a + b) < max; b++) {
      for (int c = 1; (a + b + c) < max; c++) {
        if (!pythagorean(a, b, c))
          continue;
        maxarr[a + b + c]++;
      }
    }
  }
  return searchmax(maxarr);
}


x86 assembly (clang, -O0):
<maxsolutions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f9 <maxsolutions+0xc9>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e6 <maxsolutions+0xb6>
movl   $0x1,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d3 <maxsolutions+0xa3>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <pythagorean@plt>
cmp    $0x0,%eax
jne    11ac <maxsolutions+0x7c>
jmp    11c5 <maxsolutions+0x95>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117e <maxsolutions+0x4e>
jmp    11d8 <maxsolutions+0xa8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <maxsolutions+0x38>
jmp    11eb <maxsolutions+0xbb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1155 <maxsolutions+0x25>
mov    -0x10(%rbp),%rdi
call   1050 <searchmax@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maxsolutions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r15d
lea    0x0(,%r15,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r14
cmp    $0x2,%r15d
jl     1235 <maxsolutions+0x105>
mov    %r15d,%eax
mov    $0x1,%r12d
movl   $0x3,0xc(%rsp)
mov    %r15d,%ecx
mov    %r15d,0x8(%rsp)
mov    %rax,0x18(%rsp)
jmp    119b <maxsolutions+0x6b>
nopl   0x0(%rax,%rax,1)
addl   $0x1,0xc(%rsp)
mov    0x10(%rsp),%rcx
mov    %rcx,%r12
mov    0x18(%rsp),%rax
cmp    %rax,%rcx
je     1235 <maxsolutions+0x105>
addl   $0xffffffff,0x8(%rsp)
lea    0x1(%r12),%rcx
mov    %rcx,0x10(%rsp)
cmp    %rax,%rcx
jae    1180 <maxsolutions+0x50>
mov    0x8(%rsp),%eax
mov    %rax,0x20(%rsp)
mov    $0x1,%r13d
mov    0xc(%rsp),%eax
mov    %eax,%ebp
mov    0x10(%rsp),%rax
jmp    11e6 <maxsolutions+0xb6>
nopl   0x0(%rax,%rax,1)
lea    (%r12,%r13,1),%rax
add    $0x1,%rax
add    $0x1,%r13
add    $0x1,%ebp
cmp    0x20(%rsp),%r13
je     1180 <maxsolutions+0x50>
add    $0x1,%eax
cmp    %r15d,%eax
jge    11d0 <maxsolutions+0xa0>
mov    $0x1,%ebx
jmp    1215 <maxsolutions+0xe5>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
add    $0xffffffff,%eax
mov    %ecx,%ebx
cmp    %r15d,%eax
jge    11d0 <maxsolutions+0xa0>
mov    %r12d,%edi
mov    %r13d,%esi
mov    %ebx,%edx
call   1040 <pythagorean@plt>
test   %eax,%eax
je     1200 <maxsolutions+0xd0>
lea    (%rbx,%rbp,1),%eax
add    $0xffffffff,%eax
mov    %eax,%eax
addl   $0x1,(%r14,%rax,4)
jmp    1200 <maxsolutions+0xd0>
mov    %r14,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <searchmax@plt>

LLVM IR (-O0):
define i32 @maxsolutions(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i32* @malloc(i32 %10)
store i32* %11, i32** %3
store i32 1, i32* %4
br label %12
12: ; preds = %58, %1
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %61
16: ; preds = %12
store i32 1, i32* %5
br label %17
17: ; preds = %54, %16
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = add nsw i32 %18, %19
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %57
23: ; preds = %17
store i32 1, i32* %6
br label %24
24: ; preds = %50, %23
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = add nsw i32 %25, %26
%28 = load i32, i32* %6
%29 = add nsw i32 %27, %28
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %53
32: ; preds = %24
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i32 @pythagorean(i32 %33, i32 %34, i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %32
br label %50
39: ; preds = %32
%40 = load i32*, i32** %3
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = add nsw i32 %41, %42
%44 = load i32, i32* %6
%45 = add nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %40, i64 %46
%48 = load i32, i32* %47
%49 = add nsw i32 %48, 1
store i32 %49, i32* %47
br label %50
50: ; preds = %39, %38
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %24
53: ; preds = %24
br label %54
54: ; preds = %53
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %17
57: ; preds = %17
br label %58
58: ; preds = %57
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %12
61: ; preds = %12
%62 = load i32*, i32** %3
%63 = call i32 @searchmax(i32* %62)
ret i32 %63
}

LLVM IR (-O2):
define i32 @maxsolutions(i32 %0) {
%2 = shl i32 %0, 2
%3 = tail call i32* @malloc(i32 %2)
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %17
5: ; preds = %1
%6 = zext i32 %0 to i64
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %5, %27
%9 = phi i64 [ 1, %5 ], [ %12, %27 ]
%10 = phi i32 [ %0, %5 ], [ %11, %27 ]
%11 = add i32 %10, -1
%12 = add nuw nsw i64 %9, 1
%13 = icmp ult i64 %12, %6
br i1 %13, label %14, label %27
14: ; preds = %8
%15 = zext i32 %11 to i64
%16 = trunc i64 %9 to i32
br label %19
17: ; preds = %27, %1
%18 = tail call i32 @searchmax(i32* %3)
ret i32 %18
19: ; preds = %14, %29
%20 = phi i64 [ 1, %14 ], [ %30, %29 ]
%21 = phi i64 [ %12, %14 ], [ %31, %29 ]
%22 = trunc i64 %21 to i32
%23 = add nuw nsw i32 %22, 1
%24 = icmp slt i32 %23, %0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = trunc i64 %20 to i32
br label %33
27: ; preds = %29, %8
%28 = icmp eq i64 %12, %7
br i1 %28, label %17, label %8
29: ; preds = %44, %19
%30 = add nuw nsw i64 %20, 1
%31 = add nuw nsw i64 %30, %9
%32 = icmp eq i64 %30, %15
br i1 %32, label %27, label %19
33: ; preds = %25, %44
%34 = phi i64 [ 1, %25 ], [ %45, %44 ]
%35 = phi i32 [ %23, %25 ], [ %47, %44 ]
%36 = trunc i64 %34 to i32
%37 = tail call i32 @pythagorean(i32 %16, i32 %26, i32 %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %33
%40 = zext i32 %35 to i64
%41 = getelementptr inbounds i32, i32* %3, i64 %40
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
store i32 %43, i32* %41
br label %44
44: ; preds = %33, %39
%45 = add nuw nsw i64 %34, 1
%46 = add i64 %45, %21
%47 = trunc i64 %46 to i32
%48 = icmp slt i32 %47, %0
br i1 %48, label %33, label %29
}