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


x86 assembly (clang, -O0):
<ffd2f>:
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    1163 <ffd2f+0x33>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122d <ffd2f+0xfd>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x14(%rbp)
jge    1196 <ffd2f+0x66>
lea    0xe85(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x19b,(%rax)
movl   $0x19b,-0x4(%rbp)
jmp    122d <ffd2f+0xfd>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%ecx
movsd  -0x10(%rbp),%xmm0
mov    $0x47,%esi
lea    0xe7d(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x0,%rax
jge    11d3 <ffd2f+0xa3>
lea    0xe6c(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11f6 <ffd2f+0xc6>
mov    -0x30(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1224 <ffd2f+0xf4>
lea    0xe46(%rip),%rdi
call   1030 <ffpmsg@plt>
mov    -0x28(%rbp),%rax
movl   $0x192,(%rax)
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):
<ffd2f>:
push   %r14
push   %rbx
push   %rax
mov    (%rdx),%eax
test   %eax,%eax
jle    1142 <ffd2f+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 <ffd2f+0x91>
lea    0xed3(%rip),%rdx
mov    %rbx,%rdi
mov    $0x47,%esi
call   1050 <snprintf@plt>
test   %rax,%rax
jns    117d <ffd2f+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 <ffd2f+0x62>
movb   $0x2e,(%rax)
mov    %rbx,%rdi
mov    $0x4e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11de <ffd2f+0xae>
lea    0xeb0(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x192,(%r14)
mov    $0x192,%eax
jmp    113a <ffd2f+0xa>
lea    0xe38(%rip),%rdi
call   1030 <ffpmsg@plt>
movl   $0x19b,(%r14)
mov    $0x19b,%eax
jmp    113a <ffd2f+0xa>
mov    (%r14),%eax
jmp    113a <ffd2f+0xa>

LLVM IR (-O0):
@.str = [43 x i8] c"Error in ffd2f: no. of decimal places < 0\00"
@.str.1 = [5 x i8] c"%.*f\00"
@.str.2 = [43 x i8] c"Error in ffd2f converting double to string\00"
@.str.3 = [47 x i8] c"Error in ffd2f: double value is a NaN or INDEF\00"
define i32 @ffd2f(double %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
store double %0, double* %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 double, double* %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, double %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = call i32 @ffpmsg(i8* getelementptr inbounds ([43 x i8], [43 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 ([47 x i8], [47 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 ffd2f: no. of decimal places < 0\00"
@.str.1 = [5 x i8] c"%.*f\00"
@.str.2 = [43 x i8] c"Error in ffd2f converting double to string\00"
@.str.3 = [47 x i8] c"Error in ffd2f: double value is a NaN or INDEF\00"
define i32 @ffd2f(double %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, double %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 ([43 x i8], [43 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 ([47 x i8], [47 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
}