#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 const *, unsigned char, double);
char *dtostre(double val, char *s, unsigned char prec, unsigned char flags) {
  char *_s = s;
  if (prec > 7) {
    prec = 7;
  }
  if (flags & 2) {
    if (val >= 0) {
      *_s++ = '+';
    }
  } else if (flags & 1) {
    if (val >= 0) {
      *_s++ = ' ';
    }
  }
  const char *fmt = "%.*le";
  if (flags & 4) {
    fmt = "%.*lE";
  }
  sprintf(_s, fmt, prec, val);
  return s;
}


x86 assembly (clang, -O0):
<dtostre>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %sil,%cl
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x7,%eax
jle    1145 <dtostre+0x35>
movb   $0x7,-0x11(%rbp)
movzbl -0x12(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     117e <dtostre+0x6e>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1179 <dtostre+0x69>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2b,(%rax)
jmp    11bc <dtostre+0xac>
movzbl -0x12(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11b7 <dtostre+0xa7>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b2 <dtostre+0xa2>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x20,(%rax)
jmp    11b7 <dtostre+0xa7>
jmp    11bc <dtostre+0xac>
lea    0xe3d(%rip),%rax
mov    %rax,-0x28(%rbp)
movzbl -0x12(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11e2 <dtostre+0xd2>
lea    0xe28(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x11(%rbp),%al
movsd  -0x8(%rbp),%xmm0
movzbl %al,%edx
call   1030 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dtostre>:
push   %rbx
mov    %rdi,%rbx
test   $0x2,%dl
jne    1134 <dtostre+0x24>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %rbx,%rdi
jb     1149 <dtostre+0x39>
mov    %edx,%ecx
mov    $0x20,%al
mov    %rbx,%rdi
and    $0x1,%ecx
jne    1143 <dtostre+0x33>
jmp    1149 <dtostre+0x39>
mov    $0x2b,%al
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %rbx,%rdi
jb     1149 <dtostre+0x39>
lea    0x1(%rbx),%rdi
mov    %al,(%rbx)
cmp    $0x7,%sil
movzbl %sil,%eax
mov    $0x7,%ecx
cmovb  %eax,%ecx
test   $0x4,%dl
lea    0xe9d(%rip),%rax
lea    0xe9c(%rip),%rsi
cmove  %rax,%rsi
movzbl %cl,%edx
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%.*le\00"
@.str.1 = [6 x i8] c"%.*lE\00"
define i8* @dtostre(double %0, i8* %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca double
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i8*
store double %0, double* %5
store i8* %1, i8** %6
store i8 %2, i8* %7
store i8 %3, i8* %8
%11 = load i8*, i8** %6
store i8* %11, i8** %9
%12 = load i8, i8* %7
%13 = zext i8 %12 to i32
%14 = icmp sgt i32 %13, 7
br i1 %14, label %15, label %16
15: ; preds = %4
store i8 7, i8* %7
br label %16
16: ; preds = %15, %4
%17 = load i8, i8* %8
%18 = zext i8 %17 to i32
%19 = and i32 %18, 2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = load double, double* %5
%23 = fcmp oge double %22, 0.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %9
store i8 43, i8* %25
br label %27
27: ; preds = %24, %21
br label %41
28: ; preds = %16
%29 = load i8, i8* %8
%30 = zext i8 %29 to i32
%31 = and i32 %30, 1
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %28
%34 = load double, double* %5
%35 = fcmp oge double %34, 0.000000e+00
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %9
store i8 32, i8* %37
br label %39
39: ; preds = %36, %33
br label %40
40: ; preds = %39, %28
br label %41
41: ; preds = %40, %27
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %10
%42 = load i8, i8* %8
%43 = zext i8 %42 to i32
%44 = and i32 %43, 4
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %10
br label %47
47: ; preds = %46, %41
%48 = load i8*, i8** %9
%49 = load i8*, i8** %10
%50 = load i8, i8* %7
%51 = load double, double* %5
%52 = call i32 @sprintf(i8* %48, i8* %49, i8 zeroext %50, double %51)
%53 = load i8*, i8** %6
ret i8* %53
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.*le\00"
@.str.1 = [6 x i8] c"%.*lE\00"
define i8* @dtostre(double %0, i8* returned writeonly %1, i8 zeroext %2, i8 zeroext %3) {
%5 = zext i8 %3 to i32
%6 = and i32 %5, 2
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = fcmp ult double %0, 0.000000e+00
br i1 %9, label %18, label %15
10: ; preds = %4
%11 = and i32 %5, 1
%12 = icmp ne i32 %11, 0
%13 = fcmp oge double %0, 0.000000e+00
%14 = and i1 %13, %12
br i1 %14, label %15, label %18
15: ; preds = %10, %8
%16 = phi i8 [ 43, %8 ], [ 32, %10 ]
%17 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %16, i8* %1
br label %18
18: ; preds = %15, %10, %8
%19 = phi i8* [ %1, %8 ], [ %1, %10 ], [ %17, %15 ]
%20 = icmp ult i8 %2, 7
%21 = select i1 %20, i8 %2, i8 7
%22 = and i32 %5, 4
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) %24, i8 zeroext %21, double %0)
ret i8* %1
}