#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 rand();
void randselect(int m, int n) {
  if (m > 0) {
    if (rand() % n < m) {
      randselect(m - 1, n - 1);
      printf("%d\n", n - 1);
    } else
      randselect(m, n - 1);
  }
}


x86 assembly (clang, -O0):
<randselect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1197 <randselect+0x67>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x8(%rbp)
cmp    -0x4(%rbp),%edx
jge    1184 <randselect+0x54>
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1040 <randselect@plt>
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
jmp    1192 <randselect+0x62>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
call   1040 <randselect@plt>
jmp    1197 <randselect+0x67>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randselect>:
test   %edi,%edi
jle    1171 <randselect+0x41>
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebx
add    $0xffffffff,%ebx
cmp    %ebp,%edx
jge    1140 <randselect+0x10>
add    $0xffffffff,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <randselect@plt>
lea    0xe9c(%rip),%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>
ret

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

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