#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 RAND_MAX;
int rand();
void cwirc_simulate_sporadicE(double *signal_strength, double ticklen) {
  static double rnd_update_timeout = 0;
  static double dir = 1;
  static double attn = 1;
  if (rnd_update_timeout <= 0) {
    dir = rand() > RAND_MAX / 2 ? ticklen / 300 : 0;
    rnd_update_timeout = 500;
  }
  rnd_update_timeout -= ticklen;
  attn = (attn + dir) / (1 + ticklen / 300);
  if (*signal_strength < 0.2)
    *signal_strength *= attn;
}


x86 assembly (clang, -O0):
<cwirc_simulate_sporadicE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd 0x2f14(%rip),%xmm0
jb     119f <cwirc_simulate_sporadicE+0x8f>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jle    1175 <cwirc_simulate_sporadicE+0x65>
movsd  -0x10(%rbp),%xmm0
movsd  0xe99(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1182 <cwirc_simulate_sporadicE+0x72>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1182 <cwirc_simulate_sporadicE+0x72>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,0x2e99(%rip)
movsd  0xe71(%rip),%xmm0
movsd  %xmm0,0x2ea1(%rip)
movsd  -0x10(%rbp),%xmm1
movsd  0x2e94(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x2e88(%rip)
movsd  0x2e70(%rip),%xmm0
addsd  0x2e60(%rip),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xe2b(%rip),%xmm1
divsd  %xmm1,%xmm2
movsd  0xe37(%rip),%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x2e3f(%rip)
mov    -0x8(%rbp),%rax
movsd  0xe13(%rip),%xmm0
ucomisd (%rax),%xmm0
jbe    121b <cwirc_simulate_sporadicE+0x10b>
movsd  0x2e21(%rip),%xmm0
mov    -0x8(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cwirc_simulate_sporadicE>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  0x2f20(%rip),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
jae    1140 <cwirc_simulate_sporadicE+0x30>
movsd  0x2ef6(%rip),%xmm3
movapd %xmm0,%xmm1
divsd  0xec2(%rip),%xmm1
jmp    118d <cwirc_simulate_sporadicE+0x7d>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1030 <rand@plt>
movsd  0x8(%rsp),%xmm0
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
movapd %xmm0,%xmm1
divsd  0xe8f(%rip),%xmm1
movapd %xmm1,%xmm3
cmp    %edx,%eax
jg     117d <cwirc_simulate_sporadicE+0x6d>
xorpd  %xmm3,%xmm3
movsd  %xmm3,0x2ea3(%rip)
movsd  0xe7b(%rip),%xmm2
subsd  %xmm0,%xmm2
movsd  %xmm2,0x2ea7(%rip)
addsd  0x2e8f(%rip),%xmm3
addsd  0xe67(%rip),%xmm1
divsd  %xmm1,%xmm3
movsd  %xmm3,0x2e7b(%rip)
movsd  (%rbx),%xmm1
movsd  0xe57(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    11cf <cwirc_simulate_sporadicE+0xbf>
mulsd  %xmm3,%xmm1
movsd  %xmm1,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@cwirc_simulate_sporadicE.rnd_update_timeout = internal global double 0.000000e+00
@cwirc_simulate_sporadicE.dir = internal global double 1.000000e+00
@cwirc_simulate_sporadicE.attn = internal global double 1.000000e+00
@RAND_MAX = global i32 0
define void @cwirc_simulate_sporadicE(double* %0, double %1) {
%3 = alloca double*
%4 = alloca double
store double* %0, double** %3
store double %1, double* %4
%5 = load double, double* @cwirc_simulate_sporadicE.rnd_update_timeout
%6 = fcmp ole double %5, 0.000000e+00
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = call i32 (...) @rand()
%9 = load i32, i32* @RAND_MAX
%10 = sdiv i32 %9, 2
%11 = icmp sgt i32 %8, %10
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load double, double* %4
%14 = fdiv double %13, 3.000000e+02
br label %16
15: ; preds = %7
br label %16
16: ; preds = %15, %12
%17 = phi double [ %14, %12 ], [ 0.000000e+00, %15 ]
store double %17, double* @cwirc_simulate_sporadicE.dir
store double 5.000000e+02, double* @cwirc_simulate_sporadicE.rnd_update_timeout
br label %18
18: ; preds = %16, %2
%19 = load double, double* %4
%20 = load double, double* @cwirc_simulate_sporadicE.rnd_update_timeout
%21 = fsub double %20, %19
store double %21, double* @cwirc_simulate_sporadicE.rnd_update_timeout
%22 = load double, double* @cwirc_simulate_sporadicE.attn
%23 = load double, double* @cwirc_simulate_sporadicE.dir
%24 = fadd double %22, %23
%25 = load double, double* %4
%26 = fdiv double %25, 3.000000e+02
%27 = fadd double 1.000000e+00, %26
%28 = fdiv double %24, %27
store double %28, double* @cwirc_simulate_sporadicE.attn
%29 = load double*, double** %3
%30 = load double, double* %29
%31 = fcmp olt double %30, 2.000000e-01
br i1 %31, label %32, label %37
32: ; preds = %18
%33 = load double, double* @cwirc_simulate_sporadicE.attn
%34 = load double*, double** %3
%35 = load double, double* %34
%36 = fmul double %35, %33
store double %36, double* %34
br label %37
37: ; preds = %32, %18
ret void
}

LLVM IR (-O2):
@cwirc_simulate_sporadicE.rnd_update_timeout = internal unnamed_addr global double 0.000000e+00
@cwirc_simulate_sporadicE.dir = internal unnamed_addr global double 1.000000e+00
@cwirc_simulate_sporadicE.attn = internal unnamed_addr global double 1.000000e+00
@RAND_MAX = global i32 0
define void @cwirc_simulate_sporadicE(double* nocapture %0, double %1) {
%3 = load double, double* @cwirc_simulate_sporadicE.rnd_update_timeout
%4 = fcmp ugt double %3, 0.000000e+00
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load double, double* @cwirc_simulate_sporadicE.dir
%7 = fdiv double %1, 3.000000e+02
br label %15
8: ; preds = %2
%9 = tail call i32 (...) @rand()
%10 = load i32, i32* @RAND_MAX
%11 = sdiv i32 %10, 2
%12 = icmp sgt i32 %9, %11
%13 = fdiv double %1, 3.000000e+02
%14 = select i1 %12, double %13, double 0.000000e+00
store double %14, double* @cwirc_simulate_sporadicE.dir
br label %15
15: ; preds = %5, %8
%16 = phi double [ %7, %5 ], [ %13, %8 ]
%17 = phi double [ %6, %5 ], [ %14, %8 ]
%18 = phi double [ %3, %5 ], [ 5.000000e+02, %8 ]
%19 = fsub double %18, %1
store double %19, double* @cwirc_simulate_sporadicE.rnd_update_timeout
%20 = load double, double* @cwirc_simulate_sporadicE.attn
%21 = fadd double %20, %17
%22 = fadd double %16, 1.000000e+00
%23 = fdiv double %21, %22
store double %23, double* @cwirc_simulate_sporadicE.attn
%24 = load double, double* %0
%25 = fcmp olt double %24, 2.000000e-01
br i1 %25, label %26, label %28
26: ; preds = %15
%27 = fmul double %24, %23
store double %27, double* %0
br label %28
28: ; preds = %26, %15
ret void
}