#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 check_sum(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
void sum_search(int n) {
  int k = 2, result;
  while (!(result = check_sum(n, k, n / k - (k >> 1))))
    k++;
  printf("%d = %d", n, result);
  for (n = 1; n < k; n++)
    printf(" + %d", result + n);
  printf("\n");
}


x86 assembly (clang, -O0):
<sum_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%edx
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
sub    %eax,%edx
call   1040 <check_sum@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1166 <sum_search+0x46>
jmp    1174 <sum_search+0x54>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1132 <sum_search+0x12>
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11bd <sum_search+0x9d>
mov    -0xc(%rbp),%esi
add    -0x4(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    118f <sum_search+0x6f>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_search>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
lea    0x2(%rbp),%esi
mov    %r14d,%eax
cltd
idiv   %esi
mov    %esi,%ecx
shr    %ecx
sub    %ecx,%eax
mov    %r14d,%edi
mov    %eax,%edx
call   1050 <check_sum@plt>
add    $0x1,%ebp
test   %eax,%eax
je     1140 <sum_search+0x10>
mov    %eax,%ebx
lea    0xe97(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
lea    0xe89(%rip),%r14
nop
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
jne    1180 <sum_search+0x50>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%d = %d\00"
@.str.1 = [6 x i8] c" + %d\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @sum_search(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 2, i32* %3
br label %5
5: ; preds = %17, %1
%6 = load i32, i32* %2
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = sdiv i32 %8, %9
%11 = load i32, i32* %3
%12 = ashr i32 %11, 1
%13 = sub nsw i32 %10, %12
%14 = call i32 @check_sum(i32 %6, i32 %7, i32 %13)
store i32 %14, i32* %4
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %20
17: ; preds = %5
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %5
20: ; preds = %5
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
store i32 1, i32* %2
br label %24
24: ; preds = %33, %20
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %36
28: ; preds = %24
%29 = load i32, i32* %4
%30 = load i32, i32* %2
%31 = add nsw i32 %29, %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %28
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %24
36: ; preds = %24
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%d = %d\00"
@.str.1 = [6 x i8] c" + %d\00"
define void @sum_search(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 2, %1 ], [ %9, %2 ]
%4 = sdiv i32 %0, %3
%5 = lshr i32 %3, 1
%6 = sub nsw i32 %4, %5
%7 = tail call i32 @check_sum(i32 %0, i32 %3, i32 %6)
%8 = icmp eq i32 %7, 0
%9 = add nuw nsw i32 %3, 1
br i1 %8, label %2, label %10
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %7)
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ 1, %10 ], [ %16, %12 ]
%14 = add nsw i32 %13, %7
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i32 %13, 1
%17 = icmp eq i32 %16, %3
br i1 %17, label %18, label %12
18: ; preds = %12
%19 = tail call i32 @putchar(i32 10)
ret void
}