#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*/ print(int, char *, int);
void sf_putnbr(unsigned int v) {
  unsigned int p;
  static const char base[11] = "0123456789";
  p = 1;
  while (p * 10 < v)
    p *= 10;
  while (p) {
    print(1, (char *)&base[((v / p) % 10)], 1);
    p /= 10;
  }
}


x86 assembly (clang, -O0):
<sf_putnbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
imul   $0xa,-0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    113b <sf_putnbr+0x2b>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <sf_putnbr+0x12>
jmp    1140 <sf_putnbr+0x30>
cmpl   $0x0,-0x8(%rbp)
je     1187 <sf_putnbr+0x77>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
lea    0xe9c(%rip),%rsi
add    %rax,%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <print@plt>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
jmp    1140 <sf_putnbr+0x30>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sf_putnbr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x1,%eax
xchg   %ax,%ax
mov    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
cmp    %ebp,%eax
jb     1120 <sf_putnbr+0x10>
test   %ebx,%ebx
je     117c <sf_putnbr+0x6c>
mov    $0xcccccccd,%r14d
lea    0xec3(%rip),%r15
nopl   (%rax)
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
mov    %rax,%rcx
imul   %r14,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
lea    (%rax,%r15,1),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <print@plt>
mov    %ebx,%eax
imul   %r14,%rax
shr    $0x23,%rax
cmp    $0x9,%ebx
mov    %eax,%ebx
ja     1140 <sf_putnbr+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@sf_putnbr.base = internal constant [11 x i8] c"0123456789\00"
define void @sf_putnbr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
br label %4
4: ; preds = %9, %1
%5 = load i32, i32* %3
%6 = mul i32 %5, 10
%7 = load i32, i32* %2
%8 = icmp ult i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* %3
%11 = mul i32 %10, 10
store i32 %11, i32* %3
br label %4
12: ; preds = %4
br label %13
13: ; preds = %16, %12
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = udiv i32 %17, %18
%20 = urem i32 %19, 10
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [11 x i8], [11 x i8]* @sf_putnbr.base, i64 0, i64 %21
%23 = call i32 @print(i32 1, i8* %22, i32 1)
%24 = load i32, i32* %3
%25 = udiv i32 %24, 10
store i32 %25, i32* %3
br label %13
26: ; preds = %13
ret void
}

LLVM IR (-O2):
@sf_putnbr.base = internal constant [11 x i8] c"0123456789\00"
define void @sf_putnbr(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 1, %1 ], [ %4, %2 ]
%4 = mul i32 %3, 10
%5 = icmp ult i32 %4, %0
br i1 %5, label %2, label %6
6: ; preds = %2
%7 = icmp eq i32 %3, 0
br i1 %7, label %17, label %8
8: ; preds = %6, %8
%9 = phi i32 [ %15, %8 ], [ %3, %6 ]
%10 = udiv i32 %0, %9
%11 = urem i32 %10, 10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [11 x i8], [11 x i8]* @sf_putnbr.base, i64 0, i64 %12
%14 = tail call i32 @print(i32 1, i8* %13, i32 1)
%15 = udiv i32 %9, 10
%16 = icmp ult i32 %9, 10
br i1 %16, label %17, label %8
17: ; preds = %8, %6
ret void
}