#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);
void piramide(int nivells) {
  int j, k;
  for (j = 1; j <= nivells; j++) {
    printf("%d", j);
    k = j;
    if (k == nivells)
      while (k > 1) {
        k--;
        printf("%d", k);
      }
  }
}


x86 assembly (clang, -O0):
<piramide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1193 <piramide+0x83>
mov    -0x8(%rbp),%esi
lea    0xec8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1180 <piramide+0x70>
jmp    1154 <piramide+0x44>
cmpl   $0x1,-0xc(%rbp)
jle    117b <piramide+0x6b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
jmp    1154 <piramide+0x44>
jmp    1180 <piramide+0x70>
jmp    1185 <piramide+0x75>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <piramide+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<piramide>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    1185 <piramide+0x75>
mov    %edi,%r14d
lea    0x1(%r14),%r12d
mov    $0x1,%r15d
lea    0xed0(%rip),%rbx
jmp    114c <piramide+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%r15),%eax
cmp    %r14d,%r15d
mov    %eax,%r15d
je     1185 <piramide+0x75>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
cmp    %r14d,%r15d
jne    1140 <piramide+0x30>
cmp    $0x2,%r15d
jb     1140 <piramide+0x30>
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x2(%rbp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
jg     1170 <piramide+0x60>
jmp    1140 <piramide+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define void @piramide(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
br label %5
5: ; preds = %27, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = icmp sle i32 %6, %7
br i1 %8, label %9, label %30
9: ; preds = %5
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %9
br label %17
17: ; preds = %20, %16
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* %4
%22 = add nsw i32 %21, -1
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %17
25: ; preds = %17
br label %26
26: ; preds = %25, %9
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %5
30: ; preds = %5
ret void
}

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