#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
int rand();
int /*<<< orphan*/ stderr;
int rand_num(int min, int max) {
  if (min > max) {
    fprintf(stderr, "for rand_num(%d, %d), max must be > min.\n", min, max);
    return max;
  } else if (min == max)
    return max;
  return rand() % (max - min + 1) + min;
}


x86 assembly (clang, -O0):
<rand_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1160 <rand_num+0x40>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xeb0(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1195 <rand_num+0x75>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1177 <rand_num+0x57>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1195 <rand_num+0x75>
jmp    117c <rand_num+0x5c>
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0xc(%rbp),%ecx
sub    -0x8(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
add    -0x8(%rbp),%edx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_num>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
mov    %esi,%ebp
sub    %edi,%ebp
jge    114b <rand_num+0x2b>
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
lea    0xec1(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
call   1030 <fprintf@plt>
jmp    115f <rand_num+0x3f>
je     115f <rand_num+0x3f>
xor    %eax,%eax
call   1040 <rand@plt>
add    $0x1,%ebp
cltd
idiv   %ebp
mov    %edx,%ebx
add    %r14d,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"for rand_num(%d, %d), max must be > min.\0A\00"
define i32 @rand_num(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = load i32, i32* %5
%8 = icmp sgt i32 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %5
store i32 %14, i32* %3
br label %31
15: ; preds = %2
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i32, i32* %5
store i32 %20, i32* %3
br label %31
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = call i32 (...) @rand()
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = sub nsw i32 %24, %25
%27 = add nsw i32 %26, 1
%28 = srem i32 %23, %27
%29 = load i32, i32* %4
%30 = add nsw i32 %28, %29
store i32 %30, i32* %3
br label %31
31: ; preds = %22, %19, %9
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"for rand_num(%d, %d), max must be > min.\0A\00"
define i32 @rand_num(i32 %0, i32 %1) {
%3 = icmp slt i32 %1, %0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
br label %15
7: ; preds = %2
%8 = icmp eq i32 %1, %0
br i1 %8, label %15, label %9
9: ; preds = %7
%10 = tail call i32 (...) @rand()
%11 = sub i32 1, %0
%12 = add i32 %11, %1
%13 = srem i32 %10, %12
%14 = add nsw i32 %13, %0
br label %15
15: ; preds = %7, %9, %4
%16 = phi i32 [ %1, %4 ], [ %14, %9 ], [ %1, %7 ]
ret i32 %16
}