#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__ isdigit(char);
int /*<<< orphan*/ sprintf(char *, char *, int, long double);
char *strchr(char *, char);
int strlen(char *);
char *floating(char *type, void *value) {
  static char str[80];
  char len, chr, *fmt, *srce, *dest;
  if (!type || !*type || strlen(type) > (size_t)2)
    return NULL;
  else if (strlen(type) == 1) {
    len = 'h';
    chr = *type;
  } else {
    len = type[0];
    chr = type[1];
  }
  if (chr == 'f')
    fmt = "%#.*G";
  else if (chr == 'e')
    fmt = "%#.*E";
  else
    return NULL;
  if (len == 'h')
    sprintf(str, fmt, 7, *((float *)value));
  else if (len == 'l')
    sprintf(str, fmt, 13, *((double *)value));
  else if (len == 'L')
    sprintf(str, fmt, 13, *((long double *)value));
  else
    return NULL;
  if (!(srce = strchr(str, '.')))
    return str;
  for (dest = srce += 2; isdigit(*srce); ++srce)
    if (*srce != '0')
      dest = srce + 1;
  while (*dest++ = *srce++)
    ;
  return str;
}


x86 assembly (clang, -O0):
<floating>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117d <floating+0x3d>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     117d <floating+0x3d>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x2,%rax
jbe    118a <floating+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    1385 <floating+0x245>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11ae <floating+0x6e>
movb   $0x68,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
jmp    11c1 <floating+0x81>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x1a(%rbp)
jmp    11c6 <floating+0x86>
movsbl -0x1a(%rbp),%eax
cmp    $0x66,%eax
jne    11e3 <floating+0xa3>
lea    0xe26(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1212 <floating+0xd2>
movsbl -0x1a(%rbp),%eax
cmp    $0x65,%eax
jne    1200 <floating+0xc0>
lea    0xe0f(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    120d <floating+0xcd>
movq   $0x0,-0x8(%rbp)
jmp    1385 <floating+0x245>
jmp    1212 <floating+0xd2>
movsbl -0x19(%rbp),%eax
cmp    $0x68,%eax
jne    1244 <floating+0x104>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
flds   (%rax)
mov    %rsp,%rax
fstpt  (%rax)
lea    0x2e1b(%rip),%rdi
mov    $0x7,%edx
call   1060 <sprintf@plt>
jmp    12bf <floating+0x17f>
movsbl -0x19(%rbp),%eax
cmp    $0x6c,%eax
jne    1276 <floating+0x136>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
fldl   (%rax)
mov    %rsp,%rax
fstpt  (%rax)
lea    0x2de9(%rip),%rdi
mov    $0xd,%edx
call   1060 <sprintf@plt>
jmp    12ba <floating+0x17a>
movsbl -0x19(%rbp),%eax
cmp    $0x4c,%eax
jne    12a8 <floating+0x168>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
fldt   (%rax)
mov    %rsp,%rax
fstpt  (%rax)
lea    0x2db7(%rip),%rdi
mov    $0xd,%edx
call   1060 <sprintf@plt>
jmp    12b5 <floating+0x175>
movq   $0x0,-0x8(%rbp)
jmp    1385 <floating+0x245>
jmp    12ba <floating+0x17a>
jmp    12bf <floating+0x17f>
lea    0x2d8a(%rip),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12ee <floating+0x1ae>
lea    0x2d6b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1385 <floating+0x245>
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1346 <floating+0x206>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
je     1330 <floating+0x1f0>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1335 <floating+0x1f5>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    12fe <floating+0x1be>
jmp    134b <floating+0x20b>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%al
mov    -0x38(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     137a <floating+0x23a>
jmp    134b <floating+0x20b>
lea    0x2ccf(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floating>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11b3 <floating+0x73>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11b3 <floating+0x73>
mov    %rsi,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
ja     11b3 <floating+0x73>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x68,%ecx
cmp    $0x1,%eax
je     117f <floating+0x3f>
movsbl (%rbx),%ecx
add    $0x1,%rbx
mov    (%rbx),%al
cmp    $0x66,%al
je     11c3 <floating+0x83>
cmp    $0x65,%al
jne    11b3 <floating+0x73>
lea    0xe76(%rip),%rsi
cmp    $0x4c,%ecx
je     11cf <floating+0x8f>
cmp    $0x6c,%ecx
je     11d4 <floating+0x94>
cmp    $0x68,%ecx
jne    11b3 <floating+0x73>
flds   (%r14)
fstpt  (%rsp)
lea    0x2ea4(%rip),%rdi
mov    $0x7,%edx
jmp    11e6 <floating+0xa6>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe36(%rip),%rsi
cmp    $0x4c,%ecx
jne    1195 <floating+0x55>
fldt   (%r14)
jmp    11d7 <floating+0x97>
fldl   (%r14)
fstpt  (%rsp)
lea    0x2e6f(%rip),%rdi
mov    $0xd,%edx
call   1060 <sprintf@plt>
lea    0x2e5e(%rip),%r14
mov    %r14,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b6 <floating+0x76>
mov    %rax,%rbx
lea    0x2(%rax),%r15
movsbl 0x2(%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     123f <floating+0xff>
add    $0x3,%rbx
nopl   (%rax)
cmpb   $0x30,-0x1(%rbx)
cmovne %rbx,%r15
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1220 <floating+0xe0>
add    $0xffffffffffffffff,%rbx
jmp    1242 <floating+0x102>
mov    %r15,%rbx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rax,1),%ecx
mov    %cl,(%r15,%rax,1)
add    $0x1,%rax
test   %cl,%cl
jne    1250 <floating+0x110>
jmp    11b6 <floating+0x76>

LLVM IR (-O0):
@floating.str = internal global [80 x i8] zeroinitializer
@.str = [6 x i8] c"%#.*G\00"
@.str.1 = [6 x i8] c"%#.*E\00"
define i8* @floating(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = icmp ugt i64 %20, 2
br i1 %21, label %22, label %23
22: ; preds = %17, %13, %2
store i8* null, i8** %3
br label %119
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %23
store i8 104, i8* %6
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
store i8 %29, i8* %7
br label %37
30: ; preds = %23
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
store i8 %33, i8* %6
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
store i8 %36, i8* %7
br label %37
37: ; preds = %30, %27
br label %38
38: ; preds = %37
%39 = load i8, i8* %7
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 102
br i1 %41, label %42, label %43
42: ; preds = %38
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %8
br label %50
43: ; preds = %38
%44 = load i8, i8* %7
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 101
br i1 %46, label %47, label %48
47: ; preds = %43
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %49
48: ; preds = %43
store i8* null, i8** %3
br label %119
49: ; preds = %47
br label %50
50: ; preds = %49, %42
%51 = load i8, i8* %6
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 104
br i1 %53, label %54, label %61
54: ; preds = %50
%55 = load i8*, i8** %8
%56 = load i8*, i8** %5
%57 = bitcast i8* %56 to float*
%58 = load float, float* %57
%59 = fpext float %58 to x86_fp80
%60 = call i32 @sprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8* %55, i32 7, x86_fp80 %59)
br label %85
61: ; preds = %50
%62 = load i8, i8* %6
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 108
br i1 %64, label %65, label %72
65: ; preds = %61
%66 = load i8*, i8** %8
%67 = load i8*, i8** %5
%68 = bitcast i8* %67 to double*
%69 = load double, double* %68
%70 = fpext double %69 to x86_fp80
%71 = call i32 @sprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8* %66, i32 13, x86_fp80 %70)
br label %84
72: ; preds = %61
%73 = load i8, i8* %6
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 76
br i1 %75, label %76, label %82
76: ; preds = %72
%77 = load i8*, i8** %8
%78 = load i8*, i8** %5
%79 = bitcast i8* %78 to x86_fp80*
%80 = load x86_fp80, x86_fp80* %79
%81 = call i32 @sprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8* %77, i32 13, x86_fp80 %80)
br label %83
82: ; preds = %72
store i8* null, i8** %3
br label %119
83: ; preds = %76
br label %84
84: ; preds = %83, %65
br label %85
85: ; preds = %84, %54
%86 = call i8* @strchr(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8 signext 46)
store i8* %86, i8** %9
%87 = icmp ne i8* %86, null
br i1 %87, label %89, label %88
88: ; preds = %85
store i8* getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8** %3
br label %119
89: ; preds = %85
%90 = load i8*, i8** %9
%91 = getelementptr inbounds i8, i8* %90, i64 2
store i8* %91, i8** %9
store i8* %91, i8** %10
br label %92
92: ; preds = %106, %89
%93 = load i8*, i8** %9
%94 = load i8, i8* %93
%95 = call i64 @isdigit(i8 signext %94)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %109
97: ; preds = %92
%98 = load i8*, i8** %9
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = icmp ne i32 %100, 48
br i1 %101, label %102, label %105
102: ; preds = %97
%103 = load i8*, i8** %9
%104 = getelementptr inbounds i8, i8* %103, i64 1
store i8* %104, i8** %10
br label %105
105: ; preds = %102, %97
br label %106
106: ; preds = %105
%107 = load i8*, i8** %9
%108 = getelementptr inbounds i8, i8* %107, i32 1
store i8* %108, i8** %9
br label %92
109: ; preds = %92
br label %110
110: ; preds = %117, %109
%111 = load i8*, i8** %9
%112 = getelementptr inbounds i8, i8* %111, i32 1
store i8* %112, i8** %9
%113 = load i8, i8* %111
%114 = load i8*, i8** %10
%115 = getelementptr inbounds i8, i8* %114, i32 1
store i8* %115, i8** %10
store i8 %113, i8* %114
%116 = icmp ne i8 %113, 0
br i1 %116, label %117, label %118
117: ; preds = %110
br label %110
118: ; preds = %110
store i8* getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8** %3
br label %119
119: ; preds = %118, %88, %82, %48, %22
%120 = load i8*, i8** %3
ret i8* %120
}

LLVM IR (-O2):
@floating.str = internal global [80 x i8] zeroinitializer
@.str = [6 x i8] c"%#.*G\00"
@.str.1 = [6 x i8] c"%#.*E\00"
define i8* @floating(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %66, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %66, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp ugt i32 %8, 2
br i1 %9, label %66, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp eq i32 %11, 1
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i8, i8* %0
%15 = getelementptr inbounds i8, i8* %0, i64 1
%16 = sext i8 %14 to i32
br label %17
17: ; preds = %10, %13
%18 = phi i32 [ %16, %13 ], [ 104, %10 ]
%19 = phi i8* [ %15, %13 ], [ %0, %10 ]
%20 = load i8, i8* %19
switch i8 %20, label %66 [
i8 102, label %22
i8 101, label %21
]
21: ; preds = %17
br label %22
22: ; preds = %17, %21
%23 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %21 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %17 ]
switch i32 %18, label %66 [
i32 104, label %24
i32 108, label %29
i32 76, label %34
]
24: ; preds = %22
%25 = bitcast i8* %1 to float*
%26 = load float, float* %25
%27 = fpext float %26 to x86_fp80
%28 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8* dereferenceable(1) %23, i32 7, x86_fp80 %27)
br label %38
29: ; preds = %22
%30 = bitcast i8* %1 to double*
%31 = load double, double* %30
%32 = fpext double %31 to x86_fp80
%33 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8* dereferenceable(1) %23, i32 13, x86_fp80 %32)
br label %38
34: ; preds = %22
%35 = bitcast i8* %1 to x86_fp80*
%36 = load x86_fp80, x86_fp80* %35
%37 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8* dereferenceable(1) %23, i32 13, x86_fp80 %36)
br label %38
38: ; preds = %29, %34, %24
%39 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), i8 signext 46)
%40 = icmp eq i8* %39, null
br i1 %40, label %66, label %41
41: ; preds = %38
%42 = getelementptr inbounds i8, i8* %39, i64 2
%43 = load i8, i8* %42
%44 = tail call i64 @isdigit(i8 signext %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %56, label %46
46: ; preds = %41, %46
%47 = phi i8* [ %52, %46 ], [ %42, %41 ]
%48 = phi i8* [ %51, %46 ], [ %42, %41 ]
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 48
%51 = getelementptr inbounds i8, i8* %48, i64 1
%52 = select i1 %50, i8* %47, i8* %51
%53 = load i8, i8* %51
%54 = tail call i64 @isdigit(i8 signext %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %46
56: ; preds = %46, %41
%57 = phi i8* [ %42, %41 ], [ %51, %46 ]
%58 = phi i8* [ %42, %41 ], [ %52, %46 ]
br label %59
59: ; preds = %56, %59
%60 = phi i8* [ %62, %59 ], [ %57, %56 ]
%61 = phi i8* [ %64, %59 ], [ %58, %56 ]
%62 = getelementptr inbounds i8, i8* %60, i64 1
%63 = load i8, i8* %60
%64 = getelementptr inbounds i8, i8* %61, i64 1
store i8 %63, i8* %61
%65 = icmp eq i8 %63, 0
br i1 %65, label %66, label %59
66: ; preds = %59, %38, %22, %17, %2, %4, %7
%67 = phi i8* [ null, %7 ], [ null, %4 ], [ null, %2 ], [ null, %17 ], [ null, %22 ], [ getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), %38 ], [ getelementptr inbounds ([80 x i8], [80 x i8]* @floating.str, i64 0, i64 0), %59 ]
ret i8* %67
}