#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 */
struct Solver {
  int dummy;
};

/* Variables and functions */
struct Solver *SolverCreate(double, int, int);
int /*<<< orphan*/ SolverDestroy(struct Solver *);
int /*<<< orphan*/ SolverDump(struct Solver *);
int /*<<< orphan*/ SolverStep(struct Solver *, double);
double exp(double);
int log(double);
int main(int argc, char **argv) {
  double a = 0.01;
  size_t nsteps = 1;
  struct Solver *solver = SolverCreate(a, 10, 1);
  SolverDump(solver);
  double logastep = (1 - log(a)) / (double)nsteps;
  for (double loga = log(a); loga <= 1; loga += logastep) {
    double newa = exp(loga);
    SolverStep(solver, newa);
    SolverDump(solver);
  }
  double newa = 1.;
  SolverStep(solver, newa);
  SolverDump(solver);
  SolverDestroy(solver);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x3f847ae147ae147b,%rax
7a 84 3f
mov    %rax,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    $0xa,%edi
mov    $0x1,%esi
mov    %esi,-0x4c(%rbp)
call   1080 <SolverCreate@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <SolverDump@plt>
movsd  -0x18(%rbp),%xmm0
call   1070 <log@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movaps 0xe34(%rip),%xmm2
movq   -0x20(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xe33(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1070 <log@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe10(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     1255 <main+0xf5>
movsd  -0x38(%rbp),%xmm0
call   1060 <exp@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
call   1050 <SolverStep@plt>
mov    -0x28(%rbp),%rdi
call   1040 <SolverDump@plt>
movsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1208 <main+0xa8>
movsd  0xdc3(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
movsd  -0x48(%rbp),%xmm0
call   1050 <SolverStep@plt>
mov    -0x28(%rbp),%rdi
call   1040 <SolverDump@plt>
mov    -0x28(%rbp),%rdi
call   1030 <SolverDestroy@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  0xe90(%rip),%xmm0
mov    $0x1,%ebp
mov    $0xa,%edi
mov    $0x1,%esi
call   1080 <SolverCreate@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <SolverDump@plt>
movsd  0xe69(%rip),%xmm0
call   1070 <log@plt>
mov    %eax,%r14d
movsd  0xe59(%rip),%xmm0
call   1070 <log@plt>
cmp    $0x1,%eax
jg     1208 <main+0xa8>
sub    %r14d,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
call   1060 <exp@plt>
mov    %rbx,%rdi
call   1050 <SolverStep@plt>
mov    %rbx,%rdi
call   1040 <SolverDump@plt>
movsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  0xe06(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    11d0 <main+0x70>
movsd  0xdf8(%rip),%xmm0
mov    %rbx,%rdi
call   1050 <SolverStep@plt>
mov    %rbx,%rdi
call   1040 <SolverDump@plt>
mov    %rbx,%rdi
call   1030 <SolverDestroy@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.Solver = type { i32 }
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i64
%8 = alloca %struct.Solver*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 1.000000e-02, double* %6
store i64 1, i64* %7
%13 = load double, double* %6
%14 = call %struct.Solver* @SolverCreate(double %13, i32 10, i32 1)
store %struct.Solver* %14, %struct.Solver** %8
%15 = load %struct.Solver*, %struct.Solver** %8
%16 = call i32 @SolverDump(%struct.Solver* %15)
%17 = load double, double* %6
%18 = call i32 @log(double %17)
%19 = sub nsw i32 1, %18
%20 = sitofp i32 %19 to double
%21 = load i64, i64* %7
%22 = uitofp i64 %21 to double
%23 = fdiv double %20, %22
store double %23, double* %9
%24 = load double, double* %6
%25 = call i32 @log(double %24)
%26 = sitofp i32 %25 to double
store double %26, double* %10
br label %27
27: ; preds = %38, %2
%28 = load double, double* %10
%29 = fcmp ole double %28, 1.000000e+00
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load double, double* %10
%32 = call double @exp(double %31)
store double %32, double* %11
%33 = load %struct.Solver*, %struct.Solver** %8
%34 = load double, double* %11
%35 = call i32 @SolverStep(%struct.Solver* %33, double %34)
%36 = load %struct.Solver*, %struct.Solver** %8
%37 = call i32 @SolverDump(%struct.Solver* %36)
br label %38
38: ; preds = %30
%39 = load double, double* %9
%40 = load double, double* %10
%41 = fadd double %40, %39
store double %41, double* %10
br label %27
42: ; preds = %27
store double 1.000000e+00, double* %12
%43 = load %struct.Solver*, %struct.Solver** %8
%44 = load double, double* %12
%45 = call i32 @SolverStep(%struct.Solver* %43, double %44)
%46 = load %struct.Solver*, %struct.Solver** %8
%47 = call i32 @SolverDump(%struct.Solver* %46)
%48 = load %struct.Solver*, %struct.Solver** %8
%49 = call i32 @SolverDestroy(%struct.Solver* %48)
ret i32 0
}

LLVM IR (-O2):
%struct.Solver = type { i32 }
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.Solver* @SolverCreate(double 1.000000e-02, i32 10, i32 1)
%4 = tail call i32 @SolverDump(%struct.Solver* %3)
%5 = tail call i32 @log(double 1.000000e-02)
%6 = sub nsw i32 1, %5
%7 = sitofp i32 %6 to double
%8 = tail call i32 @log(double 1.000000e-02)
%9 = icmp sgt i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = sitofp i32 %8 to double
br label %16
12: ; preds = %16, %2
%13 = tail call i32 @SolverStep(%struct.Solver* %3, double 1.000000e+00)
%14 = tail call i32 @SolverDump(%struct.Solver* %3)
%15 = tail call i32 @SolverDestroy(%struct.Solver* %3)
ret i32 0
16: ; preds = %10, %16
%17 = phi double [ %21, %16 ], [ %11, %10 ]
%18 = tail call double @exp(double %17)
%19 = tail call i32 @SolverStep(%struct.Solver* %3, double %18)
%20 = tail call i32 @SolverDump(%struct.Solver* %3)
%21 = fadd double %17, %7
%22 = fcmp ugt double %21, 1.000000e+00
br i1 %22, label %12, label %16
}