#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*/ ft_putchar(char);
void print_bits(unsigned char octet) {
  char bits[8];
  int nb;
  int count;
  count = 0;
  nb = octet;
  while (nb > 0) {
    bits[count] = nb % 2;
    nb = nb / 2;
    count++;
  }
  while (count - 1 >= 0) {
    ft_putchar(bits[count - 1] + '0');
    count--;
  }
}


x86 assembly (clang, -O0):
<print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x14(%rbp)
movzbl -0x1(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1167 <print_bits+0x57>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x9(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112c <print_bits+0x1c>
jmp    116c <print_bits+0x5c>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
jl     11a1 <print_bits+0x91>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x9(%rbp,%rax,1),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <ft_putchar@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    116c <print_bits+0x5c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     1169 <print_bits+0x59>
movzbl %dil,%eax
xor    %ebx,%ebx
mov    %eax,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edx
and    $0x1,%dl
mov    %dl,0x8(%rsp,%rbx,1)
shr    %ecx
add    $0x1,%rbx
cmp    $0x2,%eax
mov    %ecx,%eax
jae    1130 <print_bits+0x20>
test   %ebx,%ebx
jle    1169 <print_bits+0x59>
add    $0x1,%rbx
xchg   %ax,%ax
movzbl 0x6(%rsp,%rbx,1),%eax
add    $0x30,%al
movsbl %al,%edi
call   1030 <ft_putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1150 <print_bits+0x40>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @print_bits(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = alloca i32
store i8 %0, i8* %2
store i32 0, i32* %5
%6 = load i8, i8* %2
%7 = zext i8 %6 to i32
store i32 %7, i32* %4
br label %8
8: ; preds = %11, %1
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i32, i32* %4
%13 = srem i32 %12, 2
%14 = trunc i32 %13 to i8
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %16
store i8 %14, i8* %17
%18 = load i32, i32* %4
%19 = sdiv i32 %18, 2
store i32 %19, i32* %4
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %8
22: ; preds = %8
br label %23
23: ; preds = %27, %22
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = add nsw i32 %33, 48
%35 = trunc i32 %34 to i8
%36 = call i32 @ft_putchar(i8 signext %35)
%37 = load i32, i32* %5
%38 = add nsw i32 %37, -1
store i32 %38, i32* %5
br label %23
39: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @print_bits(i8 zeroext %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8 %0, 0
br i1 %4, label %29, label %5
5: ; preds = %1
%6 = zext i8 %0 to i32
br label %12
7: ; preds = %12
%8 = trunc i64 %19 to i32
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = and i64 %19, 4294967295
br label %21
12: ; preds = %5, %12
%13 = phi i64 [ 0, %5 ], [ %19, %12 ]
%14 = phi i32 [ %6, %5 ], [ %18, %12 ]
%15 = trunc i32 %14 to i8
%16 = and i8 %15, 1
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 %13
store i8 %16, i8* %17
%18 = lshr i32 %14, 1
%19 = add nuw nsw i64 %13, 1
%20 = icmp ult i32 %14, 2
br i1 %20, label %7, label %12
21: ; preds = %10, %21
%22 = phi i64 [ %11, %10 ], [ %23, %21 ]
%23 = add nsw i64 %22, -1
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = add i8 %25, 48
%27 = tail call i32 @ft_putchar(i8 signext %26)
%28 = icmp ugt i64 %22, 1
br i1 %28, label %21, label %29
29: ; preds = %21, %1, %7
ret void
}