void less_div(char *num, int num_len, int div_len) {
  printf("0.");
  if (div_len - num_len > 1)
    printf("%0*d", div_len - num_len - 1, 0);
  while (num[num_len - 1] == '0')
    num_len--;
  printf("%.*s\n", num_len, num);
}


x86 assembly (clang, -O0):
<less_div>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x1,%eax
jle    1158 <less_div+0x48>
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
sub    $0x1,%esi
lea    0xeb4(%rip),%rdi
xor    %edx,%edx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115d <less_div+0x4d>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    1185 <less_div+0x75>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <less_div+0x4d>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<less_div>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xede(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
sub    %ebp,%ebx
cmp    $0x2,%ebx
jl     1145 <less_div+0x35>
add    $0xffffffff,%ebx
lea    0xec9(%rip),%rdi
mov    %ebx,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
movslq %ebp,%rax
add    $0x1,%ebp
add    %r14,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%ebp
cmpb   $0x30,(%rax)
lea    -0x1(%rax),%rax
je     1160 <less_div+0x50>
lea    0xe95(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0.\00"
@.str.1 = [5 x i8] c"%0*d\00"
@.str.2 = [6 x i8] c"%.*s\0A\00"
define void @less_div(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %6
%9 = load i32, i32* %5
%10 = sub nsw i32 %8, %9
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %13, %14
%16 = sub nsw i32 %15, 1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 0)
br label %18
18: ; preds = %12, %3
br label %19
19: ; preds = %28, %18
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 48
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = load i32, i32* %5
%30 = add nsw i32 %29, -1
store i32 %30, i32* %5
br label %19
31: ; preds = %19
%32 = load i32, i32* %5
%33 = load i8*, i8** %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %32, i8* %33)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"0.\00"
@.str.1 = [5 x i8] c"%0*d\00"
@.str.2 = [6 x i8] c"%.*s\0A\00"
define void @less_div(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = sub nsw i32 %2, %1
%6 = icmp sgt i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = add nsw i32 %5, -1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 0)
br label %10
10: ; preds = %7, %3
%11 = sext i32 %1 to i64
br label %12
12: ; preds = %12, %10
%13 = phi i64 [ %14, %12 ], [ %11, %10 ]
%14 = add i64 %13, -1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 48
br i1 %17, label %12, label %18
18: ; preds = %12
%19 = trunc i64 %13 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %0)
ret void
}