#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 DBL_DIG;
int /*<<< orphan*/ fabs(double);
int /*<<< orphan*/ is_integer(double);
int /*<<< orphan*/ modf(int /*<<< orphan*/, double *);
int /*<<< orphan*/ sprintf(char *, char *, double);
int strlen(char *);
int get_length(double val, char *map) {
  double integer;
  int length;
  char s[2 * DBL_DIG];
  modf(fabs(val), &integer);
  if (map != NULL && !is_integer(val)) {
    *map |= 040;
  }
  sprintf(s, "%.f", integer);
  length = strlen(s);
  if (val < 0)
    length++;
  return length;
}


x86 assembly (clang, -O0):
<get_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <fabs@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1050 <modf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11ce <get_length+0x7e>
movsd  -0x8(%rbp),%xmm0
call   1030 <is_integer@plt>
cmp    $0x0,%eax
jne    11ce <get_length+0x7e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
or     $0x20,%ecx
mov    %cl,(%rax)
mov    -0x38(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe22(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1206 <get_length+0xb6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_length>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    %rsp,%r15
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movsd  %xmm0,-0x20(%rbp)
call   1060 <fabs@plt>
lea    -0x28(%rbp),%rsi
mov    %eax,%edi
call   1050 <modf@plt>
test   %r14,%r14
je     11ab <get_length+0x5b>
movsd  -0x20(%rbp),%xmm0
call   1030 <is_integer@plt>
test   %eax,%eax
jne    11ab <get_length+0x5b>
orb    $0x20,(%r14)
movsd  -0x28(%rbp),%xmm0
lea    0xe49(%rip),%rsi
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
ucomisd -0x20(%rbp),%xmm0
seta   %cl
add    %ecx,%eax
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_DIG = global i32 0
@.str = [4 x i8] c"%.f\00"
define i32 @get_length(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store double %0, double* %3
store i8* %1, i8** %4
%9 = load i32, i32* @DBL_DIG
%10 = mul nsw i32 2, %9
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load double, double* %3
%15 = call i32 @fabs(double %14)
%16 = call i32 @modf(i32 %15, double* %5)
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %29
19: ; preds = %2
%20 = load double, double* %3
%21 = call i32 @is_integer(double %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = or i32 %26, 32
%28 = trunc i32 %27 to i8
store i8 %28, i8* %24
br label %29
29: ; preds = %23, %19, %2
%30 = load double, double* %5
%31 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %30)
%32 = call i32 @strlen(i8* %13)
store i32 %32, i32* %6
%33 = load double, double* %3
%34 = fcmp olt double %33, 0.000000e+00
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %38
38: ; preds = %35, %29
%39 = load i32, i32* %6
%40 = load i8*, i8** %7
ret i32 %39
}

LLVM IR (-O2):
@DBL_DIG = global i32 0
@.str = [4 x i8] c"%.f\00"
define i32 @get_length(double %0, i8* %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = load i32, i32* @DBL_DIG
%6 = shl nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = tail call i32 @fabs(double %0)
%11 = call i32 @modf(i32 %10, double* %3)
%12 = icmp eq i8* %1, null
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = tail call i32 @is_integer(double %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i8, i8* %1
%18 = or i8 %17, 32
store i8 %18, i8* %1
br label %19
19: ; preds = %16, %13, %2
%20 = load double, double* %3
%21 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %20)
%22 = call i32 @strlen(i8* %9)
%23 = fcmp olt double %0, 0.000000e+00
%24 = zext i1 %23 to i32
%25 = add nsw i32 %22, %24
ret i32 %25
}