#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 *);
void diamond(int n) {
  int level, d = 1, s = (n + 1) / 2, c = 1;
  int i;
  for (level = 1; level <= 2 * n - 1; ++level, d += c, s -= c) {
    for (i = 0; i < s; ++i)
      printf(" ");
    for (i = 0; i < d; ++i)
      printf("*");
    if (d == n)
      c = -1;
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<diamond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11f0 <diamond+0xe0>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1182 <diamond+0x72>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115c <diamond+0x4c>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11af <diamond+0x9f>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <diamond+0x79>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11c2 <diamond+0xb2>
movl   $0xffffffff,-0x14(%rbp)
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <diamond+0x31>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diamond>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
test   %edi,%edi
jle    11c1 <diamond+0xb1>
mov    0x10(%rsp),%rcx
lea    (%rcx,%rcx,1),%eax
lea    0x1(%rcx),%r14d
shr    %r14d
cmp    $0x3,%eax
mov    $0x2,%ecx
cmovge %eax,%ecx
mov    %ecx,0xc(%rsp)
mov    $0x1,%ebx
mov    $0x1,%r15d
mov    $0x1,%r12d
jmp    1188 <diamond+0x78>
nopl   0x0(%rax)
cmp    0x10(%rsp),%r15d
mov    $0xffffffff,%eax
cmove  %eax,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12d
add    %ebx,%r15d
sub    %ebx,%r14d
cmp    0xc(%rsp),%r12d
je     11c1 <diamond+0xb1>
mov    %r14d,%r13d
test   %r14d,%r14d
jle    11a0 <diamond+0x90>
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%r13d
jne    1190 <diamond+0x80>
mov    %r15d,%ebp
test   %r15d,%r15d
jle    1160 <diamond+0x50>
nopl   0x0(%rax,%rax,1)
mov    $0x2a,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11b0 <diamond+0xa0>
jmp    1160 <diamond+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @diamond(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %34
3: ; preds = %1
%4 = shl nuw i32 %0, 1
%5 = add nuw nsw i32 %0, 1
%6 = lshr i32 %5, 1
%7 = call i32 @llvm.smax.i32(i32 %4, i32 2)
br label %8
8: ; preds = %3, %26
%9 = phi i32 [ %28, %26 ], [ 1, %3 ]
%10 = phi i32 [ %32, %26 ], [ %6, %3 ]
%11 = phi i32 [ %31, %26 ], [ 1, %3 ]
%12 = phi i32 [ %30, %26 ], [ 1, %3 ]
%13 = icmp sgt i32 %10, 0
br i1 %13, label %16, label %14
14: ; preds = %16, %8
%15 = icmp sgt i32 %11, 0
br i1 %15, label %21, label %26
16: ; preds = %8, %16
%17 = phi i32 [ %19, %16 ], [ 0, %8 ]
%18 = tail call i32 @putchar(i32 32)
%19 = add nuw nsw i32 %17, 1
%20 = icmp eq i32 %19, %10
br i1 %20, label %14, label %16
21: ; preds = %14, %21
%22 = phi i32 [ %24, %21 ], [ 0, %14 ]
%23 = tail call i32 @putchar(i32 42)
%24 = add nuw nsw i32 %22, 1
%25 = icmp eq i32 %24, %11
br i1 %25, label %26, label %21
26: ; preds = %21, %14
%27 = icmp eq i32 %11, %0
%28 = select i1 %27, i32 -1, i32 %9
%29 = tail call i32 @putchar(i32 10)
%30 = add nuw nsw i32 %12, 1
%31 = add nsw i32 %28, %11
%32 = sub nsw i32 %10, %28
%33 = icmp eq i32 %30, %7
br i1 %33, label %34, label %8
34: ; preds = %26, %1
ret void
}