#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*/ sprintf(char *, char *, double);
int /*<<< orphan*/ strcat(char *, char *);
void *strchr(char *, char);
int strlen(char *);
char *rul__mol_format_double(double d) {
  static char buffer[50];
  long i;
  sprintf(buffer, "%.15g", d);
  if (strchr(buffer, '.') == ((void *)0)) {
    strcat(buffer, ".0");
  } else {
    if (strchr(buffer, 'e') == ((void *)0)) {
      i = strlen(buffer) - 1;
      while (buffer[i - 1] != '.' && buffer[i] == '0') {
        buffer[i] = '\0';
        i--;
      }
    }
  }
  return (buffer);
}


x86 assembly (clang, -O0):
<rul__mol_format_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    0x2ef7(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2ee4(%rip),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1198 <rul__mol_format_double+0x58>
lea    0x2ec9(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1050 <strcat@plt>
jmp    123b <rul__mol_format_double+0xfb>
lea    0x2eb1(%rip),%rdi
mov    $0x65,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1236 <rul__mol_format_double+0xf6>
lea    0x2e96(%rip),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
lea    0x2e79(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x11(%rbp)
je     1201 <rul__mol_format_double+0xc1>
mov    -0x10(%rbp),%rcx
lea    0x2e5c(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1211 <rul__mol_format_double+0xd1>
jmp    1231 <rul__mol_format_double+0xf1>
mov    -0x10(%rbp),%rcx
lea    0x2e34(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    11c8 <rul__mol_format_double+0x88>
jmp    1236 <rul__mol_format_double+0xf6>
jmp    123b <rul__mol_format_double+0xfb>
lea    0x2e0e(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rul__mol_format_double>:
push   %rbx
lea    0x2f08(%rip),%rbx
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b4 <rul__mol_format_double+0x74>
lea    0x2ee0(%rip),%rbx
mov    %rbx,%rdi
mov    $0x65,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11c7 <rul__mol_format_double+0x87>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2e,-0x2(%rax,%rbx,1)
je     11c7 <rul__mol_format_double+0x87>
add    $0xffffffffffffffff,%rax
add    %rax,%rbx
nopw   0x0(%rax,%rax,1)
cmpb   $0x30,(%rbx)
jne    11c7 <rul__mol_format_double+0x87>
movb   $0x0,(%rbx)
cmpb   $0x2e,-0x2(%rbx)
lea    -0x1(%rbx),%rbx
jne    11a0 <rul__mol_format_double+0x60>
jmp    11c7 <rul__mol_format_double+0x87>
lea    0x2e95(%rip),%rdi
lea    0xe44(%rip),%rsi
call   1050 <strcat@plt>
lea    0x2e82(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@rul__mol_format_double.buffer = internal global [50 x i8] zeroinitializer
@.str = [6 x i8] c"%.15g\00"
@.str.1 = [3 x i8] c".0\00"
define i8* @rul__mol_format_double(double %0) {
%2 = alloca double
%3 = alloca i64
store double %0, double* %2
%4 = load double, double* %2
%5 = call i32 @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %4)
%6 = call i8* @strchr(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0), i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @strcat(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %39
10: ; preds = %1
%11 = call i8* @strchr(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0), i8 signext 101)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %38
13: ; preds = %10
%14 = call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0))
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
store i64 %16, i64* %3
br label %17
17: ; preds = %32, %13
%18 = load i64, i64* %3
%19 = sub nsw i64 %18, 1
%20 = getelementptr inbounds [50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 46
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i64, i64* %3
%26 = getelementptr inbounds [50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 48
br label %30
30: ; preds = %24, %17
%31 = phi i1 [ false, %17 ], [ %29, %24 ]
br i1 %31, label %32, label %37
32: ; preds = %30
%33 = load i64, i64* %3
%34 = getelementptr inbounds [50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 %33
store i8 0, i8* %34
%35 = load i64, i64* %3
%36 = add nsw i64 %35, -1
store i64 %36, i64* %3
br label %17
37: ; preds = %30
br label %38
38: ; preds = %37, %10
br label %39
39: ; preds = %38, %8
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@rul__mol_format_double.buffer = internal global [50 x i8] zeroinitializer
@.str = [6 x i8] c"%.15g\00"
@.str.1 = [3 x i8] c".0\00"
define i8* @rul__mol_format_double(double %0) {
%2 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %0)
%3 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0), i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @strcat(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %29
7: ; preds = %1
%8 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0), i8 signext 101)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0))
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = add nsw i64 %13, -1
%15 = getelementptr inbounds [50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 46
br i1 %17, label %29, label %18
18: ; preds = %10, %24
%19 = phi i64 [ %25, %24 ], [ %14, %10 ]
%20 = phi i64 [ %19, %24 ], [ %13, %10 ]
%21 = getelementptr inbounds [50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 48
br i1 %23, label %24, label %29
24: ; preds = %18
store i8 0, i8* %21
%25 = add nsw i64 %19, -1
%26 = getelementptr inbounds [50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 46
br i1 %28, label %29, label %18
29: ; preds = %18, %24, %10, %7, %5
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @rul__mol_format_double.buffer, i64 0, i64 0)
}