#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*/ putc(unsigned char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void encode_num(int num, int is_literal) {
  unsigned char ch;
  unsigned int x = num;
  if (is_literal)
    x = num < 0 ? (-x << 1) | 1 : x << 1;
  while (x & ~0x7f) {
    ch = (x & 0x7f) | 0x80;
    putc(ch, stdout);
    x >>= 7;
  }
  ch = x;
  putc(ch, stdout);
}


x86 assembly (clang, -O0):
<encode_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     115a <encode_num+0x4a>
cmpl   $0x0,-0x4(%rbp)
jge    114b <encode_num+0x3b>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
shl    $0x1,%eax
or     $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <encode_num+0x44>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    115f <encode_num+0x4f>
mov    -0x10(%rbp),%eax
and    $0xffffff80,%eax
cmp    $0x0,%eax
je     119e <encode_num+0x8e>
mov    -0x10(%rbp),%eax
and    $0x7f,%eax
or     $0x80,%eax
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
mov    0x2e5a(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <putc@plt>
mov    -0x10(%rbp),%eax
shr    $0x7,%eax
mov    %eax,-0x10(%rbp)
jmp    115f <encode_num+0x4f>
mov    -0x10(%rbp),%eax
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
mov    0x2e32(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1030 <putc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_num>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
test   %esi,%esi
je     112b <encode_num+0x1b>
lea    (%rbx,%rbx,1),%eax
mov    $0x1,%ecx
sub    %eax,%ecx
test   %ebx,%ebx
cmovns %eax,%ecx
mov    %ecx,%ebx
cmp    $0x80,%ebx
jae    1137 <encode_num+0x27>
mov    %ebx,%ebp
jmp    115c <encode_num+0x4c>
mov    0x2ea2(%rip),%r14
mov    %ebx,%ebp
mov    %ebx,%eax
or     $0x80,%al
mov    (%r14),%esi
movzbl %al,%edi
call   1030 <putc@plt>
shr    $0x7,%ebp
cmp    $0x3fff,%ebx
mov    %ebp,%ebx
ja     1140 <encode_num+0x30>
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
movzbl %bpl,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putc@plt>

LLVM IR (-O0):
@stdout = global i32 0
define void @encode_num(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
store i32 %7, i32* %6
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* %6
%15 = sub i32 0, %14
%16 = shl i32 %15, 1
%17 = or i32 %16, 1
br label %21
18: ; preds = %10
%19 = load i32, i32* %6
%20 = shl i32 %19, 1
br label %21
21: ; preds = %18, %13
%22 = phi i32 [ %17, %13 ], [ %20, %18 ]
store i32 %22, i32* %6
br label %23
23: ; preds = %21, %2
br label %24
24: ; preds = %28, %23
%25 = load i32, i32* %6
%26 = and i32 %25, -128
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i32, i32* %6
%30 = and i32 %29, 127
%31 = or i32 %30, 128
%32 = trunc i32 %31 to i8
store i8 %32, i8* %5
%33 = load i8, i8* %5
%34 = load i32, i32* @stdout
%35 = call i32 @putc(i8 zeroext %33, i32 %34)
%36 = load i32, i32* %6
%37 = lshr i32 %36, 7
store i32 %37, i32* %6
br label %24
38: ; preds = %24
%39 = load i32, i32* %6
%40 = trunc i32 %39 to i8
store i8 %40, i8* %5
%41 = load i8, i8* %5
%42 = load i32, i32* @stdout
%43 = call i32 @putc(i8 zeroext %41, i32 %42)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @encode_num(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = icmp slt i32 %0, 0
%6 = mul i32 %0, -2
%7 = or i32 %6, 1
%8 = shl i32 %0, 1
%9 = select i1 %5, i32 %7, i32 %8
br label %10
10: ; preds = %4, %2
%11 = phi i32 [ %9, %4 ], [ %0, %2 ]
%12 = icmp ult i32 %11, 128
br i1 %12, label %21, label %13
13: ; preds = %10, %13
%14 = phi i32 [ %19, %13 ], [ %11, %10 ]
%15 = trunc i32 %14 to i8
%16 = or i8 %15, -128
%17 = load i32, i32* @stdout
%18 = tail call i32 @putc(i8 zeroext %16, i32 %17)
%19 = lshr i32 %14, 7
%20 = icmp ult i32 %14, 16384
br i1 %20, label %21, label %13
21: ; preds = %13, %10
%22 = phi i32 [ %11, %10 ], [ %19, %13 ]
%23 = trunc i32 %22 to i8
%24 = load i32, i32* @stdout
%25 = tail call i32 @putc(i8 zeroext %23, i32 %24)
ret void
}