#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*/ printf(char *, ...);
void printbinary(int value, int n, int breakafter, char breakcharacter) {
  printf("0b");
  for (int i = n - 1; i >= 0; i--) {
    printf("%d", (value >> i) & 1);
    if (i % breakafter == 0)
      printf("%c", breakcharacter);
  }
}


x86 assembly (clang, -O0):
<printbinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %al,-0xd(%rbp)
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1195 <printbinary+0x85>
mov    -0x4(%rbp),%esi
mov    -0x14(%rbp),%ecx
sar    %cl,%esi
and    $0x1,%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1182 <printbinary+0x72>
movsbl -0xd(%rbp),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1187 <printbinary+0x77>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <printbinary+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbinary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%r13d
lea    0xec3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    1193 <printbinary+0x73>
movsbl %r15b,%r15d
add    $0x1,%ebx
lea    0xead(%rip),%r12
jmp    1168 <printbinary+0x48>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jbe    1193 <printbinary+0x73>
lea    -0x2(%rbx),%ebp
mov    %r13d,%esi
mov    %ebp,%ecx
shr    %cl,%esi
and    $0x1,%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
cltd
idiv   %r14d
test   %edx,%edx
jne    1160 <printbinary+0x40>
mov    %r15d,%edi
call   1030 <putchar@plt>
jmp    1160 <printbinary+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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