#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 */
double RAND_MAX;
int /*<<< orphan*/ printf(char *, int, int, double);
int rand();
int /*<<< orphan*/ srand(int);
int time(int /*<<< orphan*/ *);
int main() {
  int rnd1, rnd2;
  double rnd3;
  srand(123);
  printf("First 3 numbers for seed 123 are: %d, %d, %d\n", rand(), rand(),
         rand());
  srand(8872);
  printf("First 3 numbers for seed 8872 are: %d, %d, %d\n", rand(), rand(),
         rand());
  srand(time(NULL));
  rnd1 = rand() % 21;
  rnd2 = rand() % 10 - 5;
  rnd3 = ((double)rand()) / RAND_MAX;
  printf("random number1: %d\nrandom number2: %d\nrandom number3: %lf\n", rnd1,
         rnd2, rnd3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x7b,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
cvtsi2sd %eax,%xmm0
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x22a8,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
cvtsi2sd %eax,%xmm0
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x15,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
sub    $0x5,%edx
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %eax,%xmm0
mov    0x2dda(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
movsd  -0x18(%rbp),%xmm0
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x7b,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <rand@plt>
cvtsi2sd %eax,%xmm0
lea    0xe8f(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    $0x22a8,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe83(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rbx
imul   $0x30c30c31,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rax,%rcx,4),%eax
sub    %eax,%ebx
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0xfffffffb,%ebp
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    0x2dc1(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe2b(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"First 3 numbers for seed 123 are: %d, %d, %d\0A\00"
@.str.1 = [47 x i8] c"First 3 numbers for seed 8872 are: %d, %d, %d\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.2 = [59 x i8] c"random number1: %d\0Arandom number2: %d\0Arandom number3: %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
store i32 0, i32* %1
%5 = call i32 @srand(i32 123)
%6 = call i32 (...) @rand()
%7 = call i32 (...) @rand()
%8 = call i32 (...) @rand()
%9 = sitofp i32 %8 to double
%10 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7, double %9)
%11 = call i32 @srand(i32 8872)
%12 = call i32 (...) @rand()
%13 = call i32 (...) @rand()
%14 = call i32 (...) @rand()
%15 = sitofp i32 %14 to double
%16 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13, double %15)
%17 = call i32 @time(i32* null)
%18 = call i32 @srand(i32 %17)
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 21
store i32 %20, i32* %2
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 10
%23 = sub nsw i32 %22, 5
store i32 %23, i32* %3
%24 = call i32 (...) @rand()
%25 = sitofp i32 %24 to double
%26 = load double, double* @RAND_MAX
%27 = fdiv double %25, %26
store double %27, double* %4
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = load double, double* %4
%31 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29, double %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [46 x i8] c"First 3 numbers for seed 123 are: %d, %d, %d\0A\00"
@.str.1 = [47 x i8] c"First 3 numbers for seed 8872 are: %d, %d, %d\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.2 = [59 x i8] c"random number1: %d\0Arandom number2: %d\0Arandom number3: %lf\0A\00"
define i32 @main() {
%1 = tail call i32 @srand(i32 123)
%2 = tail call i32 (...) @rand()
%3 = tail call i32 (...) @rand()
%4 = tail call i32 (...) @rand()
%5 = sitofp i32 %4 to double
%6 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3, double %5)
%7 = tail call i32 @srand(i32 8872)
%8 = tail call i32 (...) @rand()
%9 = tail call i32 (...) @rand()
%10 = tail call i32 (...) @rand()
%11 = sitofp i32 %10 to double
%12 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9, double %11)
%13 = tail call i32 @time(i32* null)
%14 = tail call i32 @srand(i32 %13)
%15 = tail call i32 (...) @rand()
%16 = srem i32 %15, 21
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 10
%19 = add nsw i32 %18, -5
%20 = tail call i32 (...) @rand()
%21 = sitofp i32 %20 to double
%22 = load double, double* @RAND_MAX
%23 = fdiv double %21, %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %19, double %23)
ret i32 0
}