#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*/ strcat(char *, char *);
const char *byte_to_binary(unsigned short x) {
  int z;
  static char b[14];
  b[0] = '\0';
  z = 256;
  while (z > 0) {
    strcat(b, ((x & z) == z) ? "1" : "0");
    z >>= 1;
  }
  return (b);
}


x86 assembly (clang, -O0):
<byte_to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movb   $0x0,0x2f03(%rip)
movl   $0x100,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    116f <byte_to_binary+0x5f>
movzwl -0x2(%rbp),%ecx
and    -0x8(%rbp),%ecx
mov    -0x8(%rbp),%edx
lea    0xeba(%rip),%rsi
lea    0xeb1(%rip),%rax
cmp    %edx,%ecx
cmove  %rax,%rsi
lea    0x2ecd(%rip),%rdi
call   1030 <strcat@plt>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112d <byte_to_binary+0x1d>
lea    0x2eb3(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_to_binary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
movb   $0x0,0x2f09(%rip)
lea    0x2f02(%rip),%r14
test   $0x100,%edi
lea    0xeee(%rip),%r15
lea    0xee5(%rip),%rbx
mov    %rbx,%rsi
cmove  %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
movd   %ebp,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xea5(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xea9(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ebp
test   $0x80,%bpl
mov    %rbx,%rsi
cmovne %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
test   $0x40,%bpl
mov    %rbx,%rsi
cmovne %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
test   $0x20,%bpl
mov    %rbx,%rsi
cmovne %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
test   $0x10,%bpl
mov    %rbx,%rsi
cmovne %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
test   $0x8,%bpl
mov    %rbx,%rsi
cmovne %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
test   $0x4,%bpl
mov    %rbx,%rsi
cmovne %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
test   $0x2,%bpl
mov    %rbx,%rsi
cmovne %r15,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
test   $0x1,%bpl
cmovne %r15,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcat@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@byte_to_binary.b = internal global [14 x i8] zeroinitializer
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @byte_to_binary(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i32
store i16 %0, i16* %2
store i8 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0)
store i32 256, i32* %3
br label %4
4: ; preds = %7, %1
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = load i16, i16* %2
%9 = zext i16 %8 to i32
%10 = load i32, i32* %3
%11 = and i32 %9, %10
%12 = load i32, i32* %3
%13 = icmp eq i32 %11, %12
%14 = zext i1 %13 to i64
%15 = select i1 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%16 = call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %3
%18 = ashr i32 %17, 1
store i32 %18, i32* %3
br label %4
19: ; preds = %4
ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0)
}

LLVM IR (-O2):
@byte_to_binary.b = internal global [14 x i8] zeroinitializer
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @byte_to_binary(i16 zeroext %0) {
store i8 0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0)
%2 = zext i16 %0 to i32
%3 = and i32 %2, 256
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%6 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %5)
%7 = insertelement <8 x i32> poison, i32 %2, i64 0
%8 = shufflevector <8 x i32> %7, <8 x i32> poison, <8 x i32> zeroinitializer
%9 = and <8 x i32> %8, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%10 = icmp eq <8 x i32> %9, zeroinitializer
%11 = extractelement <8 x i1> %10, i64 7
%12 = select i1 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%13 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %12)
%14 = extractelement <8 x i1> %10, i64 6
%15 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%16 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %15)
%17 = extractelement <8 x i1> %10, i64 5
%18 = select i1 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%19 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %18)
%20 = extractelement <8 x i1> %10, i64 4
%21 = select i1 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%22 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %21)
%23 = extractelement <8 x i1> %10, i64 3
%24 = select i1 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%25 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %24)
%26 = extractelement <8 x i1> %10, i64 2
%27 = select i1 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%28 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %27)
%29 = extractelement <8 x i1> %10, i64 1
%30 = select i1 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%31 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %30)
%32 = extractelement <8 x i1> %10, i64 0
%33 = select i1 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%34 = tail call i32 @strcat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %33)
ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @byte_to_binary.b, i64 0, i64 0)
}