#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 */
struct printing_state {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ print_buff_add(struct printing_state *, char);
void print_unsigned_decimal(struct printing_state *ps, unsigned int d) {
  unsigned int leading_zero = 1;
  unsigned int base = 1000000000;
  unsigned int digit = 0;
  unsigned int unsigned_d = d;
  if (d == 0) {
    print_buff_add(ps, '0');
  }
  while (base) {
    digit = unsigned_d / base;
    if (digit) {
      print_buff_add(ps, (char)('0' + (int)digit));
      leading_zero = 0;
    } else {
      if (!leading_zero) {
        print_buff_add(ps, (char)('0' + (int)digit));
      }
    }
    unsigned_d = unsigned_d - (base * digit);
    base /= 10;
  }
}


x86 assembly (clang, -O0):
<print_unsigned_decimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x3b9aca00,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1152 <print_unsigned_decimal+0x42>
mov    -0x8(%rbp),%rdi
mov    $0x30,%esi
call   1030 <print_buff_add@plt>
jmp    1157 <print_unsigned_decimal+0x47>
cmpl   $0x0,-0x14(%rbp)
je     11d8 <print_unsigned_decimal+0xc8>
mov    -0x1c(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1194 <print_unsigned_decimal+0x84>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    $0x30,%eax
movsbl %al,%esi
call   1030 <print_buff_add@plt>
movl   $0x0,-0x10(%rbp)
jmp    11b5 <print_unsigned_decimal+0xa5>
cmpl   $0x0,-0x10(%rbp)
jne    11b0 <print_unsigned_decimal+0xa0>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    $0x30,%eax
movsbl %al,%esi
call   1030 <print_buff_add@plt>
jmp    11b5 <print_unsigned_decimal+0xa5>
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x14(%rbp)
jmp    1157 <print_unsigned_decimal+0x47>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_unsigned_decimal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
test   %esi,%esi
jne    112e <print_unsigned_decimal+0x1e>
mov    %r14,%rdi
mov    $0x30,%esi
call   1030 <print_buff_add@plt>
mov    $0x1,%ecx
mov    $0x3b9aca00,%ebx
mov    $0xcccccccd,%r12d
jmp    1163 <print_unsigned_decimal+0x53>
add    $0x30,%al
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <print_buff_add@plt>
xor    %ecx,%ecx
mov    %ebx,%eax
imul   %r12,%rax
shr    $0x23,%rax
mov    %r15d,%ebp
cmp    $0x9,%ebx
mov    %eax,%ebx
jbe    117d <print_unsigned_decimal+0x6d>
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
mov    %edx,%r15d
cmp    %ebp,%ebx
jbe    1140 <print_unsigned_decimal+0x30>
test   %ecx,%ecx
mov    $0x1,%ecx
jne    114f <print_unsigned_decimal+0x3f>
mov    $0x30,%al
jmp    1142 <print_unsigned_decimal+0x32>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.printing_state = type { i32 }
define void @print_unsigned_decimal(%struct.printing_state* %0, i32 %1) {
%3 = alloca %struct.printing_state*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.printing_state* %0, %struct.printing_state** %3
store i32 %1, i32* %4
store i32 1, i32* %5
store i32 1000000000, i32* %6
store i32 0, i32* %7
%9 = load i32, i32* %4
store i32 %9, i32* %8
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load %struct.printing_state*, %struct.printing_state** %3
%14 = call i32 @print_buff_add(%struct.printing_state* %13, i8 signext 48)
br label %15
15: ; preds = %12, %2
br label %16
16: ; preds = %41, %15
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %49
19: ; preds = %16
%20 = load i32, i32* %8
%21 = load i32, i32* %6
%22 = udiv i32 %20, %21
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load %struct.printing_state*, %struct.printing_state** %3
%27 = load i32, i32* %7
%28 = add nsw i32 48, %27
%29 = trunc i32 %28 to i8
%30 = call i32 @print_buff_add(%struct.printing_state* %26, i8 signext %29)
store i32 0, i32* %5
br label %41
31: ; preds = %19
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %31
%35 = load %struct.printing_state*, %struct.printing_state** %3
%36 = load i32, i32* %7
%37 = add nsw i32 48, %36
%38 = trunc i32 %37 to i8
%39 = call i32 @print_buff_add(%struct.printing_state* %35, i8 signext %38)
br label %40
40: ; preds = %34, %31
br label %41
41: ; preds = %40, %25
%42 = load i32, i32* %8
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = mul i32 %43, %44
%46 = sub i32 %42, %45
store i32 %46, i32* %8
%47 = load i32, i32* %6
%48 = udiv i32 %47, 10
store i32 %48, i32* %6
br label %16
49: ; preds = %16
ret void
}

LLVM IR (-O2):
%struct.printing_state = type { i32 }
define void @print_unsigned_decimal(%struct.printing_state* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @print_buff_add(%struct.printing_state* %0, i8 signext 48)
br label %6
6: ; preds = %4, %2
br label %7
7: ; preds = %6, %22
%8 = phi i32 [ %12, %22 ], [ %1, %6 ]
%9 = phi i32 [ %25, %22 ], [ 1000000000, %6 ]
%10 = phi i32 [ %23, %22 ], [ 1, %6 ]
%11 = udiv i32 %8, %9
%12 = urem i32 %8, %9
%13 = icmp ugt i32 %9, %8
br i1 %13, label %17, label %14
14: ; preds = %7
%15 = trunc i32 %11 to i8
%16 = add i8 %15, 48
br label %19
17: ; preds = %7
%18 = icmp eq i32 %10, 0
br i1 %18, label %19, label %22
19: ; preds = %17, %14
%20 = phi i8 [ %16, %14 ], [ 48, %17 ]
%21 = tail call i32 @print_buff_add(%struct.printing_state* %0, i8 signext %20)
br label %22
22: ; preds = %19, %17
%23 = phi i32 [ 1, %17 ], [ 0, %19 ]
%24 = mul nuw i32 %11, %9
%25 = udiv i32 %9, 10
%26 = icmp ult i32 %9, 10
br i1 %26, label %27, label %7
27: ; preds = %22
ret void
}