#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*/ memset(char *, char, int);
int /*<<< orphan*/ printk_char(unsigned short const, int /*<<< orphan*/);
int /*<<< orphan*/ printk_string(unsigned short const, char *);
void printk_uint(const unsigned short out, unsigned int val) {
  if (val == 0) {
    printk_char(out, '0');
  } else {
    unsigned int numLen = 11;
    unsigned int div = 1000000000;
    char numBuf[11];
    memset(numBuf, '\0', 11);
    while ((val / div) == 0) {
      --numLen;
      div /= 10;
    }
    numLen -= 2;
    do {
      int mod = val % 10;
      char c;
      switch (mod) {
      case 0:
        c = '0';
        break;
      case 1:
        c = '1';
        break;
      case 2:
        c = '2';
        break;
      case 3:
        c = '3';
        break;
      case 4:
        c = '4';
        break;
      case 5:
        c = '5';
        break;
      case 6:
        c = '6';
        break;
      case 7:
        c = '7';
        break;
      case 8:
        c = '8';
        break;
      case 9:
        c = '9';
        break;
      default:
        c = '?';
      }
      numBuf[numLen--] = c;
      val = val / 10;
    } while (val != 0);
    printk_string(out, numBuf);
  }
}


x86 assembly (clang, -O0):
<printk_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    115f <printk_uint+0x2f>
mov    $0x30,%esi
movzwl -0x2(%rbp),%edi
call   1030 <printk_char@plt>
jmp    1296 <printk_uint+0x166>
movl   $0xb,-0xc(%rbp)
movl   $0x3b9aca00,-0x10(%rbp)
lea    -0x1b(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
cmp    $0x0,%eax
jne    11ab <printk_uint+0x7b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x10(%rbp)
jmp    117d <printk_uint+0x4d>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    %ecx,%eax
mov    $0xcccccccd,%edx
imul   %rdx,%rcx
shr    $0x23,%rcx
mov    %ecx,%edx
add    %edx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x9,%rax
ja     1255 <printk_uint+0x125>
mov    -0x30(%rbp),%rax
lea    0xe0e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x30,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x31,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x32,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x33,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x34,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x35,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x36,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x37,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x38,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x39,-0x21(%rbp)
jmp    1259 <printk_uint+0x129>
movb   $0x3f,-0x21(%rbp)
mov    -0x21(%rbp),%cl
mov    -0xc(%rbp),%eax
mov    %eax,%edx
add    $0xffffffff,%edx
mov    %edx,-0xc(%rbp)
mov    %eax,%eax
mov    %cl,-0x1b(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11b4 <printk_uint+0x84>
mov    -0x2(%rbp),%ax
lea    -0x1b(%rbp),%rsi
movzwl %ax,%edi
call   1050 <printk_string@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printk_uint>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
test   %esi,%esi
je     11cd <printk_uint+0x9d>
mov    %esi,%ebp
lea    0xd(%rsp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1040 <memset@plt>
mov    $0x9,%eax
cmp    $0x3b9ac9ff,%ebp
ja     1181 <printk_uint+0x51>
mov    $0x3b9aca00,%ecx
mov    $0x9,%eax
mov    $0xcccccccd,%edx
nop
mov    %ecx,%ecx
imul   %rdx,%rcx
shr    $0x23,%rcx
add    $0xffffffff,%eax
cmp    %ebp,%ecx
ja     1170 <printk_uint+0x40>
mov    $0xcccccccd,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %ebp,%edi
sub    %esi,%edi
or     $0x30,%dil
mov    %eax,%esi
add    $0xffffffff,%eax
mov    %dil,0xd(%rsp,%rsi,1)
cmp    $0x9,%ebp
mov    %edx,%ebp
ja     1190 <printk_uint+0x60>
movzwl %bx,%edi
lea    0xd(%rsp),%rsi
call   1050 <printk_string@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
movzwl %bx,%edi
mov    $0x30,%esi
add    $0x18,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printk_char@plt>

LLVM IR (-O0):
define void @printk_uint(i16 zeroext %0, i32 %1) {
%3 = alloca i16
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [11 x i8]
%8 = alloca i32
%9 = alloca i8
store i16 %0, i16* %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i16, i16* %3
%14 = call i32 @printk_char(i16 zeroext %13, i32 48)
br label %61
15: ; preds = %2
store i32 11, i32* %5
store i32 1000000000, i32* %6
%16 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i8 signext 0, i32 11)
br label %18
18: ; preds = %23, %15
%19 = load i32, i32* %4
%20 = load i32, i32* %6
%21 = udiv i32 %19, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i32, i32* %5
%25 = add i32 %24, -1
store i32 %25, i32* %5
%26 = load i32, i32* %6
%27 = udiv i32 %26, 10
store i32 %27, i32* %6
br label %18
28: ; preds = %18
%29 = load i32, i32* %5
%30 = sub i32 %29, 2
store i32 %30, i32* %5
br label %31
31: ; preds = %54, %28
%32 = load i32, i32* %4
%33 = urem i32 %32, 10
store i32 %33, i32* %8
%34 = load i32, i32* %8
switch i32 %34, label %45 [
i32 0, label %35
i32 1, label %36
i32 2, label %37
i32 3, label %38
i32 4, label %39
i32 5, label %40
i32 6, label %41
i32 7, label %42
i32 8, label %43
i32 9, label %44
]
35: ; preds = %31
store i8 48, i8* %9
br label %46
36: ; preds = %31
store i8 49, i8* %9
br label %46
37: ; preds = %31
store i8 50, i8* %9
br label %46
38: ; preds = %31
store i8 51, i8* %9
br label %46
39: ; preds = %31
store i8 52, i8* %9
br label %46
40: ; preds = %31
store i8 53, i8* %9
br label %46
41: ; preds = %31
store i8 54, i8* %9
br label %46
42: ; preds = %31
store i8 55, i8* %9
br label %46
43: ; preds = %31
store i8 56, i8* %9
br label %46
44: ; preds = %31
store i8 57, i8* %9
br label %46
45: ; preds = %31
store i8 63, i8* %9
br label %46
46: ; preds = %45, %44, %43, %42, %41, %40, %39, %38, %37, %36, %35
%47 = load i8, i8* %9
%48 = load i32, i32* %5
%49 = add i32 %48, -1
store i32 %49, i32* %5
%50 = zext i32 %48 to i64
%51 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 %50
store i8 %47, i8* %51
%52 = load i32, i32* %4
%53 = udiv i32 %52, 10
store i32 %53, i32* %4
br label %54
54: ; preds = %46
%55 = load i32, i32* %4
%56 = icmp ne i32 %55, 0
br i1 %56, label %31, label %57
57: ; preds = %54
%58 = load i16, i16* %3
%59 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%60 = call i32 @printk_string(i16 zeroext %58, i8* %59)
br label %61
61: ; preds = %57, %12
ret void
}

LLVM IR (-O2):
define void @printk_uint(i16 zeroext %0, i32 %1) {
%3 = alloca [11 x i8]
%4 = icmp eq i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printk_char(i16 zeroext %0, i32 48)
br label %34
7: ; preds = %2
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i8 signext 0, i32 11)
%10 = icmp ult i32 %1, 1000000000
br i1 %10, label %11, label %19
11: ; preds = %7, %11
%12 = phi i32 [ %15, %11 ], [ 1000000000, %7 ]
%13 = phi i32 [ %14, %11 ], [ 11, %7 ]
%14 = add i32 %13, -1
%15 = udiv i32 %12, 10
%16 = icmp ugt i32 %15, %1
br i1 %16, label %11, label %17
17: ; preds = %11
%18 = add i32 %13, -3
br label %19
19: ; preds = %17, %7
%20 = phi i32 [ %18, %17 ], [ 9, %7 ]
br label %21
21: ; preds = %19, %21
%22 = phi i32 [ %27, %21 ], [ %20, %19 ]
%23 = phi i32 [ %30, %21 ], [ %1, %19 ]
%24 = urem i32 %23, 10
%25 = trunc i32 %24 to i8
%26 = or i8 %25, 48
%27 = add i32 %22, -1
%28 = zext i32 %22 to i64
%29 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %28
store i8 %26, i8* %29
%30 = udiv i32 %23, 10
%31 = icmp ult i32 %23, 10
br i1 %31, label %32, label %21
32: ; preds = %21
%33 = call i32 @printk_string(i16 zeroext %0, i8* %8)
br label %34
34: ; preds = %32, %5
ret void
}