#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, int);
void rule(int l, int r, int h) {
  int m = (l + r) / 2;
  if (h > 0) {
    printf("position %d, height %d\n", m, h);
    rule(l, m, h - 1);
    rule(m, r, h - 1);
  }
}


x86 assembly (clang, -O0):
<rule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1180 <rule+0x60>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1040 <rule@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1040 <rule@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rule>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1175 <rule+0x55>
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%r12d
lea    0xec2(%rip),%r15
xchg   %ax,%ax
lea    (%r12,%r14,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
lea    -0x1(%rbx),%r13d
mov    %r12d,%edi
mov    %ebp,%esi
mov    %r13d,%edx
call   1040 <rule@plt>
mov    %ebp,%r12d
cmp    $0x1,%ebx
mov    %r13d,%ebx
ja     1140 <rule+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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