#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*/ sprintf(char *, char *, unsigned char);
void mls_type_data_ushort_to_str(char *outstr, unsigned short inb) {
  int i, size = 2;
  for (i = 0; i < size; i++) {
    unsigned char byte;
    byte = (unsigned char)((inb >> ((size - i - 1) * 8)) & (unsigned char)0xff);
    sprintf(outstr, "%02X", byte);
    outstr += 2;
  }
}


x86 assembly (clang, -O0):
<mls_type_data_ushort_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movl   $0x2,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1185 <mls_type_data_ushort_to_str+0x75>
movzwl -0xa(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x3,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
movzbl -0x15(%rbp),%edx
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <mls_type_data_ushort_to_str+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mls_type_data_ushort_to_str>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edx
shr    $0x8,%edx
lea    0xedb(%rip),%r14
mov    %r14,%rsi
call   1030 <sprintf@plt>
add    $0x2,%rbx
movzbl %bpl,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define void @mls_type_data_ushort_to_str(i8* %0, i16 zeroext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %3
store i16 %1, i16* %4
store i32 2, i32* %6
store i32 0, i32* %5
br label %8
8: ; preds = %28, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %31
12: ; preds = %8
%13 = load i16, i16* %4
%14 = zext i16 %13 to i32
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = sub nsw i32 %15, %16
%18 = sub nsw i32 %17, 1
%19 = mul nsw i32 %18, 8
%20 = ashr i32 %14, %19
%21 = and i32 %20, 255
%22 = trunc i32 %21 to i8
store i8 %22, i8* %7
%23 = load i8*, i8** %3
%24 = load i8, i8* %7
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8* %27, i8** %3
br label %28
28: ; preds = %12
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %8
31: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define void @mls_type_data_ushort_to_str(i8* nocapture writeonly %0, i16 zeroext %1) {
%3 = lshr i16 %1, 8
%4 = trunc i16 %3 to i8
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %4)
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = trunc i16 %1 to i8
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %7)
ret void
}