#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*/ ffpmsg(char *);
scalar_t__ snprintf(char *, int, char *, int, ...);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int strlen(char *);
int ffd2e(double dval, int decim, char *cval, int *status) {
  char *cptr;
  if (*status > 0)
    return (*status);
  cval[0] = '\0';
  if (decim < 0) {
    if (snprintf(cval, 71, "%.*G", -decim, dval) < 0) {
      ffpmsg("Error in ffd2e converting float to string");
      *status = 402;
    } else {
      if (!strchr(cval, '.') && strchr(cval, 'E')) {
        if (snprintf(cval, 71, "%.1E", dval) < 0) {
          ffpmsg("Error in ffd2e converting float to string");
          *status = 402;
        }
        return (*status);
      }
    }
  } else {
    if (snprintf(cval, 71, "%.*E", decim, dval) < 0) {
      ffpmsg("Error in ffd2e converting float to string");
      *status = 402;
    }
  }
  if (*status <= 0) {
    if ((cptr = strchr(cval, ',')))
      *cptr = '.';
    if (strchr(cval, 'N')) {
      ffpmsg("Error in ffd2e: double value is a NaN or INDEF");
      *status = 402;
    } else if (!strchr(cval, '.') && !strchr(cval, 'E') &&
               strlen(cval) < 71 - 1) {
      strcat(cval, ".");
    }
  }
  return (*status);
}


