#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 */
int /*<<< orphan*/ sprintf(char *, char *, float);
char *tochar(float value, int len) {
  static char s[20];
  int i, to, from;
  sprintf(s, "%12.5E", value);
  from = 9;
  to = len - 2;
  for (i = 0; i < 4; i++)
    s[to + i] = s[from + i];
  return s + 1;
}


x86 assembly (clang, -O0):
<tochar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
lea    0x2f14(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1030 <sprintf@plt>
movl   $0x9,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jge    118d <tochar+0x7d>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
movslq %eax,%rcx
lea    0x2ed7(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
movslq %eax,%rcx
lea    0x2ec4(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114f <tochar+0x3f>
lea    0x2eac(%rip),%rax
add    $0x1,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tochar>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x2f24(%rip),%rbx
lea    0xedd(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
movslq %ebp,%rax
mov    0x2f15(%rip),%cl
mov    %cl,-0x2(%rax,%rbx,1)
mov    0x2f0c(%rip),%cl
mov    %cl,-0x1(%rax,%rbx,1)
mov    0x2f03(%rip),%cl
mov    %cl,(%rax,%rbx,1)
mov    0x2efb(%rip),%cl
mov    %cl,0x1(%rax,%rbx,1)
lea    0x2ee5(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@tochar.s = internal global [20 x i8] zeroinitializer
@.str = [7 x i8] c"%12.5E\00"
define i8* @tochar(float %0, i32 %1) {
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store float %0, float* %3
store i32 %1, i32* %4
%8 = load float, float* %3
%9 = call i32 @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tochar.s, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %8)
store i32 9, i32* %7
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 2
store i32 %11, i32* %6
store i32 0, i32* %5
br label %12
12: ; preds = %27, %2
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %30
15: ; preds = %12
%16 = load i32, i32* %7
%17 = load i32, i32* %5
%18 = add nsw i32 %16, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [20 x i8], [20 x i8]* @tochar.s, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = load i32, i32* %6
%23 = load i32, i32* %5
%24 = add nsw i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [20 x i8], [20 x i8]* @tochar.s, i64 0, i64 %25
store i8 %21, i8* %26
br label %27
27: ; preds = %15
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %12
30: ; preds = %12
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tochar.s, i64 0, i64 1)
}

LLVM IR (-O2):
@tochar.s = internal global [20 x i8] zeroinitializer
@.str = [7 x i8] c"%12.5E\00"
define i8* @tochar(float %0, i32 %1) {
%3 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @tochar.s, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %0)
%4 = add nsw i32 %1, -2
%5 = sext i32 %4 to i64
%6 = load i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tochar.s, i64 0, i64 9)
%7 = getelementptr inbounds [20 x i8], [20 x i8]* @tochar.s, i64 0, i64 %5
store i8 %6, i8* %7
%8 = load i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tochar.s, i64 0, i64 10)
%9 = add nsw i64 %5, 1
%10 = getelementptr inbounds [20 x i8], [20 x i8]* @tochar.s, i64 0, i64 %9
store i8 %8, i8* %10
%11 = load i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tochar.s, i64 0, i64 11)
%12 = add nsw i64 %5, 2
%13 = getelementptr inbounds [20 x i8], [20 x i8]* @tochar.s, i64 0, i64 %12
store i8 %11, i8* %13
%14 = load i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tochar.s, i64 0, i64 12)
%15 = add nsw i64 %5, 3
%16 = getelementptr inbounds [20 x i8], [20 x i8]* @tochar.s, i64 0, i64 %15
store i8 %14, i8* %16
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tochar.s, i64 0, i64 1)
}