#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*/ sprintf(char *, char *, double);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ xfree(char *);
char *xmalloc(unsigned int);
char *dofmt(char *fmtstr, double v) {
  char buff[1024];
  char *p;
  if (!fmtstr)
    return (0);
  (void)sprintf(buff, fmtstr, v);
  p = xmalloc((unsigned)(strlen(buff) + 1));
  (void)strcpy(p, buff);
  xfree(fmtstr);
  return (p);
}


x86 assembly (clang, -O0):
<dofmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117c <dofmt+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11d6 <dofmt+0x86>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
call   1070 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %eax,%edi
call   1060 <xmalloc@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <xfree@plt>
mov    -0x428(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dofmt>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
test   %rdi,%rdi
je     119a <dofmt+0x4a>
mov    %rdi,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <xfree@plt>
jmp    119c <dofmt+0x4c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @dofmt(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
%6 = alloca [1024 x i8]
%7 = alloca i8*
store i8* %0, i8** %4
store double %1, double* %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %2
store i8* null, i8** %3
br label %27
11: ; preds = %2
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = load double, double* %5
%15 = call i32 @sprintf(i8* %12, i8* %13, double %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i8* @xmalloc(i32 %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %4
%25 = call i32 @xfree(i8* %24)
%26 = load i8*, i8** %7
store i8* %26, i8** %3
br label %27
27: ; preds = %11, %10
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
define i8* @dofmt(i8* %0, double %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = call i32 @sprintf(i8* %4, i8* %0, double %1)
%8 = call i64 @strlen(i8* %4)
%9 = trunc i64 %8 to i32
%10 = add i32 %9, 1
%11 = tail call i8* @xmalloc(i32 %10)
%12 = call i32 @strcpy(i8* %11, i8* %4)
%13 = call i32 @xfree(i8* %0)
br label %14
14: ; preds = %2, %6
%15 = phi i8* [ %11, %6 ], [ null, %2 ]
ret i8* %15
}