#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 */
scalar_t__ malloc(int);
int snprintf(char *, int, char *, double);
int /*<<< orphan*/ strncpy(char *, char *, int);
int lwm2m_float64ToPlainText(double data, char **bufferP) {
  char string[64];
  int len;
  len = snprintf(string, 64, "%lf", data);
  if (len > 0) {
    *bufferP = (char *)malloc(len);
    if (NULL != *bufferP) {
      strncpy(*bufferP, string, len);
    } else {
      len = 0;
    }
  }
  return len;
}


x86 assembly (clang, -O0):
<lwm2m_float64ToPlainText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
mov    $0x40,%esi
lea    0xeaa(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jle    11ad <lwm2m_float64ToPlainText+0x7d>
mov    -0x54(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
je     11a1 <lwm2m_float64ToPlainText+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1030 <strncpy@plt>
jmp    11a8 <lwm2m_float64ToPlainText+0x78>
movl   $0x0,-0x54(%rbp)
jmp    11ad <lwm2m_float64ToPlainText+0x7d>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lwm2m_float64ToPlainText>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%r14
lea    0xebf(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
call   1040 <snprintf@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1174 <lwm2m_float64ToPlainText+0x44>
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1172 <lwm2m_float64ToPlainText+0x42>
mov    %rsp,%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
jmp    1174 <lwm2m_float64ToPlainText+0x44>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
define i32 @lwm2m_float64ToPlainText(double %0, i8** %1) {
%3 = alloca double
%4 = alloca i8**
%5 = alloca [64 x i8]
%6 = alloca i32
store double %0, double* %3
store i8** %1, i8*** %4
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = load double, double* %3
%9 = call i32 @snprintf(i8* %7, i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %2
%13 = load i32, i32* %6
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = load i8**, i8*** %4
store i8* %15, i8** %16
%17 = load i8**, i8*** %4
%18 = load i8*, i8** %17
%19 = icmp ne i8* null, %18
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load i8**, i8*** %4
%22 = load i8*, i8** %21
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%24 = load i32, i32* %6
%25 = call i32 @strncpy(i8* %22, i8* %23, i32 %24)
br label %27
26: ; preds = %12
store i32 0, i32* %6
br label %27
27: ; preds = %26, %20
br label %28
28: ; preds = %27, %2
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
define i32 @lwm2m_float64ToPlainText(double %0, i8** nocapture writeonly %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = call i64 @malloc(i32 %5)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %1
%10 = icmp eq i64 %8, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @strncpy(i8* %9, i8* %4, i32 %5)
br label %13
13: ; preds = %7, %11, %2
%14 = phi i32 [ %5, %11 ], [ %5, %2 ], [ 0, %7 ]
ret i32 %14
}