#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 int /*<<< orphan*/ buf;

/* Variables and functions */
unsigned long __builtin_alpha_umulh(unsigned long, int);
int print_buf_pad(char *, int, char *, int, int);
int print_decimal(unsigned long val, int width, int pad) {
  char buf[32];
  char *p = buf + sizeof(buf);
  if (val == 0)
    *--p = '0';
  else {
    do {
      unsigned long d, r;
      d = __builtin_alpha_umulh(val, 0xcccccccccccccccd);
      d >>= 3;
      r = val - (d * 10);
      *--p = r + '0';
      val = d;
    } while (val);
  }
  return print_buf_pad(buf, sizeof(buf), p, width, pad);
}


x86 assembly (clang, -O0):
<print_decimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x30(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1161 <print_decimal+0x41>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x30,-0x1(%rax)
jmp    11c8 <print_decimal+0xa8>
jmp    1166 <print_decimal+0x46>
mov    -0x8(%rbp),%rdi
mov    $0xcccccccd,%esi
call   1030 <__builtin_alpha_umulh@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
shr    $0x3,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
imul   $0xa,-0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x30,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1166 <print_decimal+0x46>
jmp    11c8 <print_decimal+0xa8>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    $0x20,%esi
call   1040 <print_buf_pad@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_decimal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
test   %rdi,%rdi
je     1173 <print_decimal+0x53>
mov    %rdi,%rbp
lea    0x20(%rsp),%rbx
nopl   (%rax)
mov    %rbp,%rdi
mov    $0xcccccccd,%esi
call   1030 <__builtin_alpha_umulh@plt>
mov    %rax,%rcx
shr    $0x3,%rcx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ebp
add    $0x30,%bpl
mov    %bpl,-0x1(%rbx)
add    $0xffffffffffffffff,%rbx
mov    %rcx,%rbp
cmp    $0x7,%rax
ja     1140 <print_decimal+0x20>
jmp    117d <print_decimal+0x5d>
lea    0x1f(%rsp),%rbx
movb   $0x30,0x1f(%rsp)
mov    %rsp,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1040 <print_buf_pad@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @print_decimal(i64 %0, i32 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%12 = getelementptr inbounds i8, i8* %11, i64 32
store i8* %12, i8** %8
%13 = load i64, i64* %4
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %8
store i8 48, i8* %17
br label %38
18: ; preds = %3
br label %19
19: ; preds = %34, %18
%20 = load i64, i64* %4
%21 = call i64 @__builtin_alpha_umulh(i64 %20, i32 -858993459)
store i64 %21, i64* %9
%22 = load i64, i64* %9
%23 = lshr i64 %22, 3
store i64 %23, i64* %9
%24 = load i64, i64* %4
%25 = load i64, i64* %9
%26 = mul i64 %25, 10
%27 = sub i64 %24, %26
store i64 %27, i64* %10
%28 = load i64, i64* %10
%29 = add i64 %28, 48
%30 = trunc i64 %29 to i8
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %8
store i8 %30, i8* %32
%33 = load i64, i64* %9
store i64 %33, i64* %4
br label %34
34: ; preds = %19
%35 = load i64, i64* %4
%36 = icmp ne i64 %35, 0
br i1 %36, label %19, label %37
37: ; preds = %34
br label %38
38: ; preds = %37, %15
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%40 = load i8*, i8** %8
%41 = load i32, i32* %5
%42 = load i32, i32* %6
%43 = call i32 @print_buf_pad(i8* %39, i32 32, i8* %40, i32 %41, i32 %42)
ret i32 %43
}

LLVM IR (-O2):
define i32 @print_decimal(i64 %0, i32 %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = icmp eq i64 %0, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 32
br label %11
9: ; preds = %3
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 31
store i8 48, i8* %10
br label %22
11: ; preds = %7, %11
%12 = phi i8* [ %20, %11 ], [ %8, %7 ]
%13 = phi i64 [ %15, %11 ], [ %0, %7 ]
%14 = tail call i64 @__builtin_alpha_umulh(i64 %13, i32 -858993459)
%15 = lshr i64 %14, 3
%16 = mul i64 %15, -10
%17 = add i64 %16, %13
%18 = trunc i64 %17 to i8
%19 = add i8 %18, 48
%20 = getelementptr inbounds i8, i8* %12, i64 -1
store i8 %19, i8* %20
%21 = icmp ult i64 %14, 8
br i1 %21, label %22, label %11
22: ; preds = %11, %9
%23 = phi i8* [ %10, %9 ], [ %20, %11 ]
%24 = call i32 @print_buf_pad(i8* %5, i32 32, i8* %23, i32 %1, i32 %2)
ret i32 %24
}