#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(short x) {
  static char b[54];
  b[0] = '\0';
  int z;
  for (z = (1 << 15); z > 0; z >>= 1) {
    strcat(b, ((x & z) == z) ? "1" : "0");
    strcat(b, " |");
  }
  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,0x2f1a(%rip)
movl   $0x8000,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1182 <byte_to_binary+0x72>
movswl -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    0x2ee4(%rip),%rdi
call   1030 <strcat@plt>
lea    0x2ed8(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1030 <strcat@plt>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112d <byte_to_binary+0x1d>
lea    0x2eb7(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_to_binary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x2f1e(%rip)
movzwl %di,%r15d
mov    $0x8000,%r12d
not    %r15d
lea    0xecc(%rip),%r13
lea    0x2f03(%rip),%rbx
lea    0xec0(%rip),%r14
mov    $0x8000,%ebp
nopl   0x0(%rax)
test   %r15d,%r12d
mov    %r13,%rsi
lea    0xea3(%rip),%rax
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1030 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcat@plt>
shr    %ebp
cmp    $0x1,%r12d
mov    %ebp,%r12d
ja     1150 <byte_to_binary+0x40>
lea    0x2eba(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@byte_to_binary.b = internal global [54 x i8] zeroinitializer
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [3 x i8] c" |\00"
define i8* @byte_to_binary(i16 signext %0) {
%2 = alloca i16
%3 = alloca i32
store i16 %0, i16* %2
store i8 0, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @byte_to_binary.b, i64 0, i64 0)
store i32 32768, i32* %3
br label %4
4: ; preds = %18, %1
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = load i16, i16* %2
%9 = sext 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 ([54 x i8], [54 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %15)
%17 = call i32 @strcat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %7
%19 = load i32, i32* %3
%20 = ashr i32 %19, 1
store i32 %20, i32* %3
br label %4
21: ; preds = %4
ret i8* getelementptr inbounds ([54 x i8], [54 x i8]* @byte_to_binary.b, i64 0, i64 0)
}

LLVM IR (-O2):
@byte_to_binary.b = internal global [54 x i8] zeroinitializer
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [3 x i8] c" |\00"
define i8* @byte_to_binary(i16 signext %0) {
store i8 0, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @byte_to_binary.b, i64 0, i64 0)
%2 = zext i16 %0 to i32
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 32768, %1 ], [ %10, %3 ]
%5 = and i32 %4, %2
%6 = icmp eq i32 %5, %4
%7 = select i1 %6, 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)
%8 = tail call i32 @strcat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* %7)
%9 = tail call i32 @strcat(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @byte_to_binary.b, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = lshr i32 %4, 1
%11 = icmp ult i32 %4, 2
br i1 %11, label %12, label %3
12: ; preds = %3
ret i8* getelementptr inbounds ([54 x i8], [54 x i8]* @byte_to_binary.b, i64 0, i64 0)
}