#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 *);
scalar_t__ malloc(int);
int rand();
int /*<<< orphan*/ stderr;
int *generateRandomNumber(int rangeMin, int rangeMax) {
  int *r;
  r = (int *)malloc(sizeof(int));
  if (r == NULL) {
    fprintf(stderr, "Malloc failed\n");
    return NULL;
  }
  *r = rand() % rangeMax + rangeMin;
  return r;
}


x86 assembly (clang, -O0):
<generateRandomNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1179 <generateRandomNumber+0x49>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1195 <generateRandomNumber+0x65>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x10(%rbp)
add    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    %edx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateRandomNumber>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    $0x4,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     115c <generateRandomNumber+0x2c>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebp
add    %r14d,%edx
mov    %edx,(%rbx)
jmp    1173 <generateRandomNumber+0x43>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1030 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"Malloc failed\0A\00"
define i32* @generateRandomNumber(i32 %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = call i64 @malloc(i32 4)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %3
br label %22
14: ; preds = %2
%15 = call i32 (...) @rand()
%16 = load i32, i32* %5
%17 = srem i32 %15, %16
%18 = load i32, i32* %4
%19 = add nsw i32 %17, %18
%20 = load i32*, i32** %6
store i32 %19, i32* %20
%21 = load i32*, i32** %6
store i32* %21, i32** %3
br label %22
22: ; preds = %14, %11
%23 = load i32*, i32** %3
ret i32* %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"Malloc failed\0A\00"
define i32* @generateRandomNumber(i32 %0, i32 %1) {
%3 = tail call i64 @malloc(i32 4)
%4 = inttoptr i64 %3 to i32*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %13
9: ; preds = %2
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, %1
%12 = add nsw i32 %11, %0
store i32 %12, i32* %4
br label %13
13: ; preds = %9, %6
%14 = phi i32* [ null, %6 ], [ %4, %9 ]
ret i32* %14
}