#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 log_get_level();
int /*<<< orphan*/ log_write(char *, ...);
void serial_print_bits(unsigned int out) {
  unsigned int mask = 0x8000;
  if (log_get_level() < 1)
    return;
  for (; mask; mask >>= 1) {
    if ((mask & 0x08888888))
      log_write(" ");
    log_write("%u", out & mask ? 1 : 0);
  }
}


x86 assembly (clang, -O0):
<serial_print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x8000,-0x8(%rbp)
mov    $0x0,%al
call   1030 <log_get_level@plt>
cmp    $0x1,%eax
jge    1147 <serial_print_bits+0x27>
jmp    11a4 <serial_print_bits+0x84>
jmp    114c <serial_print_bits+0x2c>
cmpl   $0x0,-0x8(%rbp)
je     11a4 <serial_print_bits+0x84>
mov    -0x8(%rbp),%eax
and    $0x8888888,%eax
cmp    $0x0,%eax
je     1175 <serial_print_bits+0x55>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <log_write@plt>
mov    -0x4(%rbp),%ecx
and    -0x8(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <log_write@plt>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114c <serial_print_bits+0x2c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_print_bits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <log_get_level@plt>
test   %eax,%eax
jle    1181 <serial_print_bits+0x61>
mov    $0x8000,%ebp
lea    0xec2(%rip),%r14
lea    0xeb9(%rip),%r15
jmp    116d <serial_print_bits+0x4d>
nopl   0x0(%rax)
xor    %esi,%esi
test   %ebx,%ebp
setne  %sil
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <log_write@plt>
mov    %ebp,%eax
shr    %eax
cmp    $0x1,%ebp
mov    %eax,%ebp
jbe    1181 <serial_print_bits+0x61>
test   $0x8888,%ebp
je     1150 <serial_print_bits+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <log_write@plt>
jmp    1150 <serial_print_bits+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"%u\00"
define void @serial_print_bits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 32768, i32* %3
%4 = call i32 (...) @log_get_level()
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %1
br label %28
7: ; preds = %1
br label %8
8: ; preds = %25, %7
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %3
%13 = and i32 %12, 143165576
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = and i32 %18, %19
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 1, i32 0
%24 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %17
%26 = load i32, i32* %3
%27 = lshr i32 %26, 1
store i32 %27, i32* %3
br label %8
28: ; preds = %6, %8
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"%u\00"
define void @serial_print_bits(i32 %0) {
%2 = tail call i32 (...) @log_get_level()
%3 = icmp slt i32 %2, 1
br i1 %3, label %17, label %4
4: ; preds = %1, %10
%5 = phi i32 [ %15, %10 ], [ 32768, %1 ]
%6 = and i32 %5, 34952
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = and i32 %5, %0
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = lshr i32 %5, 1
%16 = icmp ult i32 %5, 2
br i1 %16, label %17, label %4
17: ; preds = %10, %1
ret void
}