#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*/ _shift_left_nstr(char *, int);
int /*<<< orphan*/ _shift_right_nstr(char *, int);
char *e_cvt(double, char *, int, int *, int *);
double utils_roundd(double, int);
void utils_dtostr(char *buff, int digits, double value) {
  int decpt, sign;
  digits++;
  value = utils_roundd(value, digits - 2);
  char *out = e_cvt(value, buff, digits, &decpt, &sign);
  if (decpt <= 0) {
    _shift_right_nstr(out, -1 * decpt + 2);
    out[1] = '.';
  } else {
    out = &buff[decpt + 1];
    _shift_right_nstr(out, 1);
    buff[decpt + 1] = '.';
  }
  if (sign) {
    buff[0] = '-';
    buff[digits + 3] = 0;
  } else {
    _shift_left_nstr(buff, 1);
    buff[digits] = 0;
  }
}


x86 assembly (clang, -O0):
<utils_dtostr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%edi
sub    $0x2,%edi
call   1030 <utils_roundd@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1050 <e_cvt@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11b9 <utils_dtostr+0x79>
mov    -0x28(%rbp),%rdi
imul   $0xffffffff,-0x1c(%rbp),%esi
add    $0x2,%esi
call   1040 <_shift_right_nstr@plt>
mov    -0x28(%rbp),%rax
movb   $0x2e,0x1(%rax)
jmp    11ec <utils_dtostr+0xac>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1040 <_shift_right_nstr@plt>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
cmpl   $0x0,-0x20(%rbp)
je     1213 <utils_dtostr+0xd3>
mov    -0x8(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    122d <utils_dtostr+0xed>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1060 <_shift_left_nstr@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utils_dtostr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x1(%rbp),%r14d
lea    -0x1(%rbp),%edi
call   1030 <utils_roundd@plt>
mov    %rsp,%rdx
lea    0x4(%rsp),%rcx
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <e_cvt@plt>
mov    %rax,%rbx
mov    (%rsp),%eax
test   %eax,%eax
jle    1195 <utils_dtostr+0x55>
lea    (%rax,%r15,1),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <_shift_right_nstr@plt>
movslq (%rsp),%rax
lea    (%rax,%r15,1),%rbx
add    $0x1,%rbx
jmp    11a8 <utils_dtostr+0x68>
mov    $0x2,%esi
sub    %eax,%esi
mov    %rbx,%rdi
call   1040 <_shift_right_nstr@plt>
add    $0x1,%rbx
movb   $0x2e,(%rbx)
cmpl   $0x0,0x4(%rsp)
je     11be <utils_dtostr+0x7e>
movb   $0x2d,(%r15)
add    $0x4,%ebp
mov    %ebp,%r14d
jmp    11cb <utils_dtostr+0x8b>
mov    %r15,%rdi
mov    $0x1,%esi
call   1060 <_shift_left_nstr@plt>
movslq %r14d,%rax
movb   $0x0,(%r15,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @utils_dtostr(i8* %0, i32 %1, double %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store double %2, double* %6
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
store i32 %11, i32* %5
%12 = load double, double* %6
%13 = load i32, i32* %5
%14 = sub nsw i32 %13, 2
%15 = call double @utils_roundd(double %12, i32 %14)
store double %15, double* %6
%16 = load double, double* %6
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = call i8* @e_cvt(double %16, i8* %17, i32 %18, i32* %7, i32* %8)
store i8* %19, i8** %9
%20 = load i32, i32* %7
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %3
%23 = load i8*, i8** %9
%24 = load i32, i32* %7
%25 = mul nsw i32 -1, %24
%26 = add nsw i32 %25, 2
%27 = call i32 @_shift_right_nstr(i8* %23, i32 %26)
%28 = load i8*, i8** %9
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 46, i8* %29
br label %43
30: ; preds = %3
%31 = load i8*, i8** %4
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = call i32 @_shift_right_nstr(i8* %36, i32 1)
%38 = load i8*, i8** %4
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8 46, i8* %42
br label %43
43: ; preds = %30, %22
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 0
store i8 45, i8* %48
%49 = load i8*, i8** %4
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
store i8 0, i8* %53
br label %61
54: ; preds = %43
%55 = load i8*, i8** %4
%56 = call i32 @_shift_left_nstr(i8* %55, i32 1)
%57 = load i8*, i8** %4
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 0, i8* %60
br label %61
61: ; preds = %54, %46
ret void
}

LLVM IR (-O2):
define void @utils_dtostr(i8* %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = add nsw i32 %1, 1
%9 = add nsw i32 %1, -1
%10 = tail call double @utils_roundd(double %2, i32 %9)
%11 = call i8* @e_cvt(double %10, i8* %0, i32 %8, i32* %4, i32* %5)
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = sub i32 2, %12
%16 = call i32 @_shift_right_nstr(i8* %11, i32 %15)
%17 = getelementptr inbounds i8, i8* %11, i64 1
br label %27
18: ; preds = %3
%19 = add nuw nsw i32 %12, 1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = call i32 @_shift_right_nstr(i8* %21, i32 1)
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
br label %27
27: ; preds = %18, %14
%28 = phi i8* [ %26, %18 ], [ %17, %14 ]
store i8 46, i8* %28
%29 = load i32, i32* %5
%30 = icmp eq i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %27
store i8 45, i8* %0
%32 = add nsw i32 %1, 4
br label %35
33: ; preds = %27
%34 = call i32 @_shift_left_nstr(i8* %0, i32 1)
br label %35
35: ; preds = %33, %31
%36 = phi i32 [ %8, %33 ], [ %32, %31 ]
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %0, i64 %37
store i8 0, i8* %38
ret void
}