#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*/ printf(char *, ...);
int nbsum(unsigned int n) {
  int i = 0;
  int j = 0;
  printf("%d = %d\n", n, n);
  for (i = n - 1; i > 0; i--) {
    j = n - i;
    if (i > j && j != 1)
      printf("%d = %d + %d\n", n, i, j);
    printf("%d = %i", n, i);
    for (j; j > 0; j--) {
      printf(" + 1");
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<nbsum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11dc <nbsum+0xcc>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1186 <nbsum+0x76>
cmpl   $0x1,-0x10(%rbp)
je     1186 <nbsum+0x76>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jle    11c0 <nbsum+0xb0>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    119a <nbsum+0x8a>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <nbsum+0x36>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nbsum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
lea    0xecb(%rip),%rdi
mov    %r12d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x1(%r12),%r13d
test   %r13d,%r13d
jle    11e4 <nbsum+0xc4>
mov    $0x2,%r14d
lea    0xeba(%rip),%r15
lea    0xebb(%rip),%rbx
jmp    1187 <nbsum+0x67>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%r13d
add    $0x1,%r14d
test   %r13d,%r13d
jle    11e4 <nbsum+0xc4>
mov    %r12d,%ebp
sub    %r13d,%ebp
cmp    %ebp,%r13d
jle    11ad <nbsum+0x8d>
cmp    $0x1,%ebp
je     11ad <nbsum+0x8d>
lea    0xe6b(%rip),%rdi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    1170 <nbsum+0x50>
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     11d0 <nbsum+0xb0>
jmp    1170 <nbsum+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"%d = %d\0A\00"
@.str.1 = [14 x i8] c"%d = %d + %d\0A\00"
@.str.2 = [8 x i8] c"%d = %i\00"
@.str.3 = [5 x i8] c" + 1\00"
define i32 @nbsum(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %0)
%3 = add i32 %0, -1
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %25
5: ; preds = %1, %21
%6 = phi i32 [ %23, %21 ], [ %3, %1 ]
%7 = sub i32 %0, %6
%8 = icmp sgt i32 %6, %7
%9 = icmp ne i32 %7, 1
%10 = and i1 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %6, i32 %7)
br label %13
13: ; preds = %11, %5
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %6)
%15 = icmp sgt i32 %7, 0
br i1 %15, label %16, label %21
16: ; preds = %13, %16
%17 = phi i32 [ %19, %16 ], [ %7, %13 ]
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%19 = add nsw i32 %17, -1
%20 = icmp ugt i32 %17, 1
br i1 %20, label %16, label %21
21: ; preds = %16, %13
%22 = tail call i32 @putchar(i32 10)
%23 = add i32 %6, -1
%24 = icmp sgt i32 %23, 0
br i1 %24, label %5, label %25
25: ; preds = %21, %1
ret i32 undef
}