#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 atoi(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, double);
char *ecvt(double x, int n, int *dp, int *sign) {
  static char buf[16];
  char tmp[32];
  int i, j;
  if (n - 1U > 15)
    n = 15;
  sprintf(tmp, "%.*e", n - 1, x);
  i = *sign = (tmp[0] == '-');
  for (j = 0; tmp[i] != 'e'; j += (tmp[i++] != '.'))
    buf[j] = tmp[i];
  buf[j] = 0;
  *dp = atoi(tmp + i + 1) + 1;
  return buf;
}


x86 assembly (clang, -O0):
<ecvt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cmp    $0xf,%eax
jbe    114e <ecvt+0x2e>
movl   $0xf,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
movsd  -0x8(%rbp),%xmm0
lea    0xe9c(%rip),%rsi
call   1040 <sprintf@plt>
movsbl -0x40(%rbp),%eax
cmp    $0x2d,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x20(%rbp),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x65,%eax
je     11d8 <ecvt+0xb8>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%dl
movslq -0x48(%rbp),%rcx
lea    0x2e93(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x44(%rbp)
cltq
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x2e,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    1188 <ecvt+0x68>
movslq -0x48(%rbp),%rcx
lea    0x2e5d(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    -0x40(%rbp),%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1030 <atoi@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    0x2e33(%rip),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecvt>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
lea    -0x11(%rdi),%eax
lea    -0x1(%rdi),%ecx
cmp    $0xfffffff0,%eax
mov    $0xe,%edx
cmovae %ecx,%edx
lea    0xebb(%rip),%rsi
mov    %rsp,%rdi
call   1040 <sprintf@plt>
xor    %ecx,%ecx
cmpb   $0x2d,(%rsp)
sete   %cl
mov    %ecx,(%rbx)
mov    (%rsp,%rcx,1),%bl
xor    %eax,%eax
cmp    $0x65,%bl
je     1191 <ecvt+0x71>
lea    0x2ed7(%rip),%rdx
nopl   0x0(%rax)
mov    %eax,%esi
mov    %eax,%eax
mov    %bl,(%rax,%rdx,1)
xor    %eax,%eax
cmp    $0x2e,%bl
movzbl 0x1(%rsp,%rcx,1),%ebx
lea    0x1(%rcx),%rcx
setne  %al
add    %esi,%eax
cmp    $0x65,%bl
jne    1170 <ecvt+0x50>
mov    %eax,%eax
mov    %ecx,%ecx
lea    0x2ea6(%rip),%rbx
movb   $0x0,(%rax,%rbx,1)
lea    (%rsp,%rcx,1),%rdi
add    $0x1,%rdi
call   1030 <atoi@plt>
add    $0x1,%eax
mov    %eax,(%r14)
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ecvt.buf = internal global [16 x i8] zeroinitializer
@.str = [5 x i8] c"%.*e\00"
define i8* @ecvt(double %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [32 x i8]
%10 = alloca i32
%11 = alloca i32
store double %0, double* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = load i32, i32* %6
%13 = sub i32 %12, 1
%14 = icmp ugt i32 %13, 15
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 15, i32* %6
br label %16
16: ; preds = %15, %4
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 1
%20 = load double, double* %5
%21 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19, double %20)
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 45
%26 = zext i1 %25 to i32
%27 = load i32*, i32** %8
store i32 %26, i32* %27
store i32 %26, i32* %10
store i32 0, i32* %11
br label %28
28: ; preds = %43, %16
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 101
br i1 %34, label %35, label %54
35: ; preds = %28
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [16 x i8], [16 x i8]* @ecvt.buf, i64 0, i64 %41
store i8 %39, i8* %42
br label %43
43: ; preds = %35
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 46
%51 = zext i1 %50 to i32
%52 = load i32, i32* %11
%53 = add nsw i32 %52, %51
store i32 %53, i32* %11
br label %28
54: ; preds = %28
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [16 x i8], [16 x i8]* @ecvt.buf, i64 0, i64 %56
store i8 0, i8* %57
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = call i32 @atoi(i8* %62)
%64 = add nsw i32 %63, 1
%65 = load i32*, i32** %7
store i32 %64, i32* %65
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ecvt.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@ecvt.buf = internal global [16 x i8] zeroinitializer
@.str = [5 x i8] c"%.*e\00"
define i8* @ecvt(double %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = add i32 %1, -17
%8 = icmp ult i32 %7, -16
%9 = add nsw i32 %1, -1
%10 = select i1 %8, i32 14, i32 %9
%11 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10, double %0)
%12 = load i8, i8* %6
%13 = icmp eq i8 %12, 45
%14 = zext i1 %13 to i32
store i32 %14, i32* %3
%15 = zext i1 %13 to i64
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 101
br i1 %18, label %35, label %19
19: ; preds = %4, %19
%20 = phi i64 [ %25, %19 ], [ %15, %4 ]
%21 = phi i8 [ %30, %19 ], [ %17, %4 ]
%22 = phi i32 [ %28, %19 ], [ 0, %4 ]
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [16 x i8], [16 x i8]* @ecvt.buf, i64 0, i64 %23
store i8 %21, i8* %24
%25 = add nuw nsw i64 %20, 1
%26 = icmp ne i8 %21, 46
%27 = zext i1 %26 to i32
%28 = add nuw nsw i32 %22, %27
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %25
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 101
br i1 %31, label %32, label %19
32: ; preds = %19
%33 = trunc i64 %25 to i32
%34 = zext i32 %28 to i64
br label %35
35: ; preds = %32, %4
%36 = phi i32 [ %14, %4 ], [ %33, %32 ]
%37 = phi i64 [ 0, %4 ], [ %34, %32 ]
%38 = zext i32 %36 to i64
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %38
%40 = getelementptr inbounds [16 x i8], [16 x i8]* @ecvt.buf, i64 0, i64 %37
store i8 0, i8* %40
%41 = getelementptr inbounds i8, i8* %39, i64 1
%42 = call i32 @atoi(i8* %41)
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @ecvt.buf, i64 0, i64 0)
}