#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__ sprintf(char *, char *, int, ...);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, 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 (sprintf(cval, "%.*G", -decim, dval) < 0) {
      ffpmsg("Error in ffd2e converting float to string");
      *status = 402;
    } else {
      if (!strchr(cval, '.') && strchr(cval, 'E')) {
        if (sprintf(cval, "%.1E", dval) < 0) {
          ffpmsg("Error in ffd2e converting float to string");
          *status = 402;
        }
        return (*status);
      }
    }
  } else {
    if (sprintf(cval, "%.*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')) {
      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    1173 <ffd2e+0x33>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <ffd2e+0x1f9>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x14(%rbp)
jge    1244 <ffd2e+0x104>
mov    -0x20(%rbp),%rdi
xor    %edx,%edx
sub    -0x14(%rbp),%edx
movsd  -0x10(%rbp),%xmm0
lea    0xe67(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
cmp    $0x0,%rax
jge    11c5 <ffd2e+0x85>
lea    0xe54(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
jmp    123f <ffd2e+0xff>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    123a <ffd2e+0xfa>
mov    -0x20(%rbp),%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     123a <ffd2e+0xfa>
mov    -0x20(%rbp),%rdi
cvttsd2si -0x10(%rbp),%edx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
cmp    $0x0,%rax
jge    122c <ffd2e+0xec>
lea    0xde8(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <ffd2e+0x1f9>
jmp    123f <ffd2e+0xff>
jmp    1283 <ffd2e+0x143>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
movsd  -0x10(%rbp),%xmm0
lea    0xddd(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
cmp    $0x0,%rax
jge    127e <ffd2e+0x13e>
lea    0xd96(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
jmp    1283 <ffd2e+0x143>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1330 <ffd2e+0x1f0>
mov    -0x20(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12b3 <ffd2e+0x173>
mov    -0x30(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     12e6 <ffd2e+0x1a6>
lea    0xd67(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
jmp    132b <ffd2e+0x1eb>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1326 <ffd2e+0x1e6>
mov    -0x20(%rbp),%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1326 <ffd2e+0x1e6>
mov    -0x20(%rbp),%rdi
lea    0xd47(%rip),%rsi
call   1050 <strcat@plt>
jmp    132b <ffd2e+0x1eb>
jmp    1330 <ffd2e+0x1f0>
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,%rbx
mov    (%rdx),%eax
test   %eax,%eax
jg     11ed <ffd2e+0xad>
mov    %rsi,%r14
mov    %edi,%edx
movb   $0x0,(%rsi)
test   %edi,%edi
js     1175 <ffd2e+0x35>
lea    0xed0(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <sprintf@plt>
test   %rax,%rax
jns    11a4 <ffd2e+0x64>
jmp    11d9 <ffd2e+0x99>
neg    %edx
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
movsd  %xmm0,(%rsp)
mov    $0x1,%al
call   1060 <sprintf@plt>
test   %rax,%rax
js     11d9 <ffd2e+0x99>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f5 <ffd2e+0xb5>
cmpl   $0x0,(%rbx)
jg     11eb <ffd2e+0xab>
mov    %r14,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11be <ffd2e+0x7e>
movb   $0x2e,(%rax)
mov    %r14,%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     123b <ffd2e+0xfb>
lea    0xe62(%rip),%rdi
jmp    11e0 <ffd2e+0xa0>
lea    0xe25(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%rbx)
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a4 <ffd2e+0x64>
cvttsd2si (%rsp),%edx
lea    0xe1c(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
test   %rax,%rax
jns    11eb <ffd2e+0xab>
lea    0xddc(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%rbx)
mov    $0x192,%eax
jmp    11ed <ffd2e+0xad>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11eb <ffd2e+0xab>
mov    %r14,%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11eb <ffd2e+0xab>
lea    0xe02(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
jmp    11eb <ffd2e+0xab>

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 %97
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*, i8*, i32, ...) @sprintf(i8* %23, 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*, i8*, i32, ...) @sprintf(i8* %41, 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 %97
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*, i8*, i32, ...) @sprintf(i8* %55, 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 %94
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 %93
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 %92, 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 %92, label %89
89: ; preds = %85
%90 = load i8*, i8** %8
%91 = call i32 @strcat(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %92
92: ; preds = %89, %85, %81
br label %93
93: ; preds = %92, %78
br label %94
94: ; preds = %93, %64
%95 = load i32*, i32** %9
%96 = load i32, i32* %95
store i32 %96, i32* %5
br label %97
97: ; preds = %94, %49, %14
%98 = load i32, i32* %5
ret i32 %98
}

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 %56, 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*, i8*, i32, ...) @sprintf(i8* %2, 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 %54
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*, i8*, i32, ...) @sprintf(i8* %2, 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 %56
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 %56
29: ; preds = %7
%30 = tail call i64 (i8*, i8*, i32, ...) @sprintf(i8* %2, 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 %54
34: ; preds = %29, %18, %15
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 1
br i1 %36, label %37, label %54
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 %54
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 %54
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 %54
52: ; preds = %49
%53 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %13, %32, %44, %52, %49, %46, %34
%55 = load i32, i32* %3
br label %56
56: ; preds = %27, %25, %4, %54
%57 = phi i32 [ %55, %54 ], [ %5, %4 ], [ %26, %25 ], [ 402, %27 ]
ret i32 %57
}