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

/* Variables and functions */
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int getIntSize(int);
void writeTag(FILE *fp, int type, int val) {
  int tempSize;
  int i;
  tempSize = getIntSize(val);
  if (tempSize) {
    fputc((type | tempSize | 0x10), fp);
    for (i = 0; i < tempSize; i++)
      fputc((val >> (8 * i)), fp);
  } else {
    fputc((type | val), fp);
  }
}


x86 assembly (clang, -O0):
<writeTag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <getIntSize@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1193 <writeTag+0x73>
mov    -0xc(%rbp),%edi
or     -0x14(%rbp),%edi
or     $0x10,%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118e <writeTag+0x6e>
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%ecx
shl    $0x3,%ecx
sar    %cl,%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1160 <writeTag+0x40>
jmp    11a2 <writeTag+0x82>
mov    -0xc(%rbp),%edi
or     -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeTag>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r14
mov    %edx,%edi
call   1040 <getIntSize@plt>
test   %eax,%eax
je     1182 <writeTag+0x62>
mov    %eax,%ebp
or     %eax,%ebx
or     $0x10,%ebx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
test   %ebp,%ebp
jle    1177 <writeTag+0x57>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %ebx,%ecx
sar    %cl,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0x8,%ebx
add    $0xffffffff,%ebp
jne    1160 <writeTag+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
or     %ebx,%r15d
mov    %r15d,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

LLVM IR (-O0):
define void @writeTag(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = call i32 @getIntSize(i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %3
%14 = load i32, i32* %5
%15 = load i32, i32* %7
%16 = or i32 %14, %15
%17 = or i32 %16, 16
%18 = load i32*, i32** %4
%19 = call i32 @fputc(i32 %17, i32* %18)
store i32 0, i32* %8
br label %20
20: ; preds = %31, %13
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = mul nsw i32 8, %26
%28 = ashr i32 %25, %27
%29 = load i32*, i32** %4
%30 = call i32 @fputc(i32 %28, i32* %29)
br label %31
31: ; preds = %24
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %20
34: ; preds = %20
br label %41
35: ; preds = %3
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = or i32 %36, %37
%39 = load i32*, i32** %4
%40 = call i32 @fputc(i32 %38, i32* %39)
br label %41
41: ; preds = %35, %34
ret void
}

LLVM IR (-O2):
define void @writeTag(i32* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 @getIntSize(i32 %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = or i32 %4, %1
%8 = or i32 %7, 16
%9 = tail call i32 @fputc(i32 %8, i32* %0)
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %21
11: ; preds = %6, %11
%12 = phi i32 [ %16, %11 ], [ 0, %6 ]
%13 = shl nsw i32 %12, 3
%14 = ashr i32 %2, %13
%15 = tail call i32 @fputc(i32 %14, i32* %0)
%16 = add nuw nsw i32 %12, 1
%17 = icmp eq i32 %16, %4
br i1 %17, label %21, label %11
18: ; preds = %3
%19 = or i32 %2, %1
%20 = tail call i32 @fputc(i32 %19, i32* %0)
br label %21
21: ; preds = %11, %6, %18
ret void
}