#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 */
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
scalar_t__ malloc(int);
int snprintf(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int lwm2m_int64ToPlainText(int64_t data, char **bufferP) {
  char string[32];
  int len;
  len = snprintf(string, 32, "%ld", 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_int64ToPlainText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x20,%esi
lea    0xeae(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    11a9 <lwm2m_int64ToPlainText+0x79>
mov    -0x34(%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     119d <lwm2m_int64ToPlainText+0x6d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <strncpy@plt>
jmp    11a4 <lwm2m_int64ToPlainText+0x74>
movl   $0x0,-0x34(%rbp)
jmp    11a9 <lwm2m_int64ToPlainText+0x79>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lwm2m_int64ToPlainText>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %edi,%ecx
lea    0xebd(%rip),%rdx
mov    %rsp,%rdi
mov    $0x20,%esi
call   1040 <snprintf@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1176 <lwm2m_int64ToPlainText+0x46>
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1174 <lwm2m_int64ToPlainText+0x44>
mov    %rsp,%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
jmp    1176 <lwm2m_int64ToPlainText+0x46>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define i32 @lwm2m_int64ToPlainText(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [32 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @snprintf(i8* %7, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %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 [32 x i8], [32 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"%ld\00"
define i32 @lwm2m_int64ToPlainText(i32 %0, i8** nocapture writeonly %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %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
}