#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 ffr2e(float fval, int decim, char *cval, int *status) {
  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 (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    $0x20,%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    131e <ffr2e+0x1de>
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    131e <ffr2e+0x1de>
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     1315 <ffr2e+0x1d5>
mov    -0x18(%rbp),%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     12cb <ffr2e+0x18b>
lea    0xd82(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x192,(%rax)
jmp    1310 <ffr2e+0x1d0>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    130b <ffr2e+0x1cb>
mov    -0x18(%rbp),%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    130b <ffr2e+0x1cb>
mov    -0x18(%rbp),%rdi
lea    0xd61(%rip),%rsi
call   1050 <strcat@plt>
jmp    1310 <ffr2e+0x1d0>
jmp    1315 <ffr2e+0x1d5>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%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     11e1 <ffr2e+0xa1>
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    11cd <ffr2e+0x8d>
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     11cd <ffr2e+0x8d>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11e9 <ffr2e+0xa9>
cmpl   $0x0,(%rbx)
jg     11df <ffr2e+0x9f>
mov    %r14,%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1230 <ffr2e+0xf0>
lea    0xe6e(%rip),%rdi
jmp    11d4 <ffr2e+0x94>
lea    0xe31(%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    0xe27(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
test   %rax,%rax
jns    11df <ffr2e+0x9f>
lea    0xde7(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%rbx)
mov    $0x192,%eax
jmp    11e1 <ffr2e+0xa1>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11df <ffr2e+0x9f>
mov    %r14,%rdi
mov    $0x45,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11df <ffr2e+0x9f>
lea    0xe0c(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
jmp    11df <ffr2e+0x9f>

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

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