#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 */
double log(double const);
int logs2x(double crval, int nlogc, int slogc, int sx, const double logc[],
           double x[], int stat[]) {
  int status;
  register int ilogc;
  register int *statp;
  register const double *logcp;
  register double *xp;
  if (crval <= 0.0) {
    return 2;
  }
  xp = x;
  logcp = logc;
  statp = stat;
  status = 0;
  for (ilogc = 0; ilogc < nlogc; ilogc++, logcp += slogc, xp += sx) {
    if (*logcp > 0.0) {
      *xp = crval * log(*logcp / crval);
      *(statp++) = 0;
    } else {
      *(statp++) = 1;
      status = 4;
    }
  }
  return status;
}


x86 assembly (clang, -O0):
<logs2x>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     114c <logs2x+0x3c>
movl   $0x2,-0x4(%rbp)
jmp    123c <logs2x+0x12c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1236 <logs2x+0x126>
mov    -0x50(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11dd <logs2x+0xcd>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x50(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x58(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x48(%rbp)
movl   $0x0,(%rax)
jmp    11f9 <logs2x+0xe9>
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x48(%rbp)
movl   $0x1,(%rax)
movl   $0x4,-0x3c(%rbp)
jmp    11fe <logs2x+0xee>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
jmp    1172 <logs2x+0x62>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logs2x>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x2,0x4(%rsp)
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%rsp)
ucomisd %xmm0,%xmm1
jae    11d6 <logs2x+0xc6>
test   %edi,%edi
jle    11ce <logs2x+0xbe>
mov    %r9,%r13
mov    %r8,%r15
mov    %rcx,%rbx
movslq %esi,%rbp
movslq %edx,%rdx
shl    $0x3,%rdx
shl    $0x3,%rbp
mov    %edi,%r12d
xor    %r14d,%r14d
xorpd  %xmm1,%xmm1
movl   $0x0,0x4(%rsp)
mov    %rdx,0x10(%rsp)
jmp    11b5 <logs2x+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
divsd  0x8(%rsp),%xmm0
call   1030 <log@plt>
xorpd  %xmm1,%xmm1
mov    0x10(%rsp),%rdx
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r15)
xor    %eax,%eax
mov    %eax,0x0(%r13,%r14,4)
add    %rdx,%r15
add    %rbp,%rbx
add    $0x1,%r14
cmp    %r14d,%r12d
je     11d6 <logs2x+0xc6>
movsd  (%rbx),%xmm0
ucomisd %xmm1,%xmm0
ja     1180 <logs2x+0x70>
movl   $0x4,0x4(%rsp)
mov    $0x1,%eax
jmp    11a1 <logs2x+0x91>
movl   $0x0,0x4(%rsp)
mov    0x4(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @logs2x(double %0, i32 %1, i32 %2, i32 %3, double* %4, double* %5, i32* %6) {
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32*
%19 = alloca double*
%20 = alloca double*
store double %0, double* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store double* %4, double** %13
store double* %5, double** %14
store i32* %6, i32** %15
%21 = load double, double* %9
%22 = fcmp ole double %21, 0.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %7
store i32 2, i32* %8
br label %64
24: ; preds = %7
%25 = load double*, double** %14
store double* %25, double** %20
%26 = load double*, double** %13
store double* %26, double** %19
%27 = load i32*, i32** %15
store i32* %27, i32** %18
store i32 0, i32* %16
store i32 0, i32* %17
br label %28
28: ; preds = %51, %24
%29 = load i32, i32* %17
%30 = load i32, i32* %10
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %62
32: ; preds = %28
%33 = load double*, double** %19
%34 = load double, double* %33
%35 = fcmp ogt double %34, 0.000000e+00
br i1 %35, label %36, label %47
36: ; preds = %32
%37 = load double, double* %9
%38 = load double*, double** %19
%39 = load double, double* %38
%40 = load double, double* %9
%41 = fdiv double %39, %40
%42 = call double @log(double %41)
%43 = fmul double %37, %42
%44 = load double*, double** %20
store double %43, double* %44
%45 = load i32*, i32** %18
%46 = getelementptr inbounds i32, i32* %45, i32 1
store i32* %46, i32** %18
store i32 0, i32* %45
br label %50
47: ; preds = %32
%48 = load i32*, i32** %18
%49 = getelementptr inbounds i32, i32* %48, i32 1
store i32* %49, i32** %18
store i32 1, i32* %48
store i32 4, i32* %16
br label %50
50: ; preds = %47, %36
br label %51
51: ; preds = %50
%52 = load i32, i32* %17
%53 = add nsw i32 %52, 1
store i32 %53, i32* %17
%54 = load i32, i32* %11
%55 = load double*, double** %19
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds double, double* %55, i64 %56
store double* %57, double** %19
%58 = load i32, i32* %12
%59 = load double*, double** %20
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds double, double* %59, i64 %60
store double* %61, double** %20
br label %28
62: ; preds = %28
%63 = load i32, i32* %16
store i32 %63, i32* %8
br label %64
64: ; preds = %62, %23
%65 = load i32, i32* %8
ret i32 %65
}

LLVM IR (-O2):
define i32 @logs2x(double %0, i32 %1, i32 %2, i32 %3, double* nocapture %4, double* nocapture writeonly %5, i32* nocapture writeonly %6) {
%8 = fcmp ugt double %0, 0.000000e+00
br i1 %8, label %9, label %34
9: ; preds = %7
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %34
11: ; preds = %9
%12 = sext i32 %2 to i64
%13 = sext i32 %3 to i64
br label %14
14: ; preds = %11, %26
%15 = phi double* [ %5, %11 ], [ %32, %26 ]
%16 = phi double* [ %4, %11 ], [ %31, %26 ]
%17 = phi i32* [ %6, %11 ], [ %29, %26 ]
%18 = phi i32 [ 0, %11 ], [ %30, %26 ]
%19 = phi i32 [ 0, %11 ], [ %28, %26 ]
%20 = load double, double* %16
%21 = fcmp ogt double %20, 0.000000e+00
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = fdiv double %20, %0
%24 = tail call double @log(double %23)
%25 = fmul double %24, %0
store double %25, double* %15
br label %26
26: ; preds = %14, %22
%27 = phi i32 [ 0, %22 ], [ 1, %14 ]
%28 = phi i32 [ %19, %22 ], [ 4, %14 ]
%29 = getelementptr inbounds i32, i32* %17, i64 1
store i32 %27, i32* %17
%30 = add nuw nsw i32 %18, 1
%31 = getelementptr inbounds double, double* %16, i64 %12
%32 = getelementptr inbounds double, double* %15, i64 %13
%33 = icmp eq i32 %30, %1
br i1 %33, label %34, label %14
34: ; preds = %26, %9, %7
%35 = phi i32 [ 2, %7 ], [ 0, %9 ], [ %28, %26 ]
ret i32 %35
}