#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
void write_type_count(FILE *out, unsigned type, unsigned count) {
  count--;
  fputc(((count >= 32) << 7) | ((count & 31) << 2) | type, out);
  count >>= 5;
  while (count) {
    fputc(((count >= 128) << 7) | (count & 127), out);
    count >>= 7;
  }
}


x86 assembly (clang, -O0):
<write_type_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
setae  %al
and    $0x1,%al
movzbl %al,%edi
shl    $0x7,%edi
mov    -0x10(%rbp),%eax
and    $0x1f,%eax
shl    $0x2,%eax
or     %eax,%edi
or     -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x10(%rbp),%eax
shr    $0x5,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1195 <write_type_count+0x85>
cmpl   $0x80,-0x10(%rbp)
setae  %al
and    $0x1,%al
movzbl %al,%edi
shl    $0x7,%edi
mov    -0x10(%rbp),%eax
and    $0x7f,%eax
or     %eax,%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x10(%rbp),%eax
shr    $0x7,%eax
mov    %eax,-0x10(%rbp)
jmp    115a <write_type_count+0x4a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_type_count>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    -0x1(%rdx),%ebx
xor    %eax,%eax
cmp    $0x20,%ebx
setae  %al
shl    $0x7,%eax
lea    -0x4(,%rdx,4),%edi
and    $0x7c,%edi
or     %esi,%edi
or     %eax,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
cmp    $0x20,%ebx
jb     1174 <write_type_count+0x64>
shr    $0x5,%ebx
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
cmp    $0x7f,%ebx
seta   %al
shl    $0x7,%eax
mov    %ebx,%edi
and    $0x7f,%edi
or     %eax,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
shr    $0x7,%ebp
cmp    $0x7f,%ebx
mov    %ebp,%ebx
ja     1150 <write_type_count+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @write_type_count(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = add i32 %7, -1
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp uge i32 %9, 32
%11 = zext i1 %10 to i32
%12 = shl i32 %11, 7
%13 = load i32, i32* %6
%14 = and i32 %13, 31
%15 = shl i32 %14, 2
%16 = or i32 %12, %15
%17 = load i32, i32* %5
%18 = or i32 %16, %17
%19 = load i32*, i32** %4
%20 = call i32 @fputc(i32 %18, i32* %19)
%21 = load i32, i32* %6
%22 = lshr i32 %21, 5
store i32 %22, i32* %6
br label %23
23: ; preds = %26, %3
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = load i32, i32* %6
%28 = icmp uge i32 %27, 128
%29 = zext i1 %28 to i32
%30 = shl i32 %29, 7
%31 = load i32, i32* %6
%32 = and i32 %31, 127
%33 = or i32 %30, %32
%34 = load i32*, i32** %4
%35 = call i32 @fputc(i32 %33, i32* %34)
%36 = load i32, i32* %6
%37 = lshr i32 %36, 7
store i32 %37, i32* %6
br label %23
38: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @write_type_count(i32* nocapture %0, i32 %1, i32 %2) {
%4 = add i32 %2, -1
%5 = icmp ugt i32 %4, 31
%6 = select i1 %5, i32 128, i32 0
%7 = shl i32 %4, 2
%8 = and i32 %7, 124
%9 = or i32 %8, %1
%10 = or i32 %9, %6
%11 = tail call i32 @fputc(i32 %10, i32* %0)
%12 = icmp ult i32 %4, 32
br i1 %12, label %23, label %13
13: ; preds = %3
%14 = lshr i32 %4, 5
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ %22, %15 ], [ %14, %13 ]
%17 = icmp ult i32 %16, 128
%18 = select i1 %17, i32 0, i32 128
%19 = and i32 %16, 127
%20 = or i32 %18, %19
%21 = tail call i32 @fputc(i32 %20, i32* %0)
%22 = lshr i32 %16, 7
br i1 %17, label %23, label %15
23: ; preds = %15, %3
ret void
}