#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 */
scalar_t__ isprint(int);
int /*<<< orphan*/ isspace(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *quantum_visual(int ch) {
  static char s1[10], s2[10], s3[10];
  static char *s = s2;
  s = (s == s1) ? s2 : (s == s2) ? s3 : s1;
  if ((isprint(ch)) && (!isspace(ch)))
    sprintf(s, "%c", ch);
  else
    sprintf(s, "%02X", ch);
  return s;
}


x86 assembly (clang, -O0):
<quantum_visual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2eff(%rip),%rax
cmp    %rax,0x2eef(%rip)
jne    115f <quantum_visual+0x2f>
lea    0x2ef5(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1186 <quantum_visual+0x56>
mov    0x2ed2(%rip),%rdx
lea    0x2ede(%rip),%rsi
lea    0x2ecd(%rip),%rax
lea    0x2eda(%rip),%rcx
cmp    %rsi,%rdx
cmove  %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,0x2ea7(%rip)
mov    -0x4(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11cf <quantum_visual+0x9f>
mov    -0x4(%rbp),%edi
call   1030 <isspace@plt>
cmp    $0x0,%eax
jne    11cf <quantum_visual+0x9f>
mov    0x2e7d(%rip),%rdi
mov    -0x4(%rbp),%edx
lea    0xe3b(%rip),%rsi
call   1050 <sprintf@plt>
jmp    11e5 <quantum_visual+0xb5>
mov    0x2e62(%rip),%rdi
mov    -0x4(%rbp),%edx
lea    0xe23(%rip),%rsi
call   1050 <sprintf@plt>
mov    0x2e4c(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quantum_visual>:
push   %rbx
mov    %edi,%ebx
mov    0x2efe(%rip),%rax
lea    0x2f00(%rip),%rcx
lea    0x2f03(%rip),%rdx
cmp    %rdx,%rax
lea    0x2f03(%rip),%rsi
cmovne %rcx,%rsi
cmp    %rcx,%rax
cmove  %rdx,%rsi
mov    %rsi,0x2ed4(%rip)
call   1040 <isprint@plt>
test   %rax,%rax
je     1179 <quantum_visual+0x49>
mov    %ebx,%edi
call   1030 <isspace@plt>
test   %eax,%eax
je     1197 <quantum_visual+0x67>
mov    0x2eb8(%rip),%rdi
lea    0xe79(%rip),%rsi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    0x2ea3(%rip),%rax
pop    %rbx
ret
mov    0x2e9a(%rip),%rax
mov    %bl,(%rax)
movb   $0x0,0x1(%rax)
pop    %rbx
ret

LLVM IR (-O0):
@quantum_visual.s1 = internal global [10 x i8] zeroinitializer
@quantum_visual.s2 = internal global [10 x i8] zeroinitializer
@quantum_visual.s3 = internal global [10 x i8] zeroinitializer
@quantum_visual.s = internal global i8* getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s2, i32 0, i32 0)
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"%02X\00"
define i8* @quantum_visual(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i8*, i8** @quantum_visual.s
%4 = icmp eq i8* %3, getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s1, i64 0, i64 0)
br i1 %4, label %5, label %6
5: ; preds = %1
br label %11
6: ; preds = %1
%7 = load i8*, i8** @quantum_visual.s
%8 = icmp eq i8* %7, getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s2, i64 0, i64 0)
%9 = zext i1 %8 to i64
%10 = select i1 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s1, i64 0, i64 0)
br label %11
11: ; preds = %6, %5
%12 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s2, i64 0, i64 0), %5 ], [ %10, %6 ]
store i8* %12, i8** @quantum_visual.s
%13 = load i32, i32* %2
%14 = call i64 @isprint(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i32, i32* %2
%18 = call i32 @isspace(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i8*, i8** @quantum_visual.s
%22 = load i32, i32* %2
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %28
24: ; preds = %16, %11
%25 = load i8*, i8** @quantum_visual.s
%26 = load i32, i32* %2
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %20
%29 = load i8*, i8** @quantum_visual.s
ret i8* %29
}

LLVM IR (-O2):
@quantum_visual.s1 = internal global [10 x i8] zeroinitializer
@quantum_visual.s2 = internal global [10 x i8] zeroinitializer
@quantum_visual.s3 = internal global [10 x i8] zeroinitializer
@quantum_visual.s = internal unnamed_addr global i8* getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s2, i64 0, i64 0)
@.str.1 = [5 x i8] c"%02X\00"
define i8* @quantum_visual(i32 %0) {
%2 = load i8*, i8** @quantum_visual.s
%3 = icmp eq i8* %2, getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s1, i64 0, i64 0)
%4 = icmp eq i8* %2, getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s2, i64 0, i64 0)
%5 = select i1 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s1, i64 0, i64 0)
%6 = select i1 %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @quantum_visual.s2, i64 0, i64 0), i8* %5
store i8* %6, i8** @quantum_visual.s
%7 = tail call i64 @isprint(i32 %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = tail call i32 @isspace(i32 %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i8*, i8** @quantum_visual.s
%14 = trunc i32 %0 to i8
store i8 %14, i8* %13
%15 = getelementptr i8, i8* %13, i64 1
store i8 0, i8* %15
br label %20
16: ; preds = %9, %1
%17 = load i8*, i8** @quantum_visual.s
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%19 = load i8*, i8** @quantum_visual.s
br label %20
20: ; preds = %16, %12
%21 = phi i8* [ %19, %16 ], [ %13, %12 ]
ret i8* %21
}