#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*/ put_bit(int);
void put_char(char c) {
  put_bit(0);
  for (int i = 0; i < 8; i++) {
    put_bit(c & 1);
    c >>= 1;
  }
  put_bit(1);
}


x86 assembly (clang, -O0):
<put_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
xor    %edi,%edi
call   1030 <put_bit@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    115a <put_char+0x4a>
movsbl -0x1(%rbp),%edi
and    $0x1,%edi
call   1030 <put_bit@plt>
movsbl -0x1(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x1(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112c <put_char+0x1c>
mov    $0x1,%edi
call   1030 <put_bit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_char>:
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
call   1030 <put_bit@plt>
mov    %ebx,%edi
and    $0x1,%edi
call   1030 <put_bit@plt>
mov    %ebx,%eax
shr    %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <put_bit@plt>
mov    %ebx,%eax
shr    $0x2,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <put_bit@plt>
mov    %ebx,%eax
shr    $0x3,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <put_bit@plt>
mov    %ebx,%eax
shr    $0x4,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <put_bit@plt>
mov    %ebx,%eax
shr    $0x5,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <put_bit@plt>
mov    %ebx,%eax
shr    $0x6,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <put_bit@plt>
shr    $0x7,%bl
movzbl %bl,%edi
call   1030 <put_bit@plt>
mov    $0x1,%edi
pop    %rbx
jmp    1030 <put_bit@plt>

LLVM IR (-O0):
define void @put_char(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
%4 = call i32 @put_bit(i32 0)
store i32 0, i32* %3
br label %5
5: ; preds = %17, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 8
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = and i32 %10, 1
%12 = call i32 @put_bit(i32 %11)
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = ashr i32 %14, 1
%16 = trunc i32 %15 to i8
store i8 %16, i8* %2
br label %17
17: ; preds = %8
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %5
20: ; preds = %5
%21 = call i32 @put_bit(i32 1)
ret void
}

LLVM IR (-O2):
define void @put_char(i8 signext %0) {
%2 = tail call i32 @put_bit(i32 0)
%3 = and i8 %0, 1
%4 = zext i8 %3 to i32
%5 = tail call i32 @put_bit(i32 %4)
%6 = lshr i8 %0, 1
%7 = and i8 %6, 1
%8 = zext i8 %7 to i32
%9 = tail call i32 @put_bit(i32 %8)
%10 = lshr i8 %0, 2
%11 = and i8 %10, 1
%12 = zext i8 %11 to i32
%13 = tail call i32 @put_bit(i32 %12)
%14 = lshr i8 %0, 3
%15 = and i8 %14, 1
%16 = zext i8 %15 to i32
%17 = tail call i32 @put_bit(i32 %16)
%18 = lshr i8 %0, 4
%19 = and i8 %18, 1
%20 = zext i8 %19 to i32
%21 = tail call i32 @put_bit(i32 %20)
%22 = lshr i8 %0, 5
%23 = and i8 %22, 1
%24 = zext i8 %23 to i32
%25 = tail call i32 @put_bit(i32 %24)
%26 = lshr i8 %0, 6
%27 = and i8 %26, 1
%28 = zext i8 %27 to i32
%29 = tail call i32 @put_bit(i32 %28)
%30 = lshr i8 %0, 7
%31 = zext i8 %30 to i32
%32 = tail call i32 @put_bit(i32 %31)
%33 = tail call i32 @put_bit(i32 1)
ret void
}