#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 *);
scalar_t__ strchr(char *, char);
int ffd2e(double dval, int decim, char *cval, int *status) {
  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 (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    1316 <ffd2e+0x1d6>
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    1316 <ffd2e+0x1d6>
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     130d <ffd2e+0x1cd>
mov    -0x20(%rbp),%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     12c3 <ffd2e+0x183>
lea    0xd8a(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
jmp    1308 <ffd2e+0x1c8>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1303 <ffd2e+0x1c3>
mov    -0x20(%rbp),%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1303 <ffd2e+0x1c3>
mov    -0x20(%rbp),%rdi
lea    0xd6a(%rip),%rsi
call   1050 <strcat@plt>
jmp    1308 <ffd2e+0x1c8>
jmp    130d <ffd2e+0x1cd>
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     11d8 <ffd2e+0x98>
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    11c4 <ffd2e+0x84>
neg    %edx
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
movsd  %xmm0,(%rsp)
mov    $0x1,%al
call   1060 <sprintf@plt>
test   %rax,%rax
js     11c4 <ffd2e+0x84>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11e0 <ffd2e+0xa0>
cmpl   $0x0,(%rbx)
jg     11d6 <ffd2e+0x96>
mov    %r14,%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1226 <ffd2e+0xe6>
lea    0xe77(%rip),%rdi
jmp    11cb <ffd2e+0x8b>
lea    0xe3a(%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    0xe31(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
test   %rax,%rax
jns    11d6 <ffd2e+0x96>
lea    0xdf1(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%rbx)
mov    $0x192,%eax
jmp    11d8 <ffd2e+0x98>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11d6 <ffd2e+0x96>
mov    %r14,%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11d6 <ffd2e+0x96>
lea    0xe17(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
jmp    11d6 <ffd2e+0x96>

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*
store double %0, double* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%10 = load i32*, i32** %9
%11 = load i32, i32* %10
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i32*, i32** %9
%15 = load i32, i32* %14
store i32 %15, i32* %5
br label %90
16: ; preds = %4
%17 = load i8*, i8** %8
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 0, i8* %18
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %16
%22 = load i8*, i8** %8
%23 = load i32, i32* %7
%24 = sub nsw i32 0, %23
%25 = load double, double* %6
%26 = call i64 (i8*, i8*, i32, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24, double %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32*, i32** %9
store i32 402, i32* %30
br label %52
31: ; preds = %21
%32 = load i8*, i8** %8
%33 = call i64 @strchr(i8* %32, i8 signext 46)
%34 = icmp ne i64 %33, 0
br i1 %34, label %51, label %35
35: ; preds = %31
%36 = load i8*, i8** %8
%37 = call i64 @strchr(i8* %36, i8 signext 69)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %35
%40 = load i8*, i8** %8
%41 = load double, double* %6
%42 = fptosi double %41 to i32
%43 = call i64 (i8*, i8*, i32, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%47 = load i32*, i32** %9
store i32 402, i32* %47
br label %48
48: ; preds = %45, %39
%49 = load i32*, i32** %9
%50 = load i32, i32* %49
store i32 %50, i32* %5
br label %90
51: ; preds = %35, %31
br label %52
52: ; preds = %51, %28
br label %63
53: ; preds = %16
%54 = load i8*, i8** %8
%55 = load i32, i32* %7
%56 = load double, double* %6
%57 = call i64 (i8*, i8*, i32, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %55, double %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%61 = load i32*, i32** %9
store i32 402, i32* %61
br label %62
62: ; preds = %59, %53
br label %63
63: ; preds = %62, %52
%64 = load i32*, i32** %9
%65 = load i32, i32* %64
%66 = icmp sle i32 %65, 0
br i1 %66, label %67, label %87
67: ; preds = %63
%68 = load i8*, i8** %8
%69 = call i64 @strchr(i8* %68, i8 signext 78)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = call i32 @ffpmsg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%73 = load i32*, i32** %9
store i32 402, i32* %73
br label %86
74: ; preds = %67
%75 = load i8*, i8** %8
%76 = call i64 @strchr(i8* %75, i8 signext 46)
%77 = icmp ne i64 %76, 0
br i1 %77, label %85, label %78
78: ; preds = %74
%79 = load i8*, i8** %8
%80 = call i64 @strchr(i8* %79, i8 signext 69)
%81 = icmp ne i64 %80, 0
br i1 %81, label %85, label %82
82: ; preds = %78
%83 = load i8*, i8** %8
%84 = call i32 @strcat(i8* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %85
85: ; preds = %82, %78, %74
br label %86
86: ; preds = %85, %71
br label %87
87: ; preds = %86, %63
%88 = load i32*, i32** %9
%89 = load i32, i32* %88
store i32 %89, i32* %5
br label %90
90: ; preds = %87, %48, %13
%91 = load i32, i32* %5
ret i32 %91
}

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 %52, 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 %50
15: ; preds = %9
%16 = tail call i64 @strchr(i8* %2, i8 signext 46)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = tail call i64 @strchr(i8* %2, i8 signext 69)
%20 = icmp eq i64 %19, 0
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 %52
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 %52
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 %50
34: ; preds = %29, %18, %15
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 1
br i1 %36, label %37, label %50
37: ; preds = %34
%38 = tail call i64 @strchr(i8* %2, i8 signext 78)
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = 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 %50
42: ; preds = %37
%43 = tail call i64 @strchr(i8* %2, i8 signext 46)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = tail call i64 @strchr(i8* %2, i8 signext 69)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %13, %32, %40, %48, %45, %42, %34
%51 = load i32, i32* %3
br label %52
52: ; preds = %27, %25, %4, %50
%53 = phi i32 [ %51, %50 ], [ %5, %4 ], [ %26, %25 ], [ 402, %27 ]
ret i32 %53
}