#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*/ getch();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int num, i, j, k, l, c;
  c = 0;
  scanf("%d", &num);
  for (i = 0; i <= num; ++i) {
    j = num - i;
    for (k = 0; k <= num; ++k) {
      l = j - k;
      ++c;
      printf("%d\t%d\t%d\n", i, k, l);
    }
  }
  printf("\n\nThere are a total of %d solutions", c);
  getch();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11cf <main+0x9f>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11bc <main+0x8c>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <main+0x49>
jmp    11c1 <main+0x91>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <main+0x2d>
mov    -0x1c(%rbp),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     11b6 <main+0x86>
lea    0xea8(%rip),%r15
xor    %r13d,%r13d
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    1181 <main+0x51>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%r12),%ecx
add    $0xffffffff,%r13d
cmp    %r12d,%eax
mov    %ecx,%r12d
jle    11b9 <main+0x89>
test   %eax,%eax
js     1170 <main+0x40>
add    %r13d,%eax
xor    %ecx,%ecx
mov    %eax,%ebx
nopl   0x0(%rax)
mov    %ecx,%ebp
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ecx,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x1(%rbp),%ecx
mov    0x4(%rsp),%eax
add    $0xffffffff,%ebx
cmp    %eax,%ebp
jl     1190 <main+0x60>
add    %ecx,%r14d
jmp    1170 <main+0x40>
xor    %r14d,%r14d
lea    0xe4d(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getch@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"%d\09%d\09%d\0A\00"
@.str.2 = [36 x i8] c"\0A\0AThere are a total of %d solutions\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %7
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %9
9: ; preds = %35, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %38
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = sub nsw i32 %14, %15
store i32 %16, i32* %4
store i32 0, i32* %5
br label %17
17: ; preds = %31, %13
%18 = load i32, i32* %5
%19 = load i32, i32* %2
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %6
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = load i32, i32* %3
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %21
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %17
34: ; preds = %17
br label %35
35: ; preds = %34
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %9
38: ; preds = %9
%39 = load i32, i32* %7
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = call i32 (...) @getch()
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"%d\09%d\09%d\0A\00"
@.str.2 = [36 x i8] c"\0A\0AThere are a total of %d solutions\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %0, %21
%7 = phi i32 [ %22, %21 ], [ %4, %0 ]
%8 = phi i32 [ %23, %21 ], [ 0, %0 ]
%9 = phi i32 [ %24, %21 ], [ 0, %0 ]
%10 = icmp slt i32 %7, 0
br i1 %10, label %21, label %11
11: ; preds = %6, %11
%12 = phi i32 [ %16, %11 ], [ %8, %6 ]
%13 = phi i32 [ %18, %11 ], [ 0, %6 ]
%14 = add nuw i32 %9, %13
%15 = sub i32 %7, %14
%16 = add nsw i32 %12, 1
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %13, i32 %15)
%18 = add nuw nsw i32 %13, 1
%19 = load i32, i32* %1
%20 = icmp slt i32 %13, %19
br i1 %20, label %11, label %21
21: ; preds = %11, %6
%22 = phi i32 [ %7, %6 ], [ %19, %11 ]
%23 = phi i32 [ %8, %6 ], [ %16, %11 ]
%24 = add nuw nsw i32 %9, 1
%25 = icmp sgt i32 %22, %9
br i1 %25, label %6, label %26
26: ; preds = %21, %0
%27 = phi i32 [ 0, %0 ], [ %23, %21 ]
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = call i32 (...) @getch()
ret i32 0
}