#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 */
typedef int uint64_t;
typedef scalar_t__ uint32_t;
struct random_data {
  int dummy;
};
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ random_r(struct random_data *, scalar_t__ *);
uint64_t my_rand(struct random_data *r1, struct random_data *r2) {
  uint64_t rand_max = 100000000000LL;
  uint64_t result;
  uint32_t u1, u2;
  random_r(r1, &u1);
  random_r(r2, &u2);
  result = (int64_t)u1 * (int64_t)u2;
  result = result % rand_max;
  return result;
}


x86 assembly (clang, -O0):
<my_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4876e800,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <random_r@plt>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <random_r@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
imul   %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_rand>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <random_r@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <random_r@plt>
mov    (%rsp),%eax
imul   0x8(%rsp),%eax
cltq
imul   $0x38863507,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x3c,%rcx
add    %edx,%ecx
imul   $0x4876e800,%ecx,%ecx
sub    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.random_data = type { i32 }
define i32 @my_rand(%struct.random_data* %0, %struct.random_data* %1) {
%3 = alloca %struct.random_data*
%4 = alloca %struct.random_data*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store %struct.random_data* %0, %struct.random_data** %3
store %struct.random_data* %1, %struct.random_data** %4
store i32 1215752192, i32* %5
%9 = load %struct.random_data*, %struct.random_data** %3
%10 = call i32 @random_r(%struct.random_data* %9, i64* %7)
%11 = load %struct.random_data*, %struct.random_data** %4
%12 = call i32 @random_r(%struct.random_data* %11, i64* %8)
%13 = load i64, i64* %7
%14 = trunc i64 %13 to i32
%15 = load i64, i64* %8
%16 = trunc i64 %15 to i32
%17 = mul nsw i32 %14, %16
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = srem i32 %18, %19
store i32 %20, i32* %6
%21 = load i32, i32* %6
ret i32 %21
}

LLVM IR (-O2):
%struct.random_data = type { i32 }
define i32 @my_rand(%struct.random_data* %0, %struct.random_data* %1) {
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = call i32 @random_r(%struct.random_data* %0, i64* %3)
%8 = call i32 @random_r(%struct.random_data* %1, i64* %4)
%9 = load i64, i64* %3
%10 = trunc i64 %9 to i32
%11 = load i64, i64* %4
%12 = trunc i64 %11 to i32
%13 = mul nsw i32 %12, %10
%14 = srem i32 %13, 1215752192
ret i32 %14
}