#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 */
scalar_t__ ft_ftohex2(char *, long double);
scalar_t__ ft_init_hex(char *);
int /*<<< orphan*/ ft_itoa(int);
long double ft_power(int, int);
char *ft_strdup(char *);
char *ft_strfjoin(char *, int /*<<< orphan*/, int, int);
char *ft_strnew(int);
char *ft_ftohex(long double f) {
  char *s;
  int i;
  long double res;
  int x;
  int sign;
  if ((x = -1) && f == 0.0)
    return (ft_strdup("0x0p+0"));
  i = 0;
  s = ft_strnew(20);
  if ((sign = (f < 0 ? -1 : 1)) == -1)
    s[i++] = '-';
  i += ft_init_hex(s + i);
  res = f;
  while ((int)res != sign) {
    if ((sign == 1 ? (res > 1) : (res < -1)))
      res = f / ft_power(2, ++x);
    else
      res = f / ft_power(2, --x);
  }
  i += ft_ftohex2(s + i, res * sign);
  if ((s[i++] = 'p') && x > 0)
    s[i++] = '+';
  return (s = ft_strfjoin(s, ft_itoa(x), 1, 1));
}


x86 assembly (clang, -O0):
<ft_ftohex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
movl   $0xffffffff,-0x44(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    1197 <ft_ftohex+0x27>
jmp    11c8 <ft_ftohex+0x58>
fldt   -0x20(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11c8 <ft_ftohex+0x58>
jp     11c8 <ft_ftohex+0x58>
jmp    11b3 <ft_ftohex+0x43>
lea    0xe46(%rip),%rdi
call   1070 <ft_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1380 <ft_ftohex+0x210>
xor    %eax,%eax
movl   $0x0,-0x2c(%rbp)
mov    $0x14,%edi
call   1060 <ft_strnew@plt>
mov    %rax,-0x28(%rbp)
fldt   -0x20(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
setbe  %al
movzbl %al,%ecx
mov    %ecx,%eax
lea    -0x1(%rax,%rax,1),%eax
mov    %eax,-0x48(%rbp)
cmp    $0xffffffff,%eax
jne    1216 <ft_ftohex+0xa6>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
call   1030 <ft_init_hex@plt>
mov    %rax,%rcx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
fldt   -0x20(%rbp)
fstpt  -0x40(%rbp)
fldt   -0x40(%rbp)
fnstcw -0x52(%rbp)
movzwl -0x52(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x54(%rbp)
fldcw  -0x54(%rbp)
fistpl -0x4c(%rbp)
fldcw  -0x52(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x48(%rbp),%eax
je     12e1 <ft_ftohex+0x171>
cmpl   $0x1,-0x48(%rbp)
jne    127f <ft_ftohex+0x10f>
fldt   -0x40(%rbp)
fld1
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
ja     1295 <ft_ftohex+0x125>
jmp    12bb <ft_ftohex+0x14b>
fldt   -0x40(%rbp)
fld1
fchs
fucomip %st(1),%st
fstp   %st(0)
jbe    12bb <ft_ftohex+0x14b>
jmp    1295 <ft_ftohex+0x125>
fldt   -0x20(%rbp)
fstpt  -0x60(%rbp)
mov    -0x44(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x44(%rbp)
mov    $0x2,%edi
call   1090 <ft_power@plt>
fldt   -0x60(%rbp)
fdivp  %st,%st(1)
fstpt  -0x40(%rbp)
jmp    12dc <ft_ftohex+0x16c>
fldt   -0x20(%rbp)
fstpt  -0x6c(%rbp)
mov    -0x44(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0x44(%rbp)
mov    $0x2,%edi
call   1090 <ft_power@plt>
fldt   -0x6c(%rbp)
fdivp  %st,%st(1)
fstpt  -0x40(%rbp)
jmp    1237 <ft_ftohex+0xc7>
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
fldt   -0x40(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x50(%rbp)
fildl  -0x50(%rbp)
fmulp  %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
call   1080 <ft_ftohex2@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x70,(%rax,%rcx,1)
mov    $0x1,%al
test   $0x1,%al
jne    1336 <ft_ftohex+0x1c6>
jmp    1356 <ft_ftohex+0x1e6>
cmpl   $0x0,-0x44(%rbp)
jle    1356 <ft_ftohex+0x1e6>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x2b,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x44(%rbp),%edi
call   1040 <ft_itoa@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1050 <ft_strfjoin@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_ftohex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
fldt   0x60(%rsp)
fldz
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jne    11a2 <ft_ftohex+0x32>
jp     11a2 <ft_ftohex+0x32>
fstp   %st(0)
lea    0xe6d(%rip),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <ft_strdup@plt>
mov    $0x14,%edi
fstpt  0x2c(%rsp)
call   1060 <ft_strnew@plt>
mov    %rax,%r14
fldz
xor    %eax,%eax
fldt   0x2c(%rsp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
setbe  %al
lea    -0x1(%rax,%rax,1),%ebx
jbe    11d5 <ft_ftohex+0x65>
movb   $0x2d,(%r14)
mov    $0x1,%ebp
jmp    11d7 <ft_ftohex+0x67>
xor    %ebp,%ebp
lea    (%r14,%rbp,1),%rdi
call   1030 <ft_init_hex@plt>
fnstcw 0x1a(%rsp)
movzwl 0x1a(%rsp),%ecx
or     $0xc00,%ecx
mov    %cx,0x1e(%rsp)
fldcw  0x1e(%rsp)
mov    %rax,%r15
fldt   0x2c(%rsp)
fistl  0x28(%rsp)
fldcw  0x1a(%rsp)
add    %rbp,%r15
mov    $0xffffffff,%ebp
cmp    0x28(%rsp),%ebx
jne    1280 <ft_ftohex+0x110>
fldz
fstp   %st(0)
movslq %r15d,%rax
mov    %r14,%rdi
add    %rax,%rdi
mov    %ebx,0x20(%rsp)
fimull 0x20(%rsp)
fstpt  (%rsp)
call   1080 <ft_ftohex2@plt>
add    %r15,%rax
movslq %eax,%rcx
movb   $0x70,(%r14,%rcx,1)
test   %ebp,%ebp
jle    125b <ft_ftohex+0xeb>
shl    $0x20,%rax
movabs $0x100000000,%rcx
add    %rax,%rcx
sar    $0x20,%rcx
movb   $0x2b,(%r14,%rcx,1)
mov    %ebp,%edi
call   1040 <ft_itoa@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <ft_strfjoin@plt>
mov    $0xffffffff,%ebp
fld    %st(0)
fxch   %st(1)
jmp    12d1 <ft_ftohex+0x161>
nopl   0x0(%rax,%rax,1)
add    %eax,%ebp
mov    $0x2,%edi
mov    %ebp,%esi
call   1090 <ft_power@plt>
fldt   0x2c(%rsp)
fdiv   %st,%st(1)
fnstcw 0x18(%rsp)
movzwl 0x18(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x1c(%rsp)
fldcw  0x1c(%rsp)
fxch   %st(1)
fistl  0x24(%rsp)
fldcw  0x18(%rsp)
cmp    0x24(%rsp),%ebx
fxch   %st(1)
je     1217 <ft_ftohex+0xa7>
fldz
fucomip %st(1),%st
fstp   %st(0)
mov    $0x1,%eax
jbe    12f0 <ft_ftohex+0x180>
fld1
fchs
jmp    12f4 <ft_ftohex+0x184>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
fld1
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
ja     1290 <ft_ftohex+0x120>
mov    $0xffffffff,%eax
jmp    1290 <ft_ftohex+0x120>

LLVM IR (-O0):
@.str = [7 x i8] c"0x0p+0\00"
define i8* @ft_ftohex(x86_fp80 %0) {
%2 = alloca i8*
%3 = alloca x86_fp80
%4 = alloca i8*
%5 = alloca i32
%6 = alloca x86_fp80
%7 = alloca i32
%8 = alloca i32
store x86_fp80 %0, x86_fp80* %3
store i32 -1, i32* %7
br i1 true, label %9, label %14
9: ; preds = %1
%10 = load x86_fp80, x86_fp80* %3
%11 = fcmp oeq x86_fp80 %10, 0xK00000000000000000000
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i8* @ft_strdup(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %2
br label %98
14: ; preds = %9, %1
store i32 0, i32* %5
%15 = call i8* @ft_strnew(i32 20)
store i8* %15, i8** %4
%16 = load x86_fp80, x86_fp80* %3
%17 = fcmp olt x86_fp80 %16, 0xK00000000000000000000
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 -1, i32 1
store i32 %19, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 45, i8* %26
br label %27
27: ; preds = %21, %14
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = call i64 @ft_init_hex(i8* %31)
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = add nsw i64 %34, %32
%36 = trunc i64 %35 to i32
store i32 %36, i32* %5
%37 = load x86_fp80, x86_fp80* %3
store x86_fp80 %37, x86_fp80* %6
br label %38
38: ; preds = %64, %27
%39 = load x86_fp80, x86_fp80* %6
%40 = fptosi x86_fp80 %39 to i32
%41 = load i32, i32* %8
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %65
43: ; preds = %38
%44 = load i32, i32* %8
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load x86_fp80, x86_fp80* %6
%48 = fcmp ogt x86_fp80 %47, 0xK3FFF8000000000000000
br i1 %48, label %52, label %58
49: ; preds = %43
%50 = load x86_fp80, x86_fp80* %6
%51 = fcmp olt x86_fp80 %50, 0xKBFFF8000000000000000
br i1 %51, label %52, label %58
52: ; preds = %49, %46
%53 = load x86_fp80, x86_fp80* %3
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
%56 = call x86_fp80 @ft_power(i32 2, i32 %55)
%57 = fdiv x86_fp80 %53, %56
store x86_fp80 %57, x86_fp80* %6
br label %64
58: ; preds = %49, %46
%59 = load x86_fp80, x86_fp80* %3
%60 = load i32, i32* %7
%61 = add nsw i32 %60, -1
store i32 %61, i32* %7
%62 = call x86_fp80 @ft_power(i32 2, i32 %61)
%63 = fdiv x86_fp80 %59, %62
store x86_fp80 %63, x86_fp80* %6
br label %64
64: ; preds = %58, %52
br label %38
65: ; preds = %38
%66 = load i8*, i8** %4
%67 = load i32, i32* %5
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = load x86_fp80, x86_fp80* %6
%71 = load i32, i32* %8
%72 = sitofp i32 %71 to x86_fp80
%73 = fmul x86_fp80 %70, %72
%74 = call i64 @ft_ftohex2(i8* %69, x86_fp80 %73)
%75 = load i32, i32* %5
%76 = sext i32 %75 to i64
%77 = add nsw i64 %76, %74
%78 = trunc i64 %77 to i32
store i32 %78, i32* %5
%79 = load i8*, i8** %4
%80 = load i32, i32* %5
%81 = add nsw i32 %80, 1
store i32 %81, i32* %5
%82 = sext i32 %80 to i64
%83 = getelementptr inbounds i8, i8* %79, i64 %82
store i8 112, i8* %83
br i1 true, label %84, label %93
84: ; preds = %65
%85 = load i32, i32* %7
%86 = icmp sgt i32 %85, 0
br i1 %86, label %87, label %93
87: ; preds = %84
%88 = load i8*, i8** %4
%89 = load i32, i32* %5
%90 = add nsw i32 %89, 1
store i32 %90, i32* %5
%91 = sext i32 %89 to i64
%92 = getelementptr inbounds i8, i8* %88, i64 %91
store i8 43, i8* %92
br label %93
93: ; preds = %87, %84, %65
%94 = load i8*, i8** %4
%95 = load i32, i32* %7
%96 = call i32 @ft_itoa(i32 %95)
%97 = call i8* @ft_strfjoin(i8* %94, i32 %96, i32 1, i32 1)
store i8* %97, i8** %4
store i8* %97, i8** %2
br label %98
98: ; preds = %93, %12
%99 = load i8*, i8** %2
ret i8* %99
}

LLVM IR (-O2):
@.str = [7 x i8] c"0x0p+0\00"
define i8* @ft_ftohex(x86_fp80 %0) {
%2 = fcmp oeq x86_fp80 %0, 0xK00000000000000000000
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i8* @ft_strdup(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %53
5: ; preds = %1
%6 = tail call i8* @ft_strnew(i32 20)
%7 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
%8 = select i1 %7, i32 -1, i32 1
br i1 %7, label %9, label %10
9: ; preds = %5
store i8 45, i8* %6
br label %10
10: ; preds = %9, %5
%11 = phi i64 [ 1, %9 ], [ 0, %5 ]
%12 = getelementptr inbounds i8, i8* %6, i64 %11
%13 = tail call i64 @ft_init_hex(i8* %12)
%14 = add nsw i64 %13, %11
%15 = fptosi x86_fp80 %0 to i32
%16 = icmp eq i32 %8, %15
br i1 %16, label %32, label %17
17: ; preds = %10, %25
%18 = phi i32 [ %27, %25 ], [ -1, %10 ]
%19 = phi x86_fp80 [ %29, %25 ], [ %0, %10 ]
br i1 %7, label %22, label %20
20: ; preds = %17
%21 = fcmp ogt x86_fp80 %19, 0xK3FFF8000000000000000
br i1 %21, label %25, label %24
22: ; preds = %17
%23 = fcmp olt x86_fp80 %19, 0xKBFFF8000000000000000
br i1 %23, label %25, label %24
24: ; preds = %22, %20
br label %25
25: ; preds = %20, %22, %24
%26 = phi i32 [ -1, %24 ], [ 1, %22 ], [ 1, %20 ]
%27 = add nsw i32 %18, %26
%28 = tail call x86_fp80 @ft_power(i32 2, i32 %27)
%29 = fdiv x86_fp80 %0, %28
%30 = fptosi x86_fp80 %29 to i32
%31 = icmp eq i32 %8, %30
br i1 %31, label %32, label %17
32: ; preds = %25, %10
%33 = phi x86_fp80 [ %0, %10 ], [ %29, %25 ]
%34 = phi i32 [ -1, %10 ], [ %27, %25 ]
%35 = shl i64 %14, 32
%36 = ashr exact i64 %35, 32
%37 = getelementptr inbounds i8, i8* %6, i64 %36
%38 = sitofp i32 %8 to x86_fp80
%39 = fmul x86_fp80 %33, %38
%40 = tail call i64 @ft_ftohex2(i8* %37, x86_fp80 %39)
%41 = add i64 %40, %14
%42 = shl i64 %41, 32
%43 = ashr exact i64 %42, 32
%44 = getelementptr inbounds i8, i8* %6, i64 %43
store i8 112, i8* %44
%45 = icmp sgt i32 %34, 0
br i1 %45, label %46, label %50
46: ; preds = %32
%47 = add i64 %42, 4294967296
%48 = ashr exact i64 %47, 32
%49 = getelementptr inbounds i8, i8* %6, i64 %48
store i8 43, i8* %49
br label %50
50: ; preds = %46, %32
%51 = tail call i32 @ft_itoa(i32 %34)
%52 = tail call i8* @ft_strfjoin(i8* %6, i32 %51, i32 1, i32 1)
br label %53
53: ; preds = %50, %3
%54 = phi i8* [ %4, %3 ], [ %52, %50 ]
ret i8* %54
}