#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 */
unsigned int sys_call(int, unsigned int, int, int /*<<< orphan*/,
                      int /*<<< orphan*/);
unsigned int tty_putw(unsigned int val) {
  char buf[10];
  unsigned int i;
  for (i = 0; i < 10; i++) {
    buf[9 - i] = (val % 10) + 0x30;
    val = val / 10;
  }
  return sys_call(0x02, (unsigned int)buf, 10, 0, 0);
}


x86 assembly (clang, -O0):
<tty_putw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jae    1168 <tty_putw+0x58>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    $0x9,%eax
sub    -0x14(%rbp),%eax
mov    %eax,%eax
mov    %cl,-0xe(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1122 <tty_putw+0x12>
lea    -0xe(%rbp),%rax
mov    %eax,%esi
mov    $0x2,%edi
mov    $0xa,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1030 <sys_call@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_putw>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r9d
mov    $0xcccccccd,%r8d
imul   $0x51eb851f,%r9,%r10
imul   $0x10624dd3,%r9,%r11
mov    $0xd1b71759,%r14d
imul   %r9,%r14
imul   $0x431bde83,%r9,%rcx
imul   $0x6b5fca6b,%r9,%rdx
imul   $0x55e63b89,%r9,%rsi
imul   %r8,%r9
shr    $0x23,%r9
lea    (%r9,%r9,1),%ebx
lea    (%rbx,%rbx,4),%ebx
mov    %edi,%ebp
sub    %ebx,%ebp
or     $0x30,%bpl
mov    %bpl,0xf(%rsp)
mov    %r9,%rbx
imul   %r8,%rbx
shr    $0x23,%rbx
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
sub    %ebx,%r9d
or     $0x30,%r9b
mov    %r9b,0xe(%rsp)
shr    $0x25,%r10
mov    %r10,%rbp
imul   %r8,%rbp
shr    $0x23,%rbp
add    %ebp,%ebp
lea    0x0(%rbp,%rbp,4),%ebp
sub    %ebp,%r10d
or     $0x30,%r10b
mov    %r10b,0xd(%rsp)
shr    $0x26,%r11
mov    %r11,%rbp
imul   %r8,%rbp
shr    $0x23,%rbp
add    %ebp,%ebp
lea    0x0(%rbp,%rbp,4),%ebp
sub    %ebp,%r11d
or     $0x30,%r11b
mov    %r11b,0xc(%rsp)
shr    $0x2d,%r14
mov    %r14,%rax
imul   %r8,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r14d
or     $0x30,%r14b
mov    %r14b,0xb(%rsp)
mov    %edi,%eax
shr    $0x5,%eax
imul   $0xa7c5ac5,%rax,%rax
shr    $0x27,%rax
imul   $0xcccd,%eax,%ebp
shr    $0x12,%ebp
and    $0xfffffffe,%ebp
lea    0x0(%rbp,%rbp,4),%ebp
sub    %ebp,%eax
or     $0x30,%al
mov    %al,0xa(%rsp)
shr    $0x32,%rcx
imul   $0xcccd,%ecx,%eax
shr    $0x12,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ecx
or     $0x30,%cl
mov    %cl,0x9(%rsp)
shr    $0x36,%rdx
imul   $0xcccd,%edx,%eax
shr    $0x12,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
or     $0x30,%dl
mov    %dl,0x8(%rsp)
shr    $0x39,%rsi
imul   $0xcd,%esi,%eax
shr    $0xa,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rax,4),%eax
sub    %al,%sil
or     $0x30,%sil
mov    %sil,0x7(%rsp)
shr    $0x9,%edi
imul   $0x44b83,%rdi,%rax
shr    $0x27,%rax
or     $0x30,%al
mov    %al,0x6(%rsp)
lea    0x6(%rsp),%rsi
mov    $0x2,%edi
mov    $0xa,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <sys_call@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @tty_putw(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = urem i32 %0, 10
%5 = trunc i32 %4 to i8
%6 = or i8 %5, 48
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 9
store i8 %6, i8* %7
%8 = udiv i32 %0, 10
%9 = urem i32 %8, 10
%10 = trunc i32 %9 to i8
%11 = or i8 %10, 48
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 8
store i8 %11, i8* %12
%13 = udiv i32 %0, 100
%14 = urem i32 %13, 10
%15 = trunc i32 %14 to i8
%16 = or i8 %15, 48
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 7
store i8 %16, i8* %17
%18 = udiv i32 %0, 1000
%19 = urem i32 %18, 10
%20 = trunc i32 %19 to i8
%21 = or i8 %20, 48
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 6
store i8 %21, i8* %22
%23 = udiv i32 %0, 10000
%24 = urem i32 %23, 10
%25 = trunc i32 %24 to i8
%26 = or i8 %25, 48
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
store i8 %26, i8* %27
%28 = udiv i32 %0, 100000
%29 = trunc i32 %28 to i16
%30 = urem i16 %29, 10
%31 = trunc i16 %30 to i8
%32 = or i8 %31, 48
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 4
store i8 %32, i8* %33
%34 = udiv i32 %0, 1000000
%35 = trunc i32 %34 to i16
%36 = urem i16 %35, 10
%37 = trunc i16 %36 to i8
%38 = or i8 %37, 48
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 3
store i8 %38, i8* %39
%40 = udiv i32 %0, 10000000
%41 = trunc i32 %40 to i16
%42 = urem i16 %41, 10
%43 = trunc i16 %42 to i8
%44 = or i8 %43, 48
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
store i8 %44, i8* %45
%46 = udiv i32 %0, 100000000
%47 = trunc i32 %46 to i8
%48 = urem i8 %47, 10
%49 = or i8 %48, 48
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
store i8 %49, i8* %50
%51 = udiv i32 %0, 1000000000
%52 = trunc i32 %51 to i8
%53 = or i8 %52, 48
store i8 %53, i8* %3
%54 = ptrtoint [10 x i8]* %2 to i64
%55 = trunc i64 %54 to i32
%56 = call i32 @sys_call(i32 2, i32 %55, i32 10, i32 0, i32 0)
ret i32 %56
}