#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, float);
scalar_t__ strchr(char *, char);
int ffr2f(float fval, int decim, char *cval, int *status) {
  if (*status > 0)
    return (*status);
  cval[0] = '\0';
  if (decim < 0) {
    ffpmsg("Error in ffr2f:  no. of decimal places < 0");
    return (*status = 411);
  }
  if (sprintf(cval, "%.*f", decim, fval) < 0) {
    ffpmsg("Error in ffr2f converting float to string");
    *status = 402;
  }
  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    $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    1163 <ffr2f+0x33>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1205 <ffr2f+0xd5>
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    1205 <ffr2f+0xd5>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
movss  -0x8(%rbp),%xmm0
lea    0xe82(%rip),%rsi
call   1050 <sprintf@plt>
cmp    $0x0,%rax
jge    11ce <ffr2f+0x9e>
lea    0xe71(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x20(%rbp),%rax
movl   $0x192,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11fc <ffr2f+0xcc>
lea    0xe6d(%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    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffr2f>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    (%rdx),%eax
test   %eax,%eax
jle    1145 <ffr2f+0x15>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsi,%rbx
mov    %edi,%edx
movb   $0x0,(%rsi)
test   %edi,%edi
js     11a4 <ffr2f+0x74>
lea    0xed3(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
test   %rax,%rax
jns    1178 <ffr2f+0x48>
lea    0xec4(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%r14)
mov    %rbx,%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c1 <ffr2f+0x91>
lea    0xec9(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%r14)
mov    $0x192,%eax
jmp    113d <ffr2f+0xd>
lea    0xe55(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x19b,(%r14)
mov    $0x19b,%eax
jmp    113d <ffr2f+0xd>
mov    (%r14),%eax
jmp    113d <ffr2f+0xd>

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*
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 %43
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 %24
21: ; preds = %16
%22 = call i32 @ffpmsg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%23 = load i32*, i32** %9
store i32 411, i32* %23
store i32 411, i32* %5
br label %43
24: ; preds = %16
%25 = load i8*, i8** %8
%26 = load i32, i32* %7
%27 = load float, float* %6
%28 = call i64 @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %26, float %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @ffpmsg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32*, i32** %9
store i32 402, i32* %32
br label %33
33: ; preds = %30, %24
%34 = load i8*, i8** %8
%35 = call i64 @strchr(i8* %34, i8 signext 78)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = call i32 @ffpmsg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32*, i32** %9
store i32 402, i32* %39
br label %40
40: ; preds = %37, %33
%41 = load i32*, i32** %9
%42 = load i32, i32* %41
store i32 %42, i32* %5
br label %43
43: ; preds = %40, %21, %13
%44 = load i32, i32* %5
ret i32 %44
}

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 %23, 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 %23
11: ; preds = %7
%12 = tail call i64 @sprintf(i8* %2, 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 i64 @strchr(i8* %2, i8 signext 78)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32, i32* %3
br label %23
21: ; preds = %16
%22 = 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 %23
23: ; preds = %21, %19, %4, %9
%24 = phi i32 [ 411, %9 ], [ %5, %4 ], [ %20, %19 ], [ 402, %21 ]
ret i32 %24
}