#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 /*<<< orphan*/ adjustStrength(int, int, double *, double *);
double drand(double, double);
int /*<<< orphan*/ printf(char *, double, double, double, double, int, int, int,
                          int, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(double);
int main(int argc, const char *argv[]) {
  srand(time(NULL));
  int aPower = 200;
  int bPower = 200;
  double aStrength = 1.0;
  double bStrength = 1.0;
  double aRatio = drand(1.800, 2.000);
  double bRatio = drand(1.400, 1.600);
  double aCount = 0;
  double bCount = 0;
  double step = 0.0008;
  int desiredCount = 100;
  int actualCount = 0;
  double percentLeft = 1.0;
  while (actualCount < desiredCount) {
    aCount += (double)aPower * aStrength * aRatio * step;
    bCount += (double)bPower * bStrength * bRatio * step;
    actualCount = ((int)aCount + (int)bCount) / 2;
    percentLeft = 1.0 - ((double)actualCount / (double)desiredCount);
    aPower = (200 - 50) * percentLeft + 50;
    bPower = (200 - 60) * percentLeft + 60;
    printf("ratio(%.4f, %.4f) strength(%.4f, %.4f) power(% 5d, % 5d) count(% "
           "4d, % 4d) = % 2d\n",
           aRatio, bRatio, aStrength, bStrength, aPower, bPower, (int)aCount,
           (int)bCount, ((int)aCount - (int)bCount));
    adjustStrength((int)aCount, (int)bCount, &aStrength, &bStrength);
    aRatio += drand(-0.0001, 0.0001);
    bRatio += drand(-0.0001, 0.0001);
    usleep(step * 1000000);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0xc8,-0x14(%rbp)
movl   $0xc8,-0x18(%rbp)
movsd  0xe64(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe57(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe6a(%rip),%xmm0
movsd  0xe6a(%rip),%xmm1
call   1040 <drand@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  0xe40(%rip),%xmm0
movsd  0xe40(%rip),%xmm1
call   1040 <drand@plt>
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe0e(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x64,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movsd  0xdeb(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    139b <main+0x23b>
cvtsi2sdl -0x14(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
cvttsd2si -0x40(%rbp),%eax
cvttsd2si -0x48(%rbp),%ecx
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
cvtsi2sdl -0x58(%rbp),%xmm1
cvtsi2sdl -0x54(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd61(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  0xda3(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd9f(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  0xd6f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd6b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
cvttsd2si -0x40(%rbp),%ecx
cvttsd2si -0x48(%rbp),%r8d
cvttsd2si -0x40(%rbp),%r9d
cvttsd2si -0x48(%rbp),%eax
sub    %eax,%r9d
lea    0xd3e(%rip),%rdi
call   1050 <printf@plt>
cvttsd2si -0x40(%rbp),%edi
cvttsd2si -0x48(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <adjustStrength@plt>
movsd  0xcea(%rip),%xmm0
movsd  0xcea(%rip),%xmm1
call   1040 <drand@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xccb(%rip),%xmm0
movsd  0xccb(%rip),%xmm1
call   1040 <drand@plt>
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xca4(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
call   1080 <usleep@plt>
jmp    121a <main+0xba>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movabs $0x3ff0000000000000,%rax
mov    %rax,0x8(%rsp)
mov    %rax,(%rsp)
movsd  0xe69(%rip),%xmm0
movsd  0xe69(%rip),%xmm1
call   1040 <drand@plt>
movaps %xmm0,0x10(%rsp)
movsd  0xe5f(%rip),%xmm0
movsd  0xe5f(%rip),%xmm1
call   1040 <drand@plt>
movapd %xmm0,%xmm1
unpcklpd 0x10(%rsp),%xmm1
movaps 0xe81(%rip),%xmm2
movapd 0xe89(%rip),%xmm3
xorpd  %xmm0,%xmm0
lea    0xebe(%rip),%r14
lea    0x8(%rsp),%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
cvtdq2pd %xmm2,%xmm2
mulpd  %xmm3,%xmm2
mulpd  %xmm1,%xmm2
mulpd  0xe6c(%rip),%xmm2
addpd  %xmm0,%xmm2
movapd %xmm2,0x50(%rsp)
cvttpd2dq %xmm2,%xmm0
movd   %xmm0,%r13d
pshufd $0x55,%xmm0,%xmm0
movd   %xmm0,%ebx
lea    (%rbx,%r13,1),%ebp
mov    %ebp,%eax
shr    $0x1f,%eax
add    %ebp,%eax
sar    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xde4(%rip),%xmm0
addsd  0xde4(%rip),%xmm0
unpcklpd %xmm0,%xmm0
mulpd  0xe30(%rip),%xmm0
addpd  0xe38(%rip),%xmm0
cvttpd2dq %xmm0,%xmm0
movd   %xmm0,%edx
movaps %xmm0,0x40(%rsp)
pshufd $0x55,%xmm0,%xmm0
movd   %xmm0,%esi
mov    %ebx,%r9d
sub    %r13d,%r9d
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
movapd %xmm3,%xmm2
unpckhpd %xmm3,%xmm2
mov    %r14,%rdi
movapd %xmm1,0x10(%rsp)
mov    %ebx,%ecx
mov    %r13d,%r8d
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r13d,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1030 <adjustStrength@plt>
movsd  0xd81(%rip),%xmm0
movsd  0xd81(%rip),%xmm1
call   1040 <drand@plt>
movaps %xmm0,0x30(%rsp)
movsd  0xd67(%rip),%xmm0
movsd  0xd67(%rip),%xmm1
call   1040 <drand@plt>
movaps %xmm0,0x20(%rsp)
movsd  0xd5d(%rip),%xmm0
call   1080 <usleep@plt>
cmp    $0xc7,%ebp
jg     1321 <main+0x1c1>
movapd 0x20(%rsp),%xmm0
unpcklpd 0x30(%rsp),%xmm0
movapd 0x10(%rsp),%xmm1
addpd  %xmm0,%xmm1
movsd  (%rsp),%xmm3
movhpd 0x8(%rsp),%xmm3
movapd 0x50(%rsp),%xmm0
movaps 0x40(%rsp),%xmm2
jmp    11f0 <main+0x90>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [83 x i8] c"ratio(%.4f, %.4f) strength(%.4f, %.4f) power(% 5d, % 5d) count(% 4d, % 4d) = % 2d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = call i32 @time(i32* null)
%19 = call i32 @srand(i32 %18)
store i32 200, i32* %6
store i32 200, i32* %7
store double 1.000000e+00, double* %8
store double 1.000000e+00, double* %9
%20 = call double @drand(double 1.800000e+00, double 2.000000e+00)
store double %20, double* %10
%21 = call double @drand(double 1.400000e+00, double 1.600000e+00)
store double %21, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store double 8.000000e-04, double* %14
store i32 100, i32* %15
store i32 0, i32* %16
store double 1.000000e+00, double* %17
br label %22
22: ; preds = %26, %2
%23 = load i32, i32* %16
%24 = load i32, i32* %15
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %93
26: ; preds = %22
%27 = load i32, i32* %6
%28 = sitofp i32 %27 to double
%29 = load double, double* %8
%30 = fmul double %28, %29
%31 = load double, double* %10
%32 = fmul double %30, %31
%33 = load double, double* %14
%34 = load double, double* %12
%35 = call double @llvm.fmuladd.f64(double %32, double %33, double %34)
store double %35, double* %12
%36 = load i32, i32* %7
%37 = sitofp i32 %36 to double
%38 = load double, double* %9
%39 = fmul double %37, %38
%40 = load double, double* %11
%41 = fmul double %39, %40
%42 = load double, double* %14
%43 = load double, double* %13
%44 = call double @llvm.fmuladd.f64(double %41, double %42, double %43)
store double %44, double* %13
%45 = load double, double* %12
%46 = fptosi double %45 to i32
%47 = load double, double* %13
%48 = fptosi double %47 to i32
%49 = add nsw i32 %46, %48
%50 = sdiv i32 %49, 2
store i32 %50, i32* %16
%51 = load i32, i32* %16
%52 = sitofp i32 %51 to double
%53 = load i32, i32* %15
%54 = sitofp i32 %53 to double
%55 = fdiv double %52, %54
%56 = fsub double 1.000000e+00, %55
store double %56, double* %17
%57 = load double, double* %17
%58 = call double @llvm.fmuladd.f64(double 1.500000e+02, double %57, double 5.000000e+01)
%59 = fptosi double %58 to i32
store i32 %59, i32* %6
%60 = load double, double* %17
%61 = call double @llvm.fmuladd.f64(double 1.400000e+02, double %60, double 6.000000e+01)
%62 = fptosi double %61 to i32
store i32 %62, i32* %7
%63 = load double, double* %10
%64 = load double, double* %11
%65 = load double, double* %8
%66 = load double, double* %9
%67 = load i32, i32* %6
%68 = load i32, i32* %7
%69 = load double, double* %12
%70 = fptosi double %69 to i32
%71 = load double, double* %13
%72 = fptosi double %71 to i32
%73 = load double, double* %12
%74 = fptosi double %73 to i32
%75 = load double, double* %13
%76 = fptosi double %75 to i32
%77 = sub nsw i32 %74, %76
%78 = call i32 @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), double %63, double %64, double %65, double %66, i32 %67, i32 %68, i32 %70, i32 %72, i32 %77)
%79 = load double, double* %12
%80 = fptosi double %79 to i32
%81 = load double, double* %13
%82 = fptosi double %81 to i32
%83 = call i32 @adjustStrength(i32 %80, i32 %82, double* %8, double* %9)
%84 = call double @drand(double -1.000000e-04, double 1.000000e-04)
%85 = load double, double* %10
%86 = fadd double %85, %84
store double %86, double* %10
%87 = call double @drand(double -1.000000e-04, double 1.000000e-04)
%88 = load double, double* %11
%89 = fadd double %88, %87
store double %89, double* %11
%90 = load double, double* %14
%91 = fmul double %90, 1.000000e+06
%92 = call i32 @usleep(double %91)
br label %22
93: ; preds = %22
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str = [83 x i8] c"ratio(%.4f, %.4f) strength(%.4f, %.4f) power(% 5d, % 5d) count(% 4d, % 4d) = % 2d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = alloca double
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = bitcast double* %3 to i8*
store double 1.000000e+00, double* %3
%8 = bitcast double* %4 to i8*
store double 1.000000e+00, double* %4
%9 = tail call double @drand(double 1.800000e+00, double 2.000000e+00)
%10 = tail call double @drand(double 1.400000e+00, double 1.600000e+00)
%11 = insertelement <2 x double> poison, double %10, i64 0
%12 = insertelement <2 x double> %11, double %9, i64 1
br label %13
13: ; preds = %47, %2
%14 = phi <2 x double> [ zeroinitializer, %2 ], [ %21, %47 ]
%15 = phi <2 x double> [ %12, %2 ], [ %50, %47 ]
%16 = phi <2 x double> [ <double 1.000000e+00, double 1.000000e+00>, %2 ], [ %54, %47 ]
%17 = phi <2 x i32> [ <i32 200, i32 200>, %2 ], [ %33, %47 ]
%18 = sitofp <2 x i32> %17 to <2 x double>
%19 = fmul <2 x double> %16, %18
%20 = fmul <2 x double> %15, %19
%21 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %20, <2 x double> <double 8.000000e-04, double 8.000000e-04>, <2 x double> %14)
%22 = fptosi <2 x double> %21 to <2 x i32>
%23 = extractelement <2 x i32> %22, i64 0
%24 = extractelement <2 x i32> %22, i64 1
%25 = add nsw i32 %23, %24
%26 = sdiv i32 %25, 2
%27 = sitofp i32 %26 to double
%28 = fdiv double %27, 1.000000e+02
%29 = fsub double 1.000000e+00, %28
%30 = insertelement <2 x double> poison, double %29, i64 0
%31 = shufflevector <2 x double> %30, <2 x double> poison, <2 x i32> zeroinitializer
%32 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> <double 1.400000e+02, double 1.500000e+02>, <2 x double> <double 6.000000e+01, double 5.000000e+01>)
%33 = fptosi <2 x double> %32 to <2 x i32>
%34 = sub nsw i32 %24, %23
%35 = extractelement <2 x double> %15, i64 0
%36 = extractelement <2 x double> %15, i64 1
%37 = extractelement <2 x double> %16, i64 0
%38 = extractelement <2 x double> %16, i64 1
%39 = extractelement <2 x i32> %33, i64 0
%40 = extractelement <2 x i32> %33, i64 1
%41 = call i32 @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), double %36, double %35, double %38, double %37, i32 %40, i32 %39, i32 %24, i32 %23, i32 %34)
%42 = call i32 @adjustStrength(i32 %24, i32 %23, double* %3, double* %4)
%43 = call double @drand(double -1.000000e-04, double 1.000000e-04)
%44 = call double @drand(double -1.000000e-04, double 1.000000e-04)
%45 = call i32 @usleep(double 8.000000e+02)
%46 = icmp slt i32 %25, 200
br i1 %46, label %47, label %55
47: ; preds = %13
%48 = insertelement <2 x double> poison, double %44, i64 0
%49 = insertelement <2 x double> %48, double %43, i64 1
%50 = fadd <2 x double> %15, %49
%51 = load double, double* %3
%52 = load double, double* %4
%53 = insertelement <2 x double> poison, double %52, i64 0
%54 = insertelement <2 x double> %53, double %51, i64 1
br label %13
55: ; preds = %13
ret i32 0
}