#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 uint32_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_bits(const char *tag, uint32_t v, uint32_t count) {
  printf("%s 0b", tag);
  for (int32_t i = 0; i < count; ++i) {
    printf("%u", (v >> (count - 1 - i)) & 1);
    if (i == 31) {
      printf(" ...");
      break;
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1196 <print_bits+0x86>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x14(%rbp),%ecx
sar    %cl,%esi
and    $0x1,%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1f,-0x14(%rbp)
jne    1183 <print_bits+0x73>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <print_bits+0x86>
jmp    1188 <print_bits+0x78>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <print_bits+0x2b>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%rsi
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    118c <print_bits+0x6c>
mov    $0xffffffff,%ebp
lea    0xeb9(%rip),%r14
nopl   (%rax)
lea    (%rbx,%rbp,1),%ecx
mov    %r15d,%esi
shr    %cl,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xffffffe0,%ebp
je     117e <print_bits+0x5e>
lea    (%rbx,%rbp,1),%eax
add    $0xffffffff,%eax
mov    %ebp,%ecx
add    $0xffffffff,%ecx
mov    %ecx,%ebp
cmp    $0xffffffff,%eax
jne    1150 <print_bits+0x30>
jmp    118c <print_bits+0x6c>
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s 0b\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [5 x i8] c" ...\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @print_bits(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %8)
store i32 0, i32* %7
br label %10
10: ; preds = %28, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 1
%18 = load i32, i32* %7
%19 = sub nsw i32 %17, %18
%20 = ashr i32 %15, %19
%21 = and i32 %20, 1
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 31
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %31
27: ; preds = %14
br label %28
28: ; preds = %27
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %10
31: ; preds = %25, %10
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s 0b\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [5 x i8] c" ...\00"
define void @print_bits(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %8, label %19
6: ; preds = %8
%7 = icmp eq i32 %16, %2
br i1 %7, label %19, label %8
8: ; preds = %3, %6
%9 = phi i32 [ %16, %6 ], [ 0, %3 ]
%10 = xor i32 %9, -1
%11 = add i32 %10, %2
%12 = lshr i32 %1, %11
%13 = and i32 %12, 1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %9, 31
%16 = add nuw nsw i32 %9, 1
br i1 %15, label %17, label %6
17: ; preds = %8
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %6, %3, %17
%20 = tail call i32 @putchar(i32 10)
ret void
}