#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 size_t uint8_t;
typedef int uint16_t;

/* Variables and functions */
void float_4dp(uint16_t num, char *str) {
  uint16_t d;
  uint8_t i;
  uint16_t const powers[] = {1000, 100, 10, 1, 0};
  for (i = 0; (d = powers[i]); i++) {
    uint8_t q;
    q = num / d;
    *str++ = '0' + q;
    num -= q * d;
  }
  *str = '\0';
}


x86 assembly (clang, -O0):
<float_4dp>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeee(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeeb(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xee9(%rip),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1195 <float_4dp+0x95>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cltq
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x30,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x48(%rbp),%rcx
movslq -0x14(%rbp),%rax
imul   %rax,%rcx
movslq -0x4(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1132 <float_4dp+0x32>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_4dp>:
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
lea    0x30(%rcx),%edx
mov    %dl,(%rsi)
imul   $0xfffffc18,%ecx,%ecx
add    %ecx,%eax
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
lea    0x30(%rcx),%edx
mov    %dl,0x1(%rsi)
imul   $0xffffff9c,%ecx,%ecx
add    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
lea    0x30(%rcx),%edx
mov    %dl,0x2(%rsi)
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x30,%al
mov    %al,0x3(%rsi)
movb   $0x0,0x4(%rsi)
ret

LLVM IR (-O0):
@__const.float_4dp.powers = [5 x i32] [i32 1000, i32 100, i32 10, i32 1, i32 0]
define void @float_4dp(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca [5 x i32]
%8 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = bitcast [5 x i32]* %7 to i8*
store i64 0, i64* %6
br label %10
10: ; preds = %33, %2
%11 = load i64, i64* %6
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 %11
%13 = load i32, i32* %12
store i32 %13, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %10
%16 = load i32, i32* %3
%17 = load i32, i32* %5
%18 = sdiv i32 %16, %17
%19 = sext i32 %18 to i64
store i64 %19, i64* %8
%20 = load i64, i64* %8
%21 = add i64 48, %20
%22 = trunc i64 %21 to i8
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i8 %22, i8* %23
%25 = load i64, i64* %8
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = mul i64 %25, %27
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = sub i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %3
br label %33
33: ; preds = %15
%34 = load i64, i64* %6
%35 = add i64 %34, 1
store i64 %35, i64* %6
br label %10
36: ; preds = %10
%37 = load i8*, i8** %4
store i8 0, i8* %37
ret void
}

LLVM IR (-O2):
define void @float_4dp(i32 %0, i8* nocapture writeonly %1) {
%3 = sdiv i32 %0, 1000
%4 = trunc i32 %3 to i8
%5 = add i8 %4, 48
%6 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %5, i8* %1
%7 = mul nsw i32 %3, -1000
%8 = add i32 %7, %0
%9 = sdiv i32 %8, 100
%10 = trunc i32 %9 to i8
%11 = add i8 %10, 48
%12 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %11, i8* %6
%13 = mul nsw i32 %9, -100
%14 = add i32 %13, %8
%15 = sdiv i32 %14, 10
%16 = trunc i32 %15 to i8
%17 = add i8 %16, 48
%18 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %17, i8* %12
%19 = mul nsw i32 %15, -10
%20 = add i32 %19, %14
%21 = trunc i32 %20 to i8
%22 = add i8 %21, 48
%23 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %22, i8* %18
store i8 0, i8* %23
ret void
}