#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 */
char *__format_double_frac(long double, int, int);
int /*<<< orphan*/ free(char *);
int log10l(long double);
scalar_t__ powl(int, int);
char *strvcat(char *, char *, int /*<<< orphan*/ *);
char *__format_double_int(long double value, int flags) {
  char *temp, *string;
  int expt;
  expt = log10l(value) + 1;
  value /= (int)powl(10, expt);
  temp = __format_double_frac(value, flags | 0x04 | 0x100, expt);
  if (value < 0) {
    string = strvcat("-", temp, NULL);
    free(temp);
  } else if (flags & 0x01) {
    string = strvcat("+", temp, NULL);
    free(temp);
  } else {
    string = temp;
  }
  return string;
}


x86 assembly (clang, -O0):
<__format_double_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
mov    %edi,-0x14(%rbp)
fldt   -0x10(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1060 <log10l@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
mov    $0xa,%edi
call   1040 <powl@plt>
mov    %eax,-0x30(%rbp)
fildl  -0x30(%rbp)
fldt   -0x10(%rbp)
fdivp  %st,%st(1)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
mov    -0x14(%rbp),%edi
or     $0x104,%edi
mov    -0x2c(%rbp),%esi
mov    %rsp,%rax
fstpt  (%rax)
call   1050 <__format_double_frac@plt>
mov    %rax,-0x20(%rbp)
fldt   -0x10(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    11e6 <__format_double_int+0x96>
jmp    11c0 <__format_double_int+0x70>
mov    -0x20(%rbp),%rsi
lea    0xe35(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <strvcat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1228 <__format_double_int+0xd8>
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     121b <__format_double_int+0xcb>
mov    -0x20(%rbp),%rsi
lea    0xe02(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <strvcat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1223 <__format_double_int+0xd3>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1228 <__format_double_int+0xd8>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__format_double_int>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
fldt   0x40(%rsp)
fld    %st(0)
fstpt  0x1c(%rsp)
fstpt  (%rsp)
call   1060 <log10l@plt>
lea    0x1(%rax),%ebx
mov    $0xa,%edi
mov    %ebx,%esi
call   1040 <powl@plt>
mov    %eax,0x18(%rsp)
fldt   0x1c(%rsp)
fidivl 0x18(%rsp)
fld    %st(0)
fstpt  0x1c(%rsp)
mov    %ebp,%edi
or     $0x104,%edi
fstpt  (%rsp)
mov    %ebx,%esi
call   1050 <__format_double_frac@plt>
mov    %rax,%rbx
fldz
fldt   0x1c(%rsp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    11b7 <__format_double_int+0x67>
lea    0xe4b(%rip),%rdi
jmp    11c9 <__format_double_int+0x79>
test   $0x1,%bpl
jne    11c2 <__format_double_int+0x72>
mov    %rbx,%rax
jmp    11e1 <__format_double_int+0x91>
lea    0xe39(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <strvcat@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"+\00"
define i8* @__format_double_int(x86_fp80 %0, i32 %1) {
%3 = alloca x86_fp80
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store x86_fp80 %0, x86_fp80* %3
store i32 %1, i32* %4
%8 = load x86_fp80, x86_fp80* %3
%9 = call i32 @log10l(x86_fp80 %8)
%10 = add nsw i32 %9, 1
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = call i64 @powl(i32 10, i32 %11)
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to x86_fp80
%15 = load x86_fp80, x86_fp80* %3
%16 = fdiv x86_fp80 %15, %14
store x86_fp80 %16, x86_fp80* %3
%17 = load x86_fp80, x86_fp80* %3
%18 = load i32, i32* %4
%19 = or i32 %18, 4
%20 = or i32 %19, 256
%21 = load i32, i32* %7
%22 = call i8* @__format_double_frac(x86_fp80 %17, i32 %20, i32 %21)
store i8* %22, i8** %5
%23 = load x86_fp80, x86_fp80* %3
%24 = fcmp olt x86_fp80 %23, 0xK00000000000000000000
br i1 %24, label %25, label %30
25: ; preds = %2
%26 = load i8*, i8** %5
%27 = call i8* @strvcat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %26, i32* null)
store i8* %27, i8** %6
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
br label %42
30: ; preds = %2
%31 = load i32, i32* %4
%32 = and i32 %31, 1
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i8*, i8** %5
%36 = call i8* @strvcat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %35, i32* null)
store i8* %36, i8** %6
%37 = load i8*, i8** %5
%38 = call i32 @free(i8* %37)
br label %41
39: ; preds = %30
%40 = load i8*, i8** %5
store i8* %40, i8** %6
br label %41
41: ; preds = %39, %34
br label %42
42: ; preds = %41, %25
%43 = load i8*, i8** %6
ret i8* %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [2 x i8] c"+\00"
define i8* @__format_double_int(x86_fp80 %0, i32 %1) {
%3 = tail call i32 @log10l(x86_fp80 %0)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @powl(i32 10, i32 %4)
%6 = trunc i64 %5 to i32
%7 = sitofp i32 %6 to x86_fp80
%8 = fdiv x86_fp80 %0, %7
%9 = or i32 %1, 260
%10 = tail call i8* @__format_double_frac(x86_fp80 %8, i32 %9, i32 %4)
%11 = fcmp olt x86_fp80 %8, 0xK00000000000000000000
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = and i32 %1, 1
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12, %2
%16 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %12 ]
%17 = tail call i8* @strvcat(i8* %16, i8* %10, i32* null)
%18 = tail call i32 @free(i8* %10)
br label %19
19: ; preds = %15, %12
%20 = phi i8* [ %10, %12 ], [ %17, %15 ]
ret i8* %20
}