#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 */
scalar_t__ drand48();
scalar_t__ lrand48();
int /*<<< orphan*/ srand48(int);
int /*<<< orphan*/ stress_double_put(double);
int /*<<< orphan*/ stress_uint64_put(long);
void __attribute__((hot)) __attribute__((optimize("-O3")))
stress_cpu_rand48(const char *name) {
  int i;
  double d = 0;
  long int l = 0;
  (void)name;
  srand48(0x0defaced);
  for (i = 0; i < 16384; i++) {
    d += drand48();
    l += lrand48();
  }
  stress_double_put(d);
  stress_uint64_put(l);
}


x86 assembly (clang, -O0):
<stress_cpu_rand48>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0xdefaced,%edi
call   1050 <srand48@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x4000,-0xc(%rbp)
jge    11bd <stress_cpu_rand48+0x6d>
mov    $0x0,%al
call   1070 <drand48@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <lrand48@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <stress_cpu_rand48+0x2d>
movsd  -0x18(%rbp),%xmm0
call   1030 <stress_double_put@plt>
mov    -0x20(%rbp),%rdi
call   1060 <stress_uint64_put@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stress_cpu_rand48>:
push   %rbp
push   %rbx
push   %rax
mov    $0xdefaced,%edi
call   1050 <srand48@plt>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    $0x4000,%ebp
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1070 <drand48@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <lrand48@plt>
add    %rax,%rbx
add    $0xffffffff,%ebp
jne    10b0 <stress_cpu_rand48+0x20>
movsd  (%rsp),%xmm0
call   1030 <stress_double_put@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <stress_uint64_put@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax

LLVM IR (-O0):
define void @stress_cpu_rand48(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca double
%5 = alloca i64
store i8* %0, i8** %2
store double 0.000000e+00, double* %4
store i64 0, i64* %5
%6 = load i8*, i8** %2
%7 = call i32 @srand48(i32 233811181)
store i32 0, i32* %3
br label %8
8: ; preds = %19, %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 16384
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = call i64 (...) @drand48()
%13 = sitofp i64 %12 to double
%14 = load double, double* %4
%15 = fadd double %14, %13
store double %15, double* %4
%16 = call i64 (...) @lrand48()
%17 = load i64, i64* %5
%18 = add nsw i64 %17, %16
store i64 %18, i64* %5
br label %19
19: ; preds = %11
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %8
22: ; preds = %8
%23 = load double, double* %4
%24 = call i32 @stress_double_put(double %23)
%25 = load i64, i64* %5
%26 = call i32 @stress_uint64_put(i64 %25)
ret void
}

LLVM IR (-O2):
define void @stress_cpu_rand48(i8* nocapture readnone %0) {
%2 = tail call i32 @srand48(i32 233811181)
br label %3
3: ; preds = %1, %3
%4 = phi i64 [ 0, %1 ], [ %11, %3 ]
%5 = phi double [ 0.000000e+00, %1 ], [ %9, %3 ]
%6 = phi i32 [ 0, %1 ], [ %12, %3 ]
%7 = tail call i64 (...) @drand48()
%8 = sitofp i64 %7 to double
%9 = fadd double %5, %8
%10 = tail call i64 (...) @lrand48()
%11 = add nsw i64 %10, %4
%12 = add nuw nsw i32 %6, 1
%13 = icmp eq i32 %12, 16384
br i1 %13, label %14, label %3
14: ; preds = %3
%15 = tail call i32 @stress_double_put(double %9)
%16 = tail call i32 @stress_uint64_put(i64 %11)
ret void
}