#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 uint8_t;
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ write(int, int *, size_t);
void writeBigInt(int fd, uint64_t val) {
  uint8_t buf[32];
  uint8_t *put = &buf[32];
  size_t size = 0;
  uint8_t flag = 0;
  do {
    *--put = (val & 0x7F) | flag;
    flag = 0x80;
    size++;
    val >>= 7;
  } while (val != 0);
  write(fd, put, size);
}


x86 assembly (clang, -O0):
<writeBigInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x90(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x98(%rbp)
movq   $0x0,-0xa0(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0x8(%rbp),%ecx
and    $0x7f,%ecx
or     -0xa4(%rbp),%ecx
mov    -0x98(%rbp),%rax
mov    %rax,%rdx
add    $0xfffffffffffffffc,%rdx
mov    %rdx,-0x98(%rbp)
mov    %ecx,-0x4(%rax)
movl   $0x80,-0xa4(%rbp)
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x7,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    114a <writeBigInt+0x3a>
mov    -0x4(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0xa0(%rbp),%rdx
call   1030 <write@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeBigInt>:
sub    $0x88,%rsp
mov    %esi,%r8d
mov    %esi,%ecx
and    $0x7f,%ecx
lea    0x7c(%rsp),%rsi
mov    %ecx,0x7c(%rsp)
mov    $0x1,%edx
cmp    $0x80,%r8d
jb     1165 <writeBigInt+0x55>
mov    $0x1,%edx
mov    %r8d,%eax
xchg   %ax,%ax
sar    $0x7,%eax
mov    %eax,%ecx
or     $0x80,%ecx
movzbl %cl,%ecx
mov    %ecx,-0x4(%rsi)
add    $0xfffffffffffffffc,%rsi
add    $0x1,%rdx
cmp    $0x3fff,%r8d
mov    %eax,%r8d
ja     1140 <writeBigInt+0x30>
call   1030 <write@plt>
add    $0x88,%rsp
ret

LLVM IR (-O0):
define void @writeBigInt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [32 x i32]
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 32
store i32* %9, i32** %6
store i64 0, i64* %7
store i32 0, i32* %8
br label %10
10: ; preds = %21, %2
%11 = load i32, i32* %4
%12 = and i32 %11, 127
%13 = load i32, i32* %8
%14 = or i32 %12, %13
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i32 -1
store i32* %16, i32** %6
store i32 %14, i32* %16
store i32 128, i32* %8
%17 = load i64, i64* %7
%18 = add i64 %17, 1
store i64 %18, i64* %7
%19 = load i32, i32* %4
%20 = ashr i32 %19, 7
store i32 %20, i32* %4
br label %21
21: ; preds = %10
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %10, label %24
24: ; preds = %21
%25 = load i32, i32* %3
%26 = load i32*, i32** %6
%27 = load i64, i64* %7
%28 = call i32 @write(i32 %25, i32* %26, i64 %27)
ret void
}

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