#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 */
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ best;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int sprintf(char *, char *, int, ...);
scalar_t__ strtod(char *, int /*<<< orphan*/);
void print_minfloat(float f, FILE *out) {
  int i;
  int bestlen;
  char best[32];
  bestlen = sprintf(best, "%#.9g", f);
  for (i = 8; i > 0; i--) {
    char buf[sizeof(best)];
    int len = sprintf(buf, "%#.*g", i, f);
    if (f == (float)strtod(buf, 0)) {
      if (len < bestlen) {
        bestlen = len;
        memcpy(best, buf, sizeof(buf));
      }
    } else {
      break;
    }
  }
  fwrite(best, bestlen, 1, out);
}


x86 assembly (clang, -O0):
<print_minfloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
cvttss2si -0x4(%rbp),%edx
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,-0x18(%rbp)
movl   $0x8,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    120c <print_minfloat+0xcc>
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%edx
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe73(%rip),%rsi
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,-0x64(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movss  -0x68(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
ucomiss %xmm1,%xmm0
jne    11f4 <print_minfloat+0xb4>
jp     11f4 <print_minfloat+0xb4>
mov    -0x64(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ef <print_minfloat+0xaf>
mov    -0x64(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
jmp    11f9 <print_minfloat+0xb9>
jmp    120c <print_minfloat+0xcc>
jmp    11fe <print_minfloat+0xbe>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <print_minfloat+0x32>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_minfloat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
movss  %xmm0,0x4(%rsp)
cvttss2si %xmm0,%edx
lea    0xea2(%rip),%rsi
lea    0x30(%rsp),%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %eax,%r15d
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe88(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%edx
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0x4(%rsp),%xmm0
jne    1477 <print_minfloat+0x337>
jp     1477 <print_minfloat+0x337>
cmp    %r15d,%ebp
jge    11d9 <print_minfloat+0x99>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %ebp,%r15d
lea    0xe26(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7,%edx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0x4(%rsp),%xmm0
jne    1477 <print_minfloat+0x337>
jp     1477 <print_minfloat+0x337>
cmp    %r15d,%ebp
jge    123b <print_minfloat+0xfb>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %ebp,%r15d
lea    0xdc4(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x6,%edx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0x4(%rsp),%xmm0
jne    1477 <print_minfloat+0x337>
jp     1477 <print_minfloat+0x337>
cmp    %r15d,%ebp
jge    129d <print_minfloat+0x15d>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %ebp,%r15d
lea    0xd62(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5,%edx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0x4(%rsp),%xmm0
jne    1477 <print_minfloat+0x337>
jp     1477 <print_minfloat+0x337>
cmp    %r15d,%ebp
jge    12ff <print_minfloat+0x1bf>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %ebp,%r15d
lea    0xd00(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0x4(%rsp),%xmm0
jne    1477 <print_minfloat+0x337>
jp     1477 <print_minfloat+0x337>
cmp    %r15d,%ebp
jge    1361 <print_minfloat+0x221>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %ebp,%r15d
lea    0xc9e(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0x4(%rsp),%xmm0
jne    1477 <print_minfloat+0x337>
jp     1477 <print_minfloat+0x337>
cmp    %r15d,%ebp
jge    13c3 <print_minfloat+0x283>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %ebp,%r15d
lea    0xc3c(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0x4(%rsp),%xmm0
jne    1477 <print_minfloat+0x337>
jp     1477 <print_minfloat+0x337>
cmp    %r15d,%ebp
jge    141d <print_minfloat+0x2dd>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %ebp,%r15d
lea    0xbe2(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss 0x4(%rsp),%xmm0
jne    1477 <print_minfloat+0x337>
jp     1477 <print_minfloat+0x337>
cmp    %r15d,%ebp
jge    1477 <print_minfloat+0x337>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    %ebp,%r15d
lea    0x30(%rsp),%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%#.9g\00"
@.str.1 = [6 x i8] c"%#.*g\00"
define void @print_minfloat(float %0, i32* %1) {
%3 = alloca float
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca [32 x i8]
%9 = alloca i32
store float %0, float* %3
store i32* %1, i32** %4
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%11 = load float, float* %3
%12 = fptosi float %11 to i32
%13 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
store i32 8, i32* %5
br label %14
14: ; preds = %40, %2
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %43
17: ; preds = %14
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%19 = load i32, i32* %5
%20 = load float, float* %3
%21 = fpext float %20 to double
%22 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19, double %21)
store i32 %22, i32* %9
%23 = load float, float* %3
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%25 = call i64 @strtod(i8* %24, i32 0)
%26 = sitofp i64 %25 to float
%27 = fcmp oeq float %23, %26
br i1 %27, label %28, label %38
28: ; preds = %17
%29 = load i32, i32* %9
%30 = load i32, i32* %6
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* %9
store i32 %33, i32* %6
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%36 = call i32 @memcpy(i8* %34, i8* %35, i32 32)
br label %37
37: ; preds = %32, %28
br label %39
38: ; preds = %17
br label %43
39: ; preds = %37
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, -1
store i32 %42, i32* %5
br label %14
43: ; preds = %38, %14
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%45 = load i32, i32* %6
%46 = load i32*, i32** %4
%47 = call i32 @fwrite(i8* %44, i32 %45, i32 1, i32* %46)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%#.9g\00"
@.str.1 = [6 x i8] c"%#.*g\00"
define void @print_minfloat(float %0, i32* nocapture %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = fptosi float %0 to i32
%7 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = fpext float %0 to double
%10 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 8, double %9)
%11 = call i64 @strtod(i8* %8, i32 0)
%12 = sitofp i64 %11 to float
%13 = fcmp oeq float %12, %0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = icmp slt i32 %10, %7
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = call i32 @memcpy(i8* %5, i8* %8, i32 32)
br label %20
18: ; preds = %80, %70, %60, %50, %40, %30, %20, %2
%19 = phi i32 [ %7, %2 ], [ %21, %20 ], [ %31, %30 ], [ %41, %40 ], [ %51, %50 ], [ %61, %60 ], [ %71, %70 ], [ %81, %80 ]
br label %92
20: ; preds = %14, %16
%21 = phi i32 [ %7, %14 ], [ %10, %16 ]
%22 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 7, double %9)
%23 = call i64 @strtod(i8* %8, i32 0)
%24 = sitofp i64 %23 to float
%25 = fcmp oeq float %24, %0
br i1 %25, label %26, label %18
26: ; preds = %20
%27 = icmp slt i32 %22, %21
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = call i32 @memcpy(i8* %5, i8* %8, i32 32)
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %21, %26 ], [ %22, %28 ]
%32 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6, double %9)
%33 = call i64 @strtod(i8* %8, i32 0)
%34 = sitofp i64 %33 to float
%35 = fcmp oeq float %34, %0
br i1 %35, label %36, label %18
36: ; preds = %30
%37 = icmp slt i32 %32, %31
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = call i32 @memcpy(i8* %5, i8* %8, i32 32)
br label %40
40: ; preds = %38, %36
%41 = phi i32 [ %31, %36 ], [ %32, %38 ]
%42 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5, double %9)
%43 = call i64 @strtod(i8* %8, i32 0)
%44 = sitofp i64 %43 to float
%45 = fcmp oeq float %44, %0
br i1 %45, label %46, label %18
46: ; preds = %40
%47 = icmp slt i32 %42, %41
br i1 %47, label %48, label %50
48: ; preds = %46
%49 = call i32 @memcpy(i8* %5, i8* %8, i32 32)
br label %50
50: ; preds = %48, %46
%51 = phi i32 [ %41, %46 ], [ %42, %48 ]
%52 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 4, double %9)
%53 = call i64 @strtod(i8* %8, i32 0)
%54 = sitofp i64 %53 to float
%55 = fcmp oeq float %54, %0
br i1 %55, label %56, label %18
56: ; preds = %50
%57 = icmp slt i32 %52, %51
br i1 %57, label %58, label %60
58: ; preds = %56
%59 = call i32 @memcpy(i8* %5, i8* %8, i32 32)
br label %60
60: ; preds = %58, %56
%61 = phi i32 [ %51, %56 ], [ %52, %58 ]
%62 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 3, double %9)
%63 = call i64 @strtod(i8* %8, i32 0)
%64 = sitofp i64 %63 to float
%65 = fcmp oeq float %64, %0
br i1 %65, label %66, label %18
66: ; preds = %60
%67 = icmp slt i32 %62, %61
br i1 %67, label %68, label %70
68: ; preds = %66
%69 = call i32 @memcpy(i8* %5, i8* %8, i32 32)
br label %70
70: ; preds = %68, %66
%71 = phi i32 [ %61, %66 ], [ %62, %68 ]
%72 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 2, double %9)
%73 = call i64 @strtod(i8* %8, i32 0)
%74 = sitofp i64 %73 to float
%75 = fcmp oeq float %74, %0
br i1 %75, label %76, label %18
76: ; preds = %70
%77 = icmp slt i32 %72, %71
br i1 %77, label %78, label %80
78: ; preds = %76
%79 = call i32 @memcpy(i8* %5, i8* %8, i32 32)
br label %80
80: ; preds = %78, %76
%81 = phi i32 [ %71, %76 ], [ %72, %78 ]
%82 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1, double %9)
%83 = call i64 @strtod(i8* %8, i32 0)
%84 = sitofp i64 %83 to float
%85 = fcmp oeq float %84, %0
br i1 %85, label %86, label %18
86: ; preds = %80
%87 = icmp slt i32 %82, %81
br i1 %87, label %88, label %90
88: ; preds = %86
%89 = call i32 @memcpy(i8* %5, i8* %8, i32 32)
br label %90
90: ; preds = %88, %86
%91 = phi i32 [ %81, %86 ], [ %82, %88 ]
br label %92
92: ; preds = %90, %18
%93 = phi i32 [ %19, %18 ], [ %91, %90 ]
%94 = call i32 @fwrite(i8* %5, i32 %93, i32 1, i32* %1)
ret void
}