#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*/ strcat(char *, char *);
const char *getBin16(uint16_t x) {
  static char b[17];
  b[0] = '\0';
  int z;
  for (z = 32768; z > 0; z >>= 1) {
    if (z == 128)
      strcat(b, " ");
    strcat(b, ((x & z) == z) ? "1" : "0");
  }
  return b;
}


x86 assembly (clang, -O0):
<getBin16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,0x2f1e(%rip)
movl   $0x8000,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    118a <getBin16+0x7a>
cmpl   $0x80,-0x8(%rbp)
jne    1153 <getBin16+0x43>
lea    0x2ef9(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <strcat@plt>
mov    -0x4(%rbp),%ecx
and    -0x8(%rbp),%ecx
mov    -0x8(%rbp),%edx
lea    0xea1(%rip),%rsi
lea    0xe98(%rip),%rax
cmp    %edx,%ecx
cmove  %rax,%rsi
lea    0x2ec9(%rip),%rdi
call   1030 <strcat@plt>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <getBin16+0x19>
lea    0x2eaf(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBin16>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x0,0x2f1c(%rip)
mov    $0x8000,%ebp
lea    0x2f10(%rip),%r14
lea    0xec9(%rip),%r15
not    %ebx
lea    0xec2(%rip),%r12
lea    0xebd(%rip),%r13
jmp    116e <getBin16+0x5e>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcat@plt>
test   %ebx,%ebp
mov    %r13,%rsi
cmove  %r12,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
shr    %ebp
movzwl %bp,%eax
cmp    $0x80,%eax
je     1150 <getBin16+0x40>
test   %bp,%bp
jne    115b <getBin16+0x4b>
lea    0x2ebc(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@getBin16.b = internal global [17 x i8] zeroinitializer
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [2 x i8] c"0\00"
define i8* @getBin16(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i8 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @getBin16.b, i64 0, i64 0)
store i32 32768, i32* %3
br label %4
4: ; preds = %21, %1
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %4
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 128
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @strcat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @getBin16.b, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = and i32 %13, %14
%16 = load i32, i32* %3
%17 = icmp eq i32 %15, %16
%18 = zext i1 %17 to i64
%19 = 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.2, i64 0, i64 0)
%20 = call i32 @strcat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @getBin16.b, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %12
%22 = load i32, i32* %3
%23 = ashr i32 %22, 1
store i32 %23, i32* %3
br label %4
24: ; preds = %4
ret i8* getelementptr inbounds ([17 x i8], [17 x i8]* @getBin16.b, i64 0, i64 0)
}

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