#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 */
long long Platform_Halt(int);
long long SYSTEM_ENTIER(double);
long long SYSTEM_MOD(long long, long long);
void Reals_ConvertL(double x, int n, unsigned char *d, long long d__len) {
  long long i, j, k;
  if (x < (double)0) {
    x = -x;
  }
  k = 0;
  i = SYSTEM_ENTIER(x);
  while (k < (long long)n) {
    d[(((unsigned long long)(k) < (unsigned long long)(d__len))
           ? k
           : (Platform_Halt(-2), 0))] =
        (unsigned char)(((i) >= 0
                             ? (i) % (10)
                             : SYSTEM_MOD((long long)(i), (long long)(10))) +
                        48);
    i = ((i) >= 0 ? (i) / (10) : -(((10) - 1 - (i)) / (10)));
    k += 1;
  }
}


x86 assembly (clang, -O0):
<Reals_ConvertL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1177 <Reals_ConvertL+0x47>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movq   $0x0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <SYSTEM_ENTIER@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
jge    127b <Reals_ConvertL+0x14b>
cmpq   $0x0,-0x28(%rbp)
jl     11c3 <Reals_ConvertL+0x93>
mov    -0x28(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rdx,%rax
mov    %rax,-0x40(%rbp)
jmp    11d5 <Reals_ConvertL+0xa5>
mov    -0x28(%rbp),%rdi
mov    $0xa,%esi
call   1040 <SYSTEM_MOD@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x30,%rax
mov    %al,-0x49(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1203 <Reals_ConvertL+0xd3>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    1213 <Reals_ConvertL+0xe3>
mov    $0xfffffffe,%edi
call   1050 <Platform_Halt@plt>
xor    %eax,%eax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x49(%rbp),%dl
mov    -0x58(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
cmpq   $0x0,-0x28(%rbp)
jl     1243 <Reals_ConvertL+0x113>
mov    -0x28(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x60(%rbp)
jmp    1262 <Reals_ConvertL+0x132>
mov    $0x9,%eax
sub    -0x28(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    118d <Reals_ConvertL+0x5d>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Reals_ConvertL>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
movapd 0xeb5(%rip),%xmm2
xorpd  %xmm0,%xmm2
xorpd  %xmm3,%xmm3
movapd %xmm0,%xmm1
cmpltsd %xmm3,%xmm1
andpd  %xmm1,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
movapd %xmm1,%xmm0
call   1030 <SYSTEM_ENTIER@plt>
test   %ebx,%ebx
jle    1240 <Reals_ConvertL+0x110>
mov    %rax,%r12
movslq %ebx,%r13
xor    %ebp,%ebp
jmp    11bc <Reals_ConvertL+0x8c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x9,%eax
sub    %r12,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
mov    %rdx,%r12
shr    $0x3,%r12
neg    %r12
add    $0x1,%rbp
cmp    %rbp,%r13
je     1240 <Reals_ConvertL+0x110>
test   %r12,%r12
js     11f0 <Reals_ConvertL+0xc0>
mov    %r12,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
shr    $0x2,%rdx
and    $0xfffffffffffffffe,%rdx
lea    (%rdx,%rdx,4),%rax
mov    %r12,%rbx
sub    %rax,%rbx
jmp    1200 <Reals_ConvertL+0xd0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%esi
mov    %r12,%rdi
call   1040 <SYSTEM_MOD@plt>
mov    %rax,%rbx
add    $0x30,%bl
mov    %rbp,%rax
cmp    %r14,%rbp
jb     1217 <Reals_ConvertL+0xe7>
mov    $0xfffffffe,%edi
call   1050 <Platform_Halt@plt>
xor    %eax,%eax
mov    %bl,(%r15,%rax,1)
test   %r12,%r12
js     1190 <Reals_ConvertL+0x60>
mov    %r12,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
mov    %rdx,%r12
shr    $0x3,%r12
jmp    11af <Reals_ConvertL+0x7f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @Reals_ConvertL(double %0, i32 %1, i8* nocapture writeonly %2, i64 %3) {
%5 = fcmp olt double %0, 0.000000e+00
%6 = fneg double %0
%7 = select i1 %5, double %6, double %0
%8 = tail call i64 @SYSTEM_ENTIER(double %7)
%9 = sext i32 %1 to i64
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %39
11: ; preds = %4, %35
%12 = phi i64 [ %37, %35 ], [ 0, %4 ]
%13 = phi i64 [ %36, %35 ], [ %8, %4 ]
%14 = icmp sgt i64 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = urem i64 %13, 10
br label %19
17: ; preds = %11
%18 = tail call i64 @SYSTEM_MOD(i64 %13, i64 10)
br label %19
19: ; preds = %17, %15
%20 = phi i64 [ %16, %15 ], [ %18, %17 ]
%21 = trunc i64 %20 to i8
%22 = add i8 %21, 48
%23 = icmp ult i64 %12, %3
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = tail call i64 @Platform_Halt(i32 -2)
br label %26
26: ; preds = %19, %24
%27 = phi i64 [ 0, %24 ], [ %12, %19 ]
%28 = getelementptr inbounds i8, i8* %2, i64 %27
store i8 %22, i8* %28
br i1 %14, label %29, label %31
29: ; preds = %26
%30 = udiv i64 %13, 10
br label %35
31: ; preds = %26
%32 = sub nsw i64 9, %13
%33 = udiv i64 %32, 10
%34 = sub nsw i64 0, %33
br label %35
35: ; preds = %31, %29
%36 = phi i64 [ %30, %29 ], [ %34, %31 ]
%37 = add nuw nsw i64 %12, 1
%38 = icmp eq i64 %37, %9
br i1 %38, label %39, label %11
39: ; preds = %35, %4
ret void
}