#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*/ myputc(unsigned long);
void print_num(unsigned long num) {
  unsigned long digit, offset;
  for (offset = 1000; offset; offset /= 10) {
    digit = num / offset;
    myputc(digit + '0');
    num -= digit * offset;
  }
}


x86 assembly (clang, -O0):
<print_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x3e8,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1177 <print_num+0x67>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x30,%rdi
call   1030 <myputc@plt>
mov    -0x10(%rbp),%rcx
imul   -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x18(%rbp)
jmp    1124 <print_num+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_num>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    %rdi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
mov    %rdx,%rbx
shr    $0x4,%rbx
lea    0x30(%rbx),%rdi
call   1030 <myputc@plt>
imul   $0xfffffffffffffc18,%rbx,%r15
add    %r14,%r15
mov    %r15,%rax
shr    $0x2,%rax
movabs $0x28f5c28f5c28f5c3,%rcx
c2 f5 28
mul    %rcx
mov    %rdx,%rbx
shr    $0x2,%rbx
lea    0x30(%rbx),%rdi
call   1030 <myputc@plt>
imul   $0xffffffffffffff9c,%rbx,%r14
add    %r15,%r14
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mov    %r14,%rax
mul    %rcx
mov    %rdx,%rbx
shr    $0x3,%rbx
lea    0x30(%rbx),%rdi
call   1030 <myputc@plt>
add    %rbx,%rbx
lea    (%rbx,%rbx,4),%rax
sub    %rax,%r14
add    $0x30,%r14
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <myputc@plt>

LLVM IR (-O0):
define void @print_num(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 1000, i64* %4
br label %5
5: ; preds = %20, %1
%6 = load i64, i64* %4
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %5
%9 = load i64, i64* %2
%10 = load i64, i64* %4
%11 = udiv i64 %9, %10
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = add i64 %12, 48
%14 = call i32 @myputc(i64 %13)
%15 = load i64, i64* %3
%16 = load i64, i64* %4
%17 = mul i64 %15, %16
%18 = load i64, i64* %2
%19 = sub i64 %18, %17
store i64 %19, i64* %2
br label %20
20: ; preds = %8
%21 = load i64, i64* %4
%22 = udiv i64 %21, 10
store i64 %22, i64* %4
br label %5
23: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @print_num(i64 %0) {
%2 = udiv i64 %0, 1000
%3 = add nuw nsw i64 %2, 48
%4 = tail call i32 @myputc(i64 %3)
%5 = mul i64 %2, -1000
%6 = add i64 %5, %0
%7 = udiv i64 %6, 100
%8 = add nuw nsw i64 %7, 48
%9 = tail call i32 @myputc(i64 %8)
%10 = mul i64 %7, -100
%11 = add i64 %10, %6
%12 = udiv i64 %11, 10
%13 = add nuw nsw i64 %12, 48
%14 = tail call i32 @myputc(i64 %13)
%15 = mul i64 %12, -10
%16 = add i64 %15, %11
%17 = add i64 %16, 48
%18 = tail call i32 @myputc(i64 %17)
ret void
}