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

/* Variables and functions */
int ebml_int_size(int /*<<< orphan*/);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
void write_ebml_int(FILE *file, uint64_t i) {
  int size = ebml_int_size(i);
  unsigned char *p_first = (char *)&i;
  unsigned char *p_current = p_first + (size - 1);
  fputc(*p_current | 1 << (8 - size), file);
  for (p_current--; p_current >= p_first; p_current--) {
    fputc(*p_current, file);
  }
}


x86 assembly (clang, -O0):
<write_ebml_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <ebml_int_size@plt>
mov    %eax,-0x10(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    $0x8,%ecx
sub    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <fputc@plt>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     11b9 <write_ebml_int+0x99>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <fputc@plt>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1188 <write_ebml_int+0x68>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ebml_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    %esi,0xc(%rsp)
mov    %esi,%edi
call   1040 <ebml_int_size@plt>
movslq %eax,%rbx
mov    $0x8,%cl
sub    %bl,%cl
mov    $0x1,%eax
shl    %cl,%eax
lea    0xc(%rsp),%r14
or     -0x1(%rbx,%r14,1),%al
movzbl %al,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
add    %r14,%rbx
add    $0xfffffffffffffffe,%rbx
cmp    %r14,%rbx
jb     1184 <write_ebml_int+0x64>
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx),%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1170 <write_ebml_int+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @write_ebml_int(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = call i32 @ebml_int_size(i32 %8)
store i32 %9, i32* %5
%10 = bitcast i32* %4 to i8*
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = load i32, i32* %5
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = load i32, i32* %5
%20 = sub nsw i32 8, %19
%21 = shl i32 1, %20
%22 = or i32 %18, %21
%23 = trunc i32 %22 to i8
%24 = load i32*, i32** %3
%25 = call i32 @fputc(i8 zeroext %23, i32* %24)
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %7
br label %28
28: ; preds = %37, %2
%29 = load i8*, i8** %7
%30 = load i8*, i8** %6
%31 = icmp uge i8* %29, %30
br i1 %31, label %32, label %40
32: ; preds = %28
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = load i32*, i32** %3
%36 = call i32 @fputc(i8 zeroext %34, i32* %35)
br label %37
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i32 -1
store i8* %39, i8** %7
br label %28
40: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @write_ebml_int(i32* nocapture %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = tail call i32 @ebml_int_size(i32 %1)
%5 = bitcast i32* %3 to i8*
%6 = add nsw i32 %4, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = load i8, i8* %8
%10 = sub nsw i32 8, %4
%11 = shl nuw i32 1, %10
%12 = trunc i32 %11 to i8
%13 = or i8 %9, %12
%14 = tail call i32 @fputc(i8 zeroext %13, i32* %0)
%15 = getelementptr inbounds i8, i8* %8, i64 -1
%16 = icmp ult i8* %15, %5
br i1 %16, label %23, label %17
17: ; preds = %2, %17
%18 = phi i8* [ %21, %17 ], [ %15, %2 ]
%19 = load i8, i8* %18
%20 = call i32 @fputc(i8 zeroext %19, i32* %0)
%21 = getelementptr inbounds i8, i8* %18, i64 -1
%22 = icmp ult i8* %21, %5
br i1 %22, label %23, label %17
23: ; preds = %17, %2
ret void
}