#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*/ write(int, char *, int);
void writenum(int fd, unsigned int n) {
  char buf[6];
  char *bp = buf + 6;
  int c = 0;
  do {
    *--bp = (n % 10) + '0';
    n /= 10;
    c++;
  } while (n);
  write(fd, bp, c);
}


x86 assembly (clang, -O0):
<writenum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0xe(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1131 <writenum+0x21>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writenum>:
push   %rax
mov    %esi,%r9d
xor    %edx,%edx
lea    0x8(%rsp),%rsi
mov    $0xcccccccd,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r9d,%ecx
imul   %r8,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%eax
lea    (%rax,%rax,4),%r10d
mov    %r9d,%eax
sub    %r10d,%eax
or     $0x30,%al
mov    %al,-0x1(%rsi)
add    $0xffffffffffffffff,%rsi
add    $0x1,%edx
cmp    $0x9,%r9d
mov    %ecx,%r9d
ja     1130 <writenum+0x20>
call   1030 <write@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @writenum(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [6 x i8]
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds i8, i8* %8, i64 6
store i8* %9, i8** %6
store i32 0, i32* %7
br label %10
10: ; preds = %21, %2
%11 = load i32, i32* %4
%12 = urem i32 %11, 10
%13 = add i32 %12, 48
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** %6
store i8 %14, i8* %16
%17 = load i32, i32* %4
%18 = udiv i32 %17, 10
store i32 %18, i32* %4
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %21
21: ; preds = %10
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %10, label %24
24: ; preds = %21
%25 = load i32, i32* %3
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = call i32 @write(i32 %25, i8* %26, i32 %27)
ret void
}

LLVM IR (-O2):
define void @writenum(i32 %0, i32 %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 6
br label %6
6: ; preds = %6, %2
%7 = phi i32 [ %1, %2 ], [ %14, %6 ]
%8 = phi i8* [ %5, %2 ], [ %13, %6 ]
%9 = phi i32 [ 0, %2 ], [ %15, %6 ]
%10 = urem i32 %7, 10
%11 = trunc i32 %10 to i8
%12 = or i8 %11, 48
%13 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %12, i8* %13
%14 = udiv i32 %7, 10
%15 = add nuw nsw i32 %9, 1
%16 = icmp ult i32 %7, 10
br i1 %16, label %17, label %6
17: ; preds = %6
%18 = call i32 @write(i32 %0, i8* %13, i32 %15)
ret void
}