#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 count_chars(float, char *);
int /*<<< orphan*/ sprintf(char *, char *, double, ...);
int LeftJust_dbl(char *fmt_str, double from_dbl, char *to_str) {
  char fmt[20];
  int num_of_f1, num_of_f2;
  num_of_f1 = count_chars('f', fmt_str);
  fmt_str += num_of_f1;
  fmt_str++;
  num_of_f2 = count_chars('f', fmt_str);
  num_of_f1 += num_of_f2;
  num_of_f1++;
  sprintf(fmt, "%c-%d.%dlf", '%', num_of_f1, num_of_f2);
  sprintf(to_str, fmt, from_dbl);
  return num_of_f1;
}


x86 assembly (clang, -O0):
<LeftJust_dbl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movss  0xec7(%rip),%xmm0
call   1030 <count_chars@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
movss  0xe96(%rip),%xmm0
call   1030 <count_chars@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xe6f(%rip),%rsi
movsd  0xe5b(%rip),%xmm0
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
movsd  -0x10(%rbp),%xmm0
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LeftJust_dbl>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
movss  0xec3(%rip),%xmm0
call   1030 <count_chars@plt>
movslq %eax,%r15
lea    (%rbx,%r15,1),%rdi
add    $0x1,%rdi
movss  0xeab(%rip),%xmm0
call   1030 <count_chars@plt>
lea    (%r15,%rax,1),%ebx
add    $0x1,%ebx
lea    0xea8(%rip),%rsi
lea    0x10(%rsp),%r15
movsd  0xe93(%rip),%xmm0
mov    %r15,%rdi
mov    %ebx,%edx
mov    %eax,%ecx
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <sprintf@plt>
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%c-%d.%dlf\00"
define i32 @LeftJust_dbl(i8* %0, double %1, i8* %2) {
%4 = alloca i8*
%5 = alloca double
%6 = alloca i8*
%7 = alloca [20 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store double %1, double* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i32 @count_chars(float 1.020000e+02, i8* %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = load i8*, i8** %4
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %13, i64 %14
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @count_chars(float 1.020000e+02, i8* %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = add nsw i32 %21, %20
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
store i32 %24, i32* %8
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double 3.700000e+01, i32 %26, i32 %27)
%29 = load i8*, i8** %6
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%31 = load double, double* %5
%32 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %29, i8* %30, double %31)
%33 = load i32, i32* %8
ret i32 %33
}

LLVM IR (-O2):
@.str = [11 x i8] c"%c-%d.%dlf\00"
define i32 @LeftJust_dbl(i8* %0, double %1, i8* nocapture writeonly %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @count_chars(float 1.020000e+02, i8* %0)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = tail call i32 @count_chars(float 1.020000e+02, i8* %9)
%11 = add i32 %6, 1
%12 = add i32 %11, %10
%13 = call i32 (i8*, i8*, double, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double 3.700000e+01, i32 %12, i32 %10)
%14 = call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %2, i8* %5, double %1)
ret i32 %12
}