#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 */
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ isprint(unsigned int);
char *int2chars(uint16_t w, char *buf) {
  buf[0] = (w & 0b1111111100000000) >> 8;
  if (!isprint((unsigned)buf[0]))
    buf[0] = '.';
  buf[1] = (w & 0b0000000011111111);
  if (!isprint((unsigned)buf[1]))
    buf[1] = '.';
  buf[2] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<int2chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isprint@plt>
cmp    $0x0,%eax
jne    114e <int2chars+0x3e>
mov    -0x10(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isprint@plt>
cmp    $0x0,%eax
jne    117d <int2chars+0x6d>
mov    -0x10(%rbp),%rax
movb   $0x2e,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int2chars>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edi,%eax
shr    $0x8,%eax
mov    %al,(%rsi)
movsbl %al,%edi
call   1030 <isprint@plt>
test   %eax,%eax
jne    112e <int2chars+0x1e>
movb   $0x2e,(%rbx)
mov    %bpl,0x1(%rbx)
movsbl %bpl,%edi
call   1030 <isprint@plt>
test   %eax,%eax
jne    1143 <int2chars+0x33>
movb   $0x2e,0x1(%rbx)
movb   $0x0,0x2(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @int2chars(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = and i32 %5, 65280
%7 = ashr i32 %6, 8
%8 = trunc i32 %7 to i8
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
store i8 %8, i8* %10
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = call i32 @isprint(i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 46, i8* %19
br label %20
20: ; preds = %17, %2
%21 = load i32, i32* %3
%22 = and i32 %21, 255
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 %23, i8* %25
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 @isprint(i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %20
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8 46, i8* %34
br label %35
35: ; preds = %32, %20
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 2
store i8 0, i8* %37
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
define i8* @int2chars(i32 %0, i8* returned writeonly %1) {
%3 = lshr i32 %0, 8
%4 = trunc i32 %3 to i8
store i8 %4, i8* %1
%5 = shl i32 %3, 24
%6 = ashr exact i32 %5, 24
%7 = tail call i32 @isprint(i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i8 46, i8* %1
br label %10
10: ; preds = %9, %2
%11 = trunc i32 %0 to i8
%12 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %11, i8* %12
%13 = shl i32 %0, 24
%14 = ashr exact i32 %13, 24
%15 = tail call i32 @isprint(i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %10
store i8 46, i8* %12
br label %18
18: ; preds = %17, %10
%19 = getelementptr inbounds i8, i8* %1, i64 2
store i8 0, i8* %19
ret i8* %1
}