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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
unsigned int clz_32(unsigned int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ put2(void *, int);
int /*<<< orphan*/ put4(char *, unsigned int);
void putrate(void *b, uint32_t v) {
  unsigned n;
  assert(b != NULL);
  if (v == 0) {
    (void)memset(b, 0, 10);
    return;
  }
  n = clz_32(v);
  put2(b, 31 - n + 0x3FFF);
  put4((char *)b + 2, v << n);
  (void)memset((char *)b + 6, 0, 4);
}


x86 assembly (clang, -O0):
<putrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1190 <putrate+0x40>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
jmp    11db <putrate+0x8b>
mov    -0xc(%rbp),%edi
call   1050 <clz_32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1f,%esi
sub    -0x10(%rbp),%esi
add    $0x3fff,%esi
call   1040 <put2@plt>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
shl    %cl,%esi
call   1030 <put4@plt>
mov    -0x8(%rbp),%rdi
add    $0x6,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putrate>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1070 <assert@plt>
test   %ebp,%ebp
je     11a4 <putrate+0x54>
mov    %ebp,%edi
call   1050 <clz_32@plt>
mov    %eax,%r14d
mov    $0x401e,%esi
sub    %eax,%esi
mov    %rbx,%rdi
call   1040 <put2@plt>
lea    0x2(%rbx),%rdi
mov    %r14d,%ecx
shl    %cl,%ebp
mov    %ebp,%esi
call   1030 <put4@plt>
add    $0x6,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
jmp    11ae <putrate+0x5e>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <memset@plt>

LLVM IR (-O0):
define void @putrate(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @memset(i8* %13, i32 0, i32 10)
br label %32
15: ; preds = %2
%16 = load i32, i32* %4
%17 = call i32 @clz_32(i32 %16)
store i32 %17, i32* %5
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sub i32 31, %19
%21 = add i32 %20, 16383
%22 = call i32 @put2(i8* %18, i32 %21)
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = shl i32 %25, %26
%28 = call i32 @put4(i8* %24, i32 %27)
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 6
%31 = call i32 @memset(i8* %30, i32 0, i32 4)
br label %32
32: ; preds = %15, %12
ret void
}

LLVM IR (-O2):
define void @putrate(i8* %0, i32 %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp eq i32 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @memset(i8* %0, i32 0, i32 10)
br label %18
9: ; preds = %2
%10 = tail call i32 @clz_32(i32 %1)
%11 = sub i32 16414, %10
%12 = tail call i32 @put2(i8* %0, i32 %11)
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = shl i32 %1, %10
%15 = tail call i32 @put4(i8* %13, i32 %14)
%16 = getelementptr inbounds i8, i8* %0, i64 6
%17 = tail call i32 @memset(i8* %16, i32 0, i32 4)
br label %18
18: ; preds = %9, %7
ret void
}