#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 uint8_t;

/* Variables and functions */
double RAND_MAX;
scalar_t__ rand();
uint8_t log_incr(uint8_t counter) {
  if (counter == 255)
    return counter;
  double r = (double)rand() / RAND_MAX;
  double baseval = counter - 5;
  if (baseval < 0)
    baseval = 0;
  double limit = 1.0 / (baseval * 10 + 1);
  if (r < limit)
    counter++;
  return counter;
}


x86 assembly (clang, -O0):
<log_incr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xff,-0x8(%rbp)
jne    1133 <log_incr+0x23>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <log_incr+0xb5>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2ea2(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x5,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1174 <log_incr+0x64>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  0xe87(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe73(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe67(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bf <log_incr+0xaf>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_incr>:
mov    $0xff,%eax
cmp    $0xff,%edi
je     117e <log_incr+0x6e>
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <rand@plt>
mov    0x2eba(%rip),%rcx
xorpd  %xmm0,%xmm0
cmp    $0x5,%ebx
jl     1141 <log_incr+0x31>
lea    -0x5(%rbx),%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
mulsd  0xeb7(%rip),%xmm0
addsd  0xeb7(%rip),%xmm0
movapd 0xeb7(%rip),%xmm1
cvtsi2sd %rax,%xmm1
movsd  (%rcx),%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %al
add    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i32 @log_incr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 255
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* %3
store i32 %10, i32* %2
br label %34
11: ; preds = %1
%12 = call i64 (...) @rand()
%13 = sitofp i64 %12 to double
%14 = load double, double* @RAND_MAX
%15 = fdiv double %13, %14
store double %15, double* %4
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 5
%18 = sitofp i32 %17 to double
store double %18, double* %5
%19 = load double, double* %5
%20 = fcmp olt double %19, 0.000000e+00
br i1 %20, label %21, label %22
21: ; preds = %11
store double 0.000000e+00, double* %5
br label %22
22: ; preds = %21, %11
%23 = load double, double* %5
%24 = call double @llvm.fmuladd.f64(double %23, double 1.000000e+01, double 1.000000e+00)
%25 = fdiv double 1.000000e+00, %24
store double %25, double* %6
%26 = load double, double* %4
%27 = load double, double* %6
%28 = fcmp olt double %26, %27
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %32
32: ; preds = %29, %22
%33 = load i32, i32* %3
store i32 %33, i32* %2
br label %34
34: ; preds = %32, %9
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i32 @log_incr(i32 %0) {
%2 = icmp eq i32 %0, 255
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = tail call i64 (...) @rand()
%5 = sitofp i64 %4 to double
%6 = load double, double* @RAND_MAX
%7 = add nsw i32 %0, -5
%8 = sitofp i32 %7 to double
%9 = icmp slt i32 %0, 5
%10 = select i1 %9, double 0.000000e+00, double %8
%11 = tail call double @llvm.fmuladd.f64(double %10, double 1.000000e+01, double 1.000000e+00)
%12 = insertelement <2 x double> <double poison, double 1.000000e+00>, double %5, i64 0
%13 = insertelement <2 x double> poison, double %6, i64 0
%14 = insertelement <2 x double> %13, double %11, i64 1
%15 = fdiv <2 x double> %12, %14
%16 = extractelement <2 x double> %15, i64 0
%17 = extractelement <2 x double> %15, i64 1
%18 = fcmp olt double %16, %17
%19 = zext i1 %18 to i32
%20 = add nsw i32 %19, %0
br label %21
21: ; preds = %1, %3
%22 = phi i32 [ %20, %3 ], [ 255, %1 ]
ret i32 %22
}