#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*/ isprint(unsigned char);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char, ...);
char *tag2str(int tag) {
  int i;
  static int si = 0;
  static char buf[5][20];
  char *bp;
  unsigned char c[4];
  bp = buf[si++];
  si %= 5;
  c[0] = 0xff & (tag >> 24);
  c[1] = 0xff & (tag >> 16);
  c[2] = 0xff & (tag >> 8);
  c[3] = 0xff & (tag >> 0);
  for (i = 0; i < 4; i++) {
    if (!isprint(c[i]))
      break;
  }
  if (i < 4) {
    sprintf(bp, "0x%x", tag);
  } else {
    sprintf(bp, "'%c%c%c%c'", c[0], c[1], c[2], c[3]);
  }
  return bp;
}


x86 assembly (clang, -O0):
<tag2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2f0f(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2f04(%rip)
movslq %eax,%rcx
lea    0x2f0a(%rip),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    0x2ee9(%rip),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,0x2edb(%rip)
mov    -0x4(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,-0x14(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x13(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x12(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x0,%eax
and    $0xff,%eax
mov    %al,-0x11(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11dd <tag2str+0xbd>
movslq -0x8(%rbp),%rax
movzbl -0x14(%rbp,%rax,1),%edi
call   1030 <isprint@plt>
cmp    $0x0,%eax
jne    11ca <tag2str+0xaa>
jmp    11dd <tag2str+0xbd>
jmp    11cf <tag2str+0xaf>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a4 <tag2str+0x84>
cmpl   $0x4,-0x8(%rbp)
jge    1204 <tag2str+0xe4>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
lea    0xe0b(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    122a <tag2str+0x10a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%al
movzbl -0x13(%rbp),%ecx
movzbl -0x12(%rbp),%r8d
movzbl -0x11(%rbp),%r9d
lea    0xde5(%rip),%rsi
movzbl %al,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag2str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
mov    0x2f0c(%rip),%eax
lea    0x1(%rax),%ecx
lea    (%rax,%rax,4),%rax
lea    0x2f0e(%rip),%rdx
lea    (%rdx,%rax,4),%r14
movslq %ecx,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,0x2ed8(%rip)
mov    %edi,%ebp
shr    $0x18,%ebp
mov    %ebp,%edi
call   1030 <isprint@plt>
movzbl %r12b,%r15d
test   %eax,%eax
je     11d0 <tag2str+0xb0>
mov    %r12d,%ebx
shr    $0x10,%ebx
movzbl %bl,%edi
call   1030 <isprint@plt>
test   %eax,%eax
je     11d0 <tag2str+0xb0>
mov    %r12d,%r13d
shr    $0x8,%r13d
movzbl %r13b,%edi
call   1030 <isprint@plt>
test   %eax,%eax
je     11d0 <tag2str+0xb0>
mov    %r15d,%edi
call   1030 <isprint@plt>
test   %eax,%eax
je     11d0 <tag2str+0xb0>
movzbl %bl,%ecx
movzbl %r13b,%r8d
movzbl %r12b,%r9d
movzbl %bpl,%edx
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    11e4 <tag2str+0xc4>
lea    0xe29(%rip),%rsi
mov    %r14,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@tag2str.si = internal global i32 0
@tag2str.buf = internal global [5 x [20 x i8]] zeroinitializer
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [11 x i8] c"'%c%c%c%c'\00"
define i8* @tag2str(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [4 x i8]
store i32 %0, i32* %2
%6 = load i32, i32* @tag2str.si
%7 = add nsw i32 %6, 1
store i32 %7, i32* @tag2str.si
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds [5 x [20 x i8]], [5 x [20 x i8]]* @tag2str.buf, i64 0, i64 %8
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
store i8* %10, i8** %4
%11 = load i32, i32* @tag2str.si
%12 = srem i32 %11, 5
store i32 %12, i32* @tag2str.si
%13 = load i32, i32* %2
%14 = ashr i32 %13, 24
%15 = and i32 255, %14
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 %16, i8* %17
%18 = load i32, i32* %2
%19 = ashr i32 %18, 16
%20 = and i32 255, %19
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %21, i8* %22
%23 = load i32, i32* %2
%24 = ashr i32 %23, 8
%25 = and i32 255, %24
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 %26, i8* %27
%28 = load i32, i32* %2
%29 = ashr i32 %28, 0
%30 = and i32 255, %29
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 %31, i8* %32
store i32 0, i32* %3
br label %33
33: ; preds = %45, %1
%34 = load i32, i32* %3
%35 = icmp slt i32 %34, 4
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @isprint(i8 zeroext %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %36
br label %48
44: ; preds = %36
br label %45
45: ; preds = %44
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %33
48: ; preds = %43, %33
%49 = load i32, i32* %3
%50 = icmp slt i32 %49, 4
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i8*, i8** %4
%53 = load i32, i32* %2
%54 = trunc i32 %53 to i8
%55 = call i32 (i8*, i8*, i8, ...) @sprintf(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %54)
br label %70
56: ; preds = %48
%57 = load i8*, i8** %4
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%59 = load i8, i8* %58
%60 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = call i32 (i8*, i8*, i8, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %59, i32 %62, i32 %65, i32 %68)
br label %70
70: ; preds = %56, %51
%71 = load i8*, i8** %4
ret i8* %71
}

LLVM IR (-O2):
@tag2str.si = internal unnamed_addr global i32 0
@tag2str.buf = internal global [5 x [20 x i8]] zeroinitializer
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [11 x i8] c"'%c%c%c%c'\00"
define i8* @tag2str(i32 %0) {
%2 = load i32, i32* @tag2str.si
%3 = add nsw i32 %2, 1
%4 = zext i32 %2 to i64
%5 = getelementptr inbounds [5 x [20 x i8]], [5 x [20 x i8]]* @tag2str.buf, i64 0, i64 %4, i64 0
%6 = srem i32 %3, 5
store i32 %6, i32* @tag2str.si
%7 = lshr i32 %0, 24
%8 = trunc i32 %7 to i8
%9 = lshr i32 %0, 16
%10 = lshr i32 %0, 8
%11 = trunc i32 %10 to i8
%12 = trunc i32 %0 to i8
%13 = tail call i32 @isprint(i8 zeroext %8)
%14 = icmp eq i32 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %1
%16 = trunc i32 %9 to i8
%17 = tail call i32 @isprint(i8 zeroext %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %30, label %19
19: ; preds = %15
%20 = tail call i32 @isprint(i8 zeroext %11)
%21 = icmp eq i32 %20, 0
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = tail call i32 @isprint(i8 zeroext %12)
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = and i32 %9, 255
%27 = and i32 %10, 255
%28 = and i32 %0, 255
%29 = tail call i32 (i8*, i8*, i8, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %8, i32 %26, i32 %27, i32 %28)
br label %32
30: ; preds = %22, %19, %15, %1
%31 = tail call i32 (i8*, i8*, i8, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
br label %32
32: ; preds = %25, %30
ret i8* %5
}