#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;
    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
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
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 = %20, %2
%11 = load i32, i32* %4
%12 = urem i32 %11, 10
%13 = trunc i32 %12 to i8
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i32 -1
store i8* %15, i8** %6
store i8 %13, i8* %15
%16 = load i32, i32* %4
%17 = udiv i32 %16, 10
store i32 %17, i32* %4
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
br label %20
20: ; preds = %10
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %10, label %23
23: ; preds = %20
%24 = load i32, i32* %3
%25 = load i8*, i8** %6
%26 = load i32, i32* %7
%27 = call i32 @write(i32 %24, i8* %25, i32 %26)
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 ], [ %13, %6 ]
%8 = phi i8* [ %5, %2 ], [ %12, %6 ]
%9 = phi i32 [ 0, %2 ], [ %14, %6 ]
%10 = urem i32 %7, 10
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %11, i8* %12
%13 = udiv i32 %7, 10
%14 = add nuw nsw i32 %9, 1
%15 = icmp ult i32 %7, 10
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = call i32 @write(i32 %0, i8* %12, i32 %14)
ret void
}