#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 */
char *put_dec_full(char *, unsigned int);
char *put_dec_trunc(char *, unsigned long);
__attribute__((no)) char *put_dec(char *buf, unsigned long num) {
  while (1) {
    unsigned rem;
    if (num < 100000)
      return put_dec_trunc(buf, num);
    rem = num % 100000;
    num /= 100000;
    buf = put_dec_full(buf, rem);
  }
}


x86 assembly (clang, -O0):
<put_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x186a0,-0x10(%rbp)
jae    1151 <put_dec+0x31>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <put_dec_trunc@plt>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    $0x186a0,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x186a0,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <put_dec_full@plt>
mov    %rax,-0x8(%rbp)
jmp    1130 <put_dec+0x10>

x86 assembly (clang, -O2):
<put_dec>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x186a0,%rsi
jae    1136 <put_dec+0x16>
mov    %r14,%rbx
jmp    1174 <put_dec+0x54>
movabs $0xa7c5ac471b47843,%r15
5a 7c 0a
mov    %r14,%rax
shr    $0x5,%rax
mul    %r15
mov    %rdx,%rbx
shr    $0x7,%rbx
imul   $0x186a0,%ebx,%eax
mov    %r14d,%esi
sub    %eax,%esi
call   1030 <put_dec_full@plt>
mov    %rax,%rdi
shr    $0xa,%r14
cmp    $0x9502f8,%r14
mov    %rbx,%r14
ja     1140 <put_dec+0x20>
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <put_dec_trunc@plt>

LLVM IR (-O0):
define i8* @put_dec(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
br label %6
6: ; preds = %2, %13
%7 = load i64, i64* %4
%8 = icmp ult i64 %7, 100000
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = call i8* @put_dec_trunc(i8* %10, i64 %11)
ret i8* %12
13: ; preds = %6
%14 = load i64, i64* %4
%15 = urem i64 %14, 100000
%16 = trunc i64 %15 to i32
store i32 %16, i32* %5
%17 = load i64, i64* %4
%18 = udiv i64 %17, 100000
store i64 %18, i64* %4
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = call i8* @put_dec_full(i8* %19, i32 %20)
store i8* %21, i8** %3
br label %6
}

LLVM IR (-O2):
define i8* @put_dec(i8* %0, i64 %1) {
%3 = icmp ult i64 %1, 100000
br i1 %3, label %12, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %9, %4 ], [ %1, %2 ]
%6 = phi i8* [ %10, %4 ], [ %0, %2 ]
%7 = urem i64 %5, 100000
%8 = trunc i64 %7 to i32
%9 = udiv i64 %5, 100000
%10 = tail call i8* @put_dec_full(i8* %6, i32 %8)
%11 = icmp ult i64 %5, 10000000000
br i1 %11, label %12, label %4
12: ; preds = %4, %2
%13 = phi i8* [ %0, %2 ], [ %10, %4 ]
%14 = phi i64 [ %1, %2 ], [ %9, %4 ]
%15 = tail call i8* @put_dec_trunc(i8* %13, i64 %14)
ret i8* %15
}