#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 */
struct timeval {
  scalar_t__ tv_usec;
};

/* Variables and functions */
double RAND_MAX;
double get_num(char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *long2str(char *, int);
double rand();
scalar_t__ rint(double);
int /*<<< orphan*/ srand(unsigned int);
char *macrandom(char *arg) {
  double up = get_num("random", arg);
  double low = get_num("random", arg);
  struct timeval t;
  gettimeofday(&t, NULL);
  srand((unsigned int)t.tv_usec);
  return long2str(arg, (int)(low + rint((up - low) / RAND_MAX * rand())));
}


x86 assembly (clang, -O0):
<macrandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1030 <get_num@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1030 <get_num@plt>
movsd  %xmm0,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1050 <srand@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    0x2e17(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <rint@plt>
movsd  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
call   1070 <long2str@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<macrandom>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xe8f(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <get_num@plt>
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <get_num@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x10(%rsp),%edi
call   1050 <srand@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mov    0x2e2f(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
mulsd  (%rsp),%xmm0
call   1060 <rint@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1070 <long2str@plt>

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [7 x i8] c"random\00"
@RAND_MAX = global double 0.000000e+00
define i8* @macrandom(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca double
%5 = alloca %struct.timeval
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call double @get_num(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6)
store double %7, double* %3
%8 = load i8*, i8** %2
%9 = call double @get_num(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %8)
store double %9, double* %4
%10 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = call i32 @srand(i32 %13)
%15 = load i8*, i8** %2
%16 = load double, double* %4
%17 = load double, double* %3
%18 = load double, double* %4
%19 = fsub double %17, %18
%20 = load double, double* @RAND_MAX
%21 = fdiv double %19, %20
%22 = call double (...) @rand()
%23 = fmul double %21, %22
%24 = call i64 @rint(double %23)
%25 = sitofp i64 %24 to double
%26 = fadd double %16, %25
%27 = fptosi double %26 to i32
%28 = call i8* @long2str(i8* %15, i32 %27)
ret i8* %28
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [7 x i8] c"random\00"
@RAND_MAX = global double 0.000000e+00
define i8* @macrandom(i8* %0) {
%2 = alloca %struct.timeval
%3 = tail call double @get_num(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call double @get_num(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = bitcast %struct.timeval* %2 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = trunc i64 %8 to i32
%10 = tail call i32 @srand(i32 %9)
%11 = fsub double %3, %4
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
%14 = tail call double (...) @rand()
%15 = fmul double %13, %14
%16 = tail call i64 @rint(double %15)
%17 = sitofp i64 %16 to double
%18 = fadd double %4, %17
%19 = fptosi double %18 to i32
%20 = tail call i8* @long2str(i8* %0, i32 %19)
ret i8* %20
}