#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*/ ret;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, float);
const char *fpmtoa(float a) {
  static int idx = 0;
  static char ret[4][20];
  idx = (idx + 1) % (sizeof(ret) / sizeof(ret[0]));
  snprintf(ret[idx], sizeof(ret[0]), "%.3f", a);
  return ret[idx];
}


x86 assembly (clang, -O0):
<fpmtoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
mov    0x2f1d(%rip),%eax
add    $0x1,%eax
cltq
and    $0x3,%rax
mov    %eax,0x2f0e(%rip)
movslq 0x2f07(%rip),%rax
lea    0x2f10(%rip),%rdi
imul   $0x14,%rax,%rax
add    %rax,%rdi
movss  -0x4(%rbp),%xmm0
mov    $0x14,%esi
lea    0xea8(%rip),%rdx
call   1030 <snprintf@plt>
movslq 0x2edc(%rip),%rcx
lea    0x2ee5(%rip),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fpmtoa>:
push   %rbx
mov    0x2f29(%rip),%eax
add    $0x1,%eax
and    $0x3,%eax
mov    %eax,0x2f1d(%rip)
lea    (%rax,%rax,4),%rax
lea    0x2f22(%rip),%rbx
lea    (%rbx,%rax,4),%rdi
lea    0xec7(%rip),%rdx
mov    $0x14,%esi
call   1030 <snprintf@plt>
mov    0x2ef7(%rip),%eax
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,4),%rax
pop    %rbx
ret

LLVM IR (-O0):
@fpmtoa.idx = internal global i32 0
@fpmtoa.ret = internal global [4 x [20 x i8]] zeroinitializer
@.str = [5 x i8] c"%.3f\00"
define i8* @fpmtoa(float %0) {
%2 = alloca float
store float %0, float* %2
%3 = load i32, i32* @fpmtoa.idx
%4 = add nsw i32 %3, 1
%5 = sext i32 %4 to i64
%6 = urem i64 %5, 4
%7 = trunc i64 %6 to i32
store i32 %7, i32* @fpmtoa.idx
%8 = load i32, i32* @fpmtoa.idx
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [4 x [20 x i8]], [4 x [20 x i8]]* @fpmtoa.ret, i64 0, i64 %9
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%12 = load float, float* %2
%13 = call i32 @snprintf(i8* %11, i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %12)
%14 = load i32, i32* @fpmtoa.idx
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x [20 x i8]], [4 x [20 x i8]]* @fpmtoa.ret, i64 0, i64 %15
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
ret i8* %17
}

LLVM IR (-O2):
@fpmtoa.idx = internal unnamed_addr global i32 0
@fpmtoa.ret = internal global [4 x [20 x i8]] zeroinitializer
@.str = [5 x i8] c"%.3f\00"
define i8* @fpmtoa(float %0) {
%2 = load i32, i32* @fpmtoa.idx
%3 = add nsw i32 %2, 1
%4 = and i32 %3, 3
store i32 %4, i32* @fpmtoa.idx
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds [4 x [20 x i8]], [4 x [20 x i8]]* @fpmtoa.ret, i64 0, i64 %5, i64 0
%7 = tail call i32 @snprintf(i8* %6, i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %0)
%8 = load i32, i32* @fpmtoa.idx
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [4 x [20 x i8]], [4 x [20 x i8]]* @fpmtoa.ret, i64 0, i64 %9, i64 0
ret i8* %10
}