#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char, ...);
int varint32_encode(int, char *, int);
int main() {
  char varint[100];
  printf("%d bytes written\n", varint32_encode(-1, varint, 100));
  printf("%hhX %hhX %hhX %hhX %hhX\n", varint[0], varint[1], varint[2],
         varint[3], varint[4]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x70(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x64,%edx
call   1040 <varint32_encode@plt>
lea    0xebe(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x70(%rbp),%al
movsbl -0x6f(%rbp),%edx
movsbl -0x6e(%rbp),%ecx
movsbl -0x6d(%rbp),%r8d
movsbl -0x6c(%rbp),%r9d
lea    0xeaa(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
mov    %rsp,%rsi
mov    $0xffffffff,%edi
mov    $0x64,%edx
call   1040 <varint32_encode@plt>
movsbl %al,%esi
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movsbl (%rsp),%esi
movsbl 0x1(%rsp),%edx
movsbl 0x2(%rsp),%ecx
movsbl 0x3(%rsp),%r8d
movsbl 0x4(%rsp),%r9d
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%d bytes written\0A\00"
@.str.1 = [26 x i8] c"%hhX %hhX %hhX %hhX %hhX\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @varint32_encode(i32 -1, i8* %2, i32 100)
%4 = trunc i32 %3 to i8
%5 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8 signext %4)
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%7 = load i8, i8* %6
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8 signext %7, i32 %10, i32 %13, i32 %16, i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"%d bytes written\0A\00"
@.str.1 = [26 x i8] c"%hhX %hhX %hhX %hhX %hhX\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @varint32_encode(i32 -1, i8* %2, i32 100)
%4 = trunc i32 %3 to i8
%5 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8 signext %4)
%6 = load i8, i8* %2
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8 signext %6, i32 %9, i32 %12, i32 %15, i32 %18)
ret i32 0
}