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


x86 assembly (clang, -O0):
<ffr2e>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    1173 <ffr2e+0x33>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1341 <ffr2e+0x201>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0xc(%rbp)
jge    1248 <ffr2e+0x108>
mov    -0x18(%rbp),%rdi
xor    %edx,%edx
sub    -0xc(%rbp),%edx
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe63(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
cmp    $0x0,%rax
jge    11c9 <ffr2e+0x89>
lea    0xe50(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x192,(%rax)
jmp    1243 <ffr2e+0x103>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    123e <ffr2e+0xfe>
mov    -0x18(%rbp),%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     123e <ffr2e+0xfe>
mov    -0x18(%rbp),%rdi
cvttss2si -0x8(%rbp),%edx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
cmp    $0x0,%rax
jge    1230 <ffr2e+0xf0>
lea    0xde4(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x192,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1341 <ffr2e+0x201>
jmp    1243 <ffr2e+0x103>
jmp    128b <ffr2e+0x14b>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd5(%rip),%rsi
mov    $0x1,%al
call   1060 <sprintf@plt>
cmp    $0x0,%rax
jge    1286 <ffr2e+0x146>
lea    0xd8e(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x192,(%rax)
jmp    128b <ffr2e+0x14b>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1338 <ffr2e+0x1f8>
mov    -0x18(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12bb <ffr2e+0x17b>
mov    -0x28(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     12ee <ffr2e+0x1ae>
lea    0xd5f(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x192,(%rax)
jmp    1333 <ffr2e+0x1f3>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    132e <ffr2e+0x1ee>
mov    -0x18(%rbp),%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    132e <ffr2e+0x1ee>
mov    -0x18(%rbp),%rdi
lea    0xd3e(%rip),%rsi
call   1050 <strcat@plt>
jmp    1333 <ffr2e+0x1f3>
jmp    1338 <ffr2e+0x1f8>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffr2e>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    (%rdx),%eax
test   %eax,%eax
jg     11f6 <ffr2e+0xb6>
mov    %rsi,%r14
mov    %edi,%edx
movb   $0x0,(%rsi)
test   %edi,%edi
js     1179 <ffr2e+0x39>
cvtss2sd %xmm0,%xmm0
lea    0xecc(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <sprintf@plt>
test   %rax,%rax
jns    11ad <ffr2e+0x6d>
jmp    11e2 <ffr2e+0xa2>
neg    %edx
movss  %xmm0,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
lea    0xe74(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <sprintf@plt>
test   %rax,%rax
js     11e2 <ffr2e+0xa2>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11fe <ffr2e+0xbe>
cmpl   $0x0,(%rbx)
jg     11f4 <ffr2e+0xb4>
mov    %r14,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c7 <ffr2e+0x87>
movb   $0x2e,(%rax)
mov    %r14,%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1245 <ffr2e+0x105>
lea    0xe59(%rip),%rdi
jmp    11e9 <ffr2e+0xa9>
lea    0xe1c(%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     11ad <ffr2e+0x6d>
cvttss2si 0x4(%rsp),%edx
lea    0xe12(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
test   %rax,%rax
jns    11f4 <ffr2e+0xb4>
lea    0xdd2(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%rbx)
mov    $0x192,%eax
jmp    11f6 <ffr2e+0xb6>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11f4 <ffr2e+0xb4>
mov    %r14,%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11f4 <ffr2e+0xb4>
lea    0xdf7(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
jmp    11f4 <ffr2e+0xb4>

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

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