#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 uint32_t;
typedef scalar_t__ u_char;

/* Variables and functions */
int /*<<< orphan*/ do_write(scalar_t__ *, size_t);
void do_write_number(uint32_t num) {
  u_char buf[5], *b = buf;
  size_t sz;
  do {
    *b = (u_char)(num & 0x7f);
  } while ((num >>= 7) && (*(b++) |= 0x80));
  sz = b - buf + 1;
  do_write(buf, sz);
}


x86 assembly (clang, -O0):
<do_write_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7f,%eax
movslq %eax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%ecx
sar    $0x7,%ecx
mov    %ecx,-0x4(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x41(%rbp)
je     116f <do_write_number+0x5f>
mov    -0x38(%rbp),%rcx
mov    %rcx,%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    (%rcx),%rax
or     $0x80,%rax
mov    %rax,(%rcx)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1123 <do_write_number+0x13>
mov    -0x38(%rbp),%rax
lea    -0x30(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <do_write@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_write_number>:
sub    $0x28,%rsp
mov    %edi,%r8d
mov    %rsp,%rdi
mov    %r8d,%ecx
and    $0x7f,%ecx
mov    %rcx,(%rsp)
mov    %rdi,%rsi
cmp    $0x80,%r8d
jb     1169 <do_write_number+0x59>
mov    %rsp,%rax
mov    %r8d,%edx
cs nopw 0x0(%rax,%rax,1)
sar    $0x7,%edx
lea    0x8(%rax),%rsi
or     $0x80,%rcx
mov    %rcx,(%rax)
mov    %edx,%ecx
and    $0x7f,%ecx
mov    %rcx,0x8(%rax)
mov    %rsi,%rax
cmp    $0x3fff,%r8d
mov    %edx,%r8d
ja     1140 <do_write_number+0x30>
sub    %rdi,%rsi
sar    $0x3,%rsi
add    $0x1,%rsi
call   1030 <do_write@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
define void @do_write_number(i32 %0) {
%2 = alloca i32
%3 = alloca [5 x i64]
%4 = alloca i64*
%5 = alloca i64
store i32 %0, i32* %2
%6 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 0
store i64* %6, i64** %4
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %2
%9 = and i32 %8, 127
%10 = sext i32 %9 to i64
%11 = load i64*, i64** %4
store i64 %10, i64* %11
br label %12
12: ; preds = %7
%13 = load i32, i32* %2
%14 = ashr i32 %13, 7
store i32 %14, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i64*, i64** %4
%18 = getelementptr inbounds i64, i64* %17, i32 1
store i64* %18, i64** %4
%19 = load i64, i64* %17
%20 = or i64 %19, 128
store i64 %20, i64* %17
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %16, %12
%23 = phi i1 [ false, %12 ], [ %21, %16 ]
br i1 %23, label %7, label %24
24: ; preds = %22
%25 = load i64*, i64** %4
%26 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 0
%27 = ptrtoint i64* %25 to i64
%28 = ptrtoint i64* %26 to i64
%29 = sub i64 %27, %28
%30 = sdiv exact i64 %29, 8
%31 = add nsw i64 %30, 1
store i64 %31, i64* %5
%32 = getelementptr inbounds [5 x i64], [5 x i64]* %3, i64 0, i64 0
%33 = load i64, i64* %5
%34 = call i32 @do_write(i64* %32, i64 %33)
ret void
}

LLVM IR (-O2):
define void @do_write_number(i32 %0) {
%2 = alloca [5 x i64]
%3 = bitcast [5 x i64]* %2 to i8*
%4 = getelementptr inbounds [5 x i64], [5 x i64]* %2, i64 0, i64 0
%5 = and i32 %0, 127
%6 = zext i32 %5 to i64
store i64 %6, i64* %4
%7 = icmp ult i32 %0, 128
br i1 %7, label %18, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %16, %8 ], [ %6, %1 ]
%10 = phi i32 [ %12, %8 ], [ %0, %1 ]
%11 = phi i64* [ %13, %8 ], [ %4, %1 ]
%12 = ashr i32 %10, 7
%13 = getelementptr inbounds i64, i64* %11, i64 1
%14 = or i64 %9, 128
store i64 %14, i64* %11
%15 = and i32 %12, 127
%16 = zext i32 %15 to i64
store i64 %16, i64* %13
%17 = icmp ult i32 %10, 16384
br i1 %17, label %18, label %8
18: ; preds = %8, %1
%19 = phi i64* [ %4, %1 ], [ %13, %8 ]
%20 = ptrtoint i64* %19 to i64
%21 = ptrtoint [5 x i64]* %2 to i64
%22 = sub i64 %20, %21
%23 = ashr exact i64 %22, 3
%24 = add nsw i64 %23, 1
%25 = call i32 @do_write(i64* %4, i64 %24)
ret void
}