#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 */
float exp(float);
double fabs(float);
float log(float n) {
  float antilog, x, old;
  x = 10.0;
  old = 0.0;
  while (fabs(old - x) > 0.000001) {
    old = x;
    antilog = exp(x);
    x -= (antilog - n) / antilog;
  }
  return x;
}


x86 assembly (clang, -O0):
<log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xecb(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1030 <fabs@plt>
movsd  0xeaf(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119e <log+0x7e>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <exp@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm1
subss  -0x4(%rbp),%xmm1
divss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1142 <log+0x22>
movss  -0xc(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log>:
sub    $0x18,%rsp
movss  %xmm0,0x10(%rsp)
movss  0xece(%rip),%xmm0
call   1030 <fabs@plt>
ucomisd 0xec9(%rip),%xmm0
jbe    1199 <log+0x79>
movss  0xebb(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
nop
movss  %xmm0,0x14(%rsp)
call   1040 <exp@plt>
movaps %xmm0,%xmm1
subss  0x10(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0xc(%rsp),%xmm2
subss  %xmm1,%xmm2
movss  %xmm2,0xc(%rsp)
movss  0x14(%rsp),%xmm0
subss  %xmm2,%xmm0
call   1030 <fabs@plt>
ucomisd 0xe79(%rip),%xmm0
movss  0xc(%rsp),%xmm0
ja     1150 <log+0x30>
jmp    11a7 <log+0x87>
movss  0xe63(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0xc(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @log(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
store float %0, float* %2
store float 1.000000e+01, float* %4
store float 0.000000e+00, float* %5
br label %6
6: ; preds = %12, %1
%7 = load float, float* %5
%8 = load float, float* %4
%9 = fsub float %7, %8
%10 = call double @fabs(float %9)
%11 = fcmp ogt double %10, 0x3EB0C6F7A0B5ED8D
br i1 %11, label %12, label %23
12: ; preds = %6
%13 = load float, float* %4
store float %13, float* %5
%14 = load float, float* %4
%15 = call float @exp(float %14)
store float %15, float* %3
%16 = load float, float* %3
%17 = load float, float* %2
%18 = fsub float %16, %17
%19 = load float, float* %3
%20 = fdiv float %18, %19
%21 = load float, float* %4
%22 = fsub float %21, %20
store float %22, float* %4
br label %6
23: ; preds = %6
%24 = load float, float* %4
ret float %24
}

LLVM IR (-O2):
define float @log(float %0) {
%2 = tail call double @fabs(float -1.000000e+01)
%3 = fcmp ogt double %2, 0x3EB0C6F7A0B5ED8D
br i1 %3, label %4, label %13
4: ; preds = %1, %4
%5 = phi float [ %9, %4 ], [ 1.000000e+01, %1 ]
%6 = tail call float @exp(float %5)
%7 = fsub float %6, %0
%8 = fdiv float %7, %6
%9 = fsub float %5, %8
%10 = fsub float %5, %9
%11 = tail call double @fabs(float %10)
%12 = fcmp ogt double %11, 0x3EB0C6F7A0B5ED8D
br i1 %12, label %4, label %13
13: ; preds = %4, %1
%14 = phi float [ 1.000000e+01, %1 ], [ %9, %4 ]
ret float %14
}