x86 assembly (clang, -O0):
<ffd2e>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jle    1183 <ffd2e+0x33>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    136a <ffd2e+0x21a>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x14(%rbp)
jge    125e <ffd2e+0x10e>
mov    -0x20(%rbp),%rdi
xor    %ecx,%ecx
sub    -0x14(%rbp),%ecx
movsd  -0x10(%rbp),%xmm0
mov    $0x47,%esi
lea    0xe52(%rip),%rdx
mov    $0x1,%al
call   1060 <snprintf@plt>
cmp    $0x0,%rax
jge    11da <ffd2e+0x8a>
lea    0xe3f(%rip),%rdi
call   1040 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
jmp    1259 <ffd2e+0x109>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    1254 <ffd2e+0x104>
mov    -0x20(%rbp),%rdi
mov    $0x45,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     1254 <ffd2e+0x104>
mov    -0x20(%rbp),%rdi
cvttsd2si -0x10(%rbp),%ecx
mov    $0x47,%esi
lea    0xe10(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
cmp    $0x0,%rax
jge    1246 <ffd2e+0xf6>
lea    0xdce(%rip),%rdi
call   1040 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    136a <ffd2e+0x21a>
jmp    1259 <ffd2e+0x109>
jmp    12a2 <ffd2e+0x152>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%ecx
movsd  -0x10(%rbp),%xmm0
mov    $0x47,%esi
lea    0xdbe(%rip),%rdx
mov    $0x1,%al
call   1060 <snprintf@plt>
cmp    $0x0,%rax
jge    129d <ffd2e+0x14d>
lea    0xd77(%rip),%rdi
call   1040 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
jmp    12a2 <ffd2e+0x152>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1361 <ffd2e+0x211>
mov    -0x20(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12d2 <ffd2e+0x182>
mov    -0x30(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x4e,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     1305 <ffd2e+0x1b5>
lea    0xd48(%rip),%rdi
call   1040 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
jmp    135c <ffd2e+0x20c>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    1357 <ffd2e+0x207>
mov    -0x20(%rbp),%rdi
mov    $0x45,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    1357 <ffd2e+0x207>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x46,%eax
jge    1357 <ffd2e+0x207>
mov    -0x20(%rbp),%rdi
lea    0xd16(%rip),%rsi
call   1070 <strcat@plt>
jmp    135c <ffd2e+0x20c>
jmp    1361 <ffd2e+0x211>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffd2e>:
push   %r14
push   %rbx
push   %rax
mov    (%rdx),%eax
test   %eax,%eax
jg     1207 <ffd2e+0xb7>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ecx
movb   $0x0,(%rsi)
test   %edi,%edi
js     118a <ffd2e+0x3a>
lea    0xec0(%rip),%rdx
mov    %r14,%rdi
mov    $0x47,%esi
mov    $0x1,%al
call   1060 <snprintf@plt>
test   %rax,%rax
jns    11be <ffd2e+0x6e>
jmp    11f3 <ffd2e+0xa3>
neg    %ecx
lea    0xe6d(%rip),%rdx
mov    %r14,%rdi
mov    $0x47,%esi
movsd  %xmm0,(%rsp)
mov    $0x1,%al
call   1060 <snprintf@plt>
test   %rax,%rax
js     11f3 <ffd2e+0xa3>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     120f <ffd2e+0xbf>
cmpl   $0x0,(%rbx)
jg     1205 <ffd2e+0xb5>
mov    %r14,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11d8 <ffd2e+0x88>
movb   $0x2e,(%rax)
mov    %r14,%rdi
mov    $0x4e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     125a <ffd2e+0x10a>
lea    0xe48(%rip),%rdi
jmp    11fa <ffd2e+0xaa>
lea    0xe0b(%rip),%rdi
call   1040 <ffpmsg@plt>
movl   $0x192,(%rbx)
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
mov    $0x45,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11be <ffd2e+0x6e>
cvttsd2si (%rsp),%ecx
lea    0xe02(%rip),%rdx
mov    %r14,%rdi
mov    $0x47,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
test   %rax,%rax
jns    1205 <ffd2e+0xb5>
lea    0xdbd(%rip),%rdi
call   1040 <ffpmsg@plt>
movl   $0x192,(%rbx)
mov    $0x192,%eax
jmp    1207 <ffd2e+0xb7>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1205 <ffd2e+0xb5>
mov    %r14,%rdi
mov    $0x45,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1205 <ffd2e+0xb5>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x45,%eax
jg     1205 <ffd2e+0xb5>
lea    0xdd2(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
jmp    1205 <ffd2e+0xb5>

LLVM IR (-O0):
@.str = [5 x i8] c"%.*G\00"
@.str.1 = [42 x i8] c"Error in ffd2e converting float to string\00"
@.str.2 = [5 x i8] c"%.1E\00"
@.str.3 = [5 x i8] c"%.*E\00"
@.str.4 = [47 x i8] c"Error in ffd2e: double value is a NaN or INDEF\00"
@.str.5 = [2 x i8] c".\00"
define i32 @ffd2e(double %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
store double %0, double* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%11 = load i32*, i32** %9
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32*, i32** %9
%16 = load i32, i32* %15
store i32 %16, i32* %5
br label %101
17: ; preds = %4
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 0, i8* %19
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %54
22: ; preds = %17
%23 = load i8*, i8** %8
%24 = load i32, i32* %7
%25 = sub nsw i32 0, %24
%26 = load double, double* %6
%27 = call i64 (i8*, i32, i8*, i32, ...) @snprintf(i8* %23, i32 71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %25, double %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32*, i32** %9
store i32 402, i32* %31
br label %53
32: ; preds = %22
%33 = load i8*, i8** %8
%34 = call i8* @strchr(i8* %33, i8 signext 46)
%35 = icmp ne i8* %34, null
br i1 %35, label %52, label %36
36: ; preds = %32
%37 = load i8*, i8** %8
%38 = call i8* @strchr(i8* %37, i8 signext 69)
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %52
40: ; preds = %36
%41 = load i8*, i8** %8
%42 = load double, double* %6
%43 = fptosi double %42 to i32
%44 = call i64 (i8*, i32, i8*, i32, ...) @snprintf(i8* %41, i32 71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%48 = load i32*, i32** %9
store i32 402, i32* %48
br label %49
49: ; preds = %46, %40
%50 = load i32*, i32** %9
%51 = load i32, i32* %50
store i32 %51, i32* %5
br label %101
52: ; preds = %36, %32
br label %53
53: ; preds = %52, %29
br label %64
54: ; preds = %17
%55 = load i8*, i8** %8
%56 = load i32, i32* %7
%57 = load double, double* %6
%58 = call i64 (i8*, i32, i8*, i32, ...) @snprintf(i8* %55, i32 71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %56, double %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%62 = load i32*, i32** %9
store i32 402, i32* %62
br label %63
63: ; preds = %60, %54
br label %64
64: ; preds = %63, %53
%65 = load i32*, i32** %9
%66 = load i32, i32* %65
%67 = icmp sle i32 %66, 0
br i1 %67, label %68, label %98
68: ; preds = %64
%69 = load i8*, i8** %8
%70 = call i8* @strchr(i8* %69, i8 signext 44)
store i8* %70, i8** %10
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = load i8*, i8** %10
store i8 46, i8* %73
br label %74
74: ; preds = %72, %68
%75 = load i8*, i8** %8
%76 = call i8* @strchr(i8* %75, i8 signext 78)
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %81
78: ; preds = %74
%79 = call i32 @ffpmsg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%80 = load i32*, i32** %9
store i32 402, i32* %80
br label %97
81: ; preds = %74
%82 = load i8*, i8** %8
%83 = call i8* @strchr(i8* %82, i8 signext 46)
%84 = icmp ne i8* %83, null
br i1 %84, label %96, label %85
85: ; preds = %81
%86 = load i8*, i8** %8
%87 = call i8* @strchr(i8* %86, i8 signext 69)
%88 = icmp ne i8* %87, null
br i1 %88, label %96, label %89
89: ; preds = %85
%90 = load i8*, i8** %8
%91 = call i32 @strlen(i8* %90)
%92 = icmp slt i32 %91, 70
br i1 %92, label %93, label %96
93: ; preds = %89
%94 = load i8*, i8** %8
%95 = call i32 @strcat(i8* %94, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %96
96: ; preds = %93, %89, %85, %81
br label %97
97: ; preds = %96, %78
br label %98
98: ; preds = %97, %64
%99 = load i32*, i32** %9
%100 = load i32, i32* %99
store i32 %100, i32* %5
br label %101
101: ; preds = %98, %49, %14
%102 = load i32, i32* %5
ret i32 %102
}

LLVM IR (-O2):
@.str = [5 x i8] c"%.*G\00"
@.str.1 = [42 x i8] c"Error in ffd2e converting float to string\00"
@.str.2 = [5 x i8] c"%.1E\00"
@.str.3 = [5 x i8] c"%.*E\00"
@.str.4 = [47 x i8] c"Error in ffd2e: double value is a NaN or INDEF\00"
@.str.5 = [2 x i8] c".\00"
define i32 @ffd2e(double %0, i32 %1, i8* %2, i32* nocapture %3) {
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 0
br i1 %6, label %59, label %7
7: ; preds = %4
store i8 0, i8* %2
%8 = icmp slt i32 %1, 0
br i1 %8, label %9, label %29
9: ; preds = %7
%10 = sub nsw i32 0, %1
%11 = tail call i64 (i8*, i32, i8*, i32, ...) @snprintf(i8* %2, i32 71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10, double %0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 402, i32* %3
br label %57
15: ; preds = %9
%16 = tail call i8* @strchr(i8* %2, i8 signext 46)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = tail call i8* @strchr(i8* %2, i8 signext 69)
%20 = icmp eq i8* %19, null
br i1 %20, label %34, label %21
21: ; preds = %18
%22 = fptosi double %0 to i32
%23 = tail call i64 (i8*, i32, i8*, i32, ...) @snprintf(i8* %2, i32 71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = load i32, i32* %3
br label %59
27: ; preds = %21
%28 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 402, i32* %3
br label %59
29: ; preds = %7
%30 = tail call i64 (i8*, i32, i8*, i32, ...) @snprintf(i8* %2, i32 71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %1, double %0)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 402, i32* %3
br label %57
34: ; preds = %29, %18, %15
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 1
br i1 %36, label %37, label %57
37: ; preds = %34
%38 = tail call i8* @strchr(i8* %2, i8 signext 44)
%39 = icmp eq i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %37
store i8 46, i8* %38
br label %41
41: ; preds = %40, %37
%42 = tail call i8* @strchr(i8* %2, i8 signext 78)
%43 = icmp eq i8* %42, null
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
store i32 402, i32* %3
br label %57
46: ; preds = %41
%47 = tail call i8* @strchr(i8* %2, i8 signext 46)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = tail call i8* @strchr(i8* %2, i8 signext 69)
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = tail call i32 @strlen(i8* %2)
%54 = icmp slt i32 %53, 70
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %13, %32, %44, %55, %52, %49, %46, %34
%58 = load i32, i32* %3
br label %59
59: ; preds = %27, %25, %4, %57
%60 = phi i32 [ %58, %57 ], [ %5, %4 ], [ %26, %25 ], [ 402, %27 ]
ret i32 %60
}