#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, float);
char *strchr(char *, char);
int ffr2f(float fval, int decim, char *cval, int *status) {
  char *cptr;
  if (*status > 0)
    return (*status);
  cval[0] = '\0';
  if (decim < 0) {
    ffpmsg("Error in ffr2f:  no. of decimal places < 0");
    return (*status = 411);
  }
  if (snprintf(cval, 71, "%.*f", decim, fval) < 0) {
    ffpmsg("Error in ffr2f converting float to string");
    *status = 402;
  }
  if ((cptr = strchr(cval, ',')))
    *cptr = '.';
  if (strchr(cval, 'N')) {
    ffpmsg("Error in ffr2f: float value is a NaN or INDEF");
    *status = 402;
  }
  return (*status);
}


x86 assembly (clang, -O0):
<ffr2f>:
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    1163 <ffr2f+0x33>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122d <ffr2f+0xfd>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0xc(%rbp)
jge    1196 <ffr2f+0x66>
lea    0xe85(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x19b,(%rax)
movl   $0x19b,-0x4(%rbp)
jmp    122d <ffr2f+0xfd>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%ecx
movss  -0x8(%rbp),%xmm0
mov    $0x47,%esi
lea    0xe7d(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x0,%rax
jge    11d3 <ffr2f+0xa3>
lea    0xe6c(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x192,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11f6 <ffr2f+0xc6>
mov    -0x28(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1224 <ffr2f+0xf4>
lea    0xe45(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x192,(%rax)
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):
<ffr2f>:
push   %r14
push   %rbx
push   %rax
mov    (%rdx),%eax
test   %eax,%eax
jle    1142 <ffr2f+0x12>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ecx
movb   $0x0,(%rsi)
test   %edi,%edi
js     11c1 <ffr2f+0x91>
lea    0xed3(%rip),%rdx
mov    %rbx,%rdi
mov    $0x47,%esi
call   1050 <snprintf@plt>
test   %rax,%rax
jns    117d <ffr2f+0x4d>
lea    0xebf(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%r14)
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1192 <ffr2f+0x62>
movb   $0x2e,(%rax)
mov    %rbx,%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11de <ffr2f+0xae>
lea    0xeaf(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%r14)
mov    $0x192,%eax
jmp    113a <ffr2f+0xa>
lea    0xe38(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x19b,(%r14)
mov    $0x19b,%eax
jmp    113a <ffr2f+0xa>
mov    (%r14),%eax
jmp    113a <ffr2f+0xa>

LLVM IR (-O0):
@.str = [43 x i8] c"Error in ffr2f: no. of decimal places < 0\00"
@.str.1 = [5 x i8] c"%.*f\00"
@.str.2 = [42 x i8] c"Error in ffr2f converting float to string\00"
@.str.3 = [46 x i8] c"Error in ffr2f: float value is a NaN or INDEF\00"
define i32 @ffr2f(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 %50
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 %25
22: ; preds = %17
%23 = call i32 @ffpmsg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%24 = load i32*, i32** %9
store i32 411, i32* %24
store i32 411, i32* %5
br label %50
25: ; preds = %17
%26 = load i8*, i8** %8
%27 = load i32, i32* %7
%28 = load float, float* %6
%29 = call i64 @snprintf(i8* %26, i32 71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %27, float %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32*, i32** %9
store i32 402, i32* %33
br label %34
34: ; preds = %31, %25
%35 = load i8*, i8** %8
%36 = call i8* @strchr(i8* %35, i8 signext 44)
store i8* %36, i8** %10
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = load i8*, i8** %10
store i8 46, i8* %39
br label %40
40: ; preds = %38, %34
%41 = load i8*, i8** %8
%42 = call i8* @strchr(i8* %41, i8 signext 78)
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = call i32 @ffpmsg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32*, i32** %9
store i32 402, i32* %46
br label %47
47: ; preds = %44, %40
%48 = load i32*, i32** %9
%49 = load i32, i32* %48
store i32 %49, i32* %5
br label %50
50: ; preds = %47, %22, %14
%51 = load i32, i32* %5
ret i32 %51
}

LLVM IR (-O2):
@.str = [43 x i8] c"Error in ffr2f: no. of decimal places < 0\00"
@.str.1 = [5 x i8] c"%.*f\00"
@.str.2 = [42 x i8] c"Error in ffr2f converting float to string\00"
@.str.3 = [46 x i8] c"Error in ffr2f: float value is a NaN or INDEF\00"
define i32 @ffr2f(float %0, i32 %1, i8* %2, i32* nocapture %3) {
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %4
store i8 0, i8* %2
%8 = icmp slt i32 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 411, i32* %3
br label %27
11: ; preds = %7
%12 = tail call i64 @snprintf(i8* %2, i32 71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %1, float %0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
store i32 402, i32* %3
br label %16
16: ; preds = %14, %11
%17 = tail call i8* @strchr(i8* %2, i8 signext 44)
%18 = icmp eq i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %16
store i8 46, i8* %17
br label %20
20: ; preds = %19, %16
%21 = tail call i8* @strchr(i8* %2, i8 signext 78)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32, i32* %3
br label %27
25: ; preds = %20
%26 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
store i32 402, i32* %3
br label %27
27: ; preds = %25, %23, %4, %9
%28 = phi i32 [ 411, %9 ], [ %5, %4 ], [ %24, %23 ], [ 402, %25 ]
ret i32 %28
}