char *ctrl(c)
char c;
{
  static char s[3];
  if (c < 040 || c == 0177) {
    s[0] = '^';
    s[1] = c == 0177 ? '?' : c + 'A' - 1;
    s[2] = '\0';
  } else {
    s[0] = c;
    s[1] = '\0';
  }
  return (s);
}


x86 assembly (clang, -O0):
<ctrl>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x20,%eax
jl     1124 <ctrl+0x24>
movsbl -0x1(%rbp),%eax
cmp    $0x7f,%eax
jne    1167 <ctrl+0x67>
movb   $0x5e,0x2ef6(%rip)
movsbl -0x1(%rbp),%eax
cmp    $0x7f,%eax
jne    1145 <ctrl+0x45>
mov    $0x3f,%eax
mov    %eax,-0x8(%rbp)
jmp    1152 <ctrl+0x52>
movsbl -0x1(%rbp),%eax
add    $0x41,%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,0x2ec7(%rip)
movb   $0x0,0x2ec1(%rip)
jmp    1177 <ctrl+0x77>
mov    -0x1(%rbp),%al
mov    %al,0x2eb1(%rip)
movb   $0x0,0x2eab(%rip)
lea    0x2ea3(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctrl>:
mov    %edi,%eax
shl    $0x18,%eax
cmp    $0x20000000,%eax
jl     1123 <ctrl+0x23>
cmp    $0x7f000000,%eax
je     1123 <ctrl+0x23>
mov    %dil,0x2f07(%rip)
lea    0x2f01(%rip),%rax
jmp    114c <ctrl+0x4c>
add    $0x40,%dil
cmp    $0x7f000000,%eax
movb   $0x5e,0x2eee(%rip)
movzbl %dil,%eax
mov    $0x3f,%ecx
cmovne %eax,%ecx
mov    %cl,0x2edd(%rip)
lea    0x2ed7(%rip),%rax
movb   $0x0,(%rax)
lea    0x2ecb(%rip),%rax
ret

LLVM IR (-O0):
@ctrl.s = internal global [3 x i8] zeroinitializer
define i8* @ctrl(i32 %0) {
%2 = alloca i8
%3 = trunc i32 %0 to i8
store i8 %3, i8* %2
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = icmp slt i32 %5, 32
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 127
br i1 %10, label %11, label %24
11: ; preds = %7, %1
store i8 94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 127
br i1 %14, label %15, label %16
15: ; preds = %11
br label %21
16: ; preds = %11
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = add nsw i32 %18, 65
%20 = sub nsw i32 %19, 1
br label %21
21: ; preds = %16, %15
%22 = phi i32 [ 63, %15 ], [ %20, %16 ]
%23 = trunc i32 %22 to i8
store i8 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 1)
store i8 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 2)
br label %26
24: ; preds = %7
%25 = load i8, i8* %2
store i8 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 1)
br label %26
26: ; preds = %24, %21
ret i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
}

LLVM IR (-O2):
@ctrl.s = internal global [3 x i8] zeroinitializer
define i8* @ctrl(i32 %0) {
%2 = shl i32 %0, 24
%3 = icmp slt i32 %2, 536870912
%4 = icmp eq i32 %2, 2130706432
%5 = or i1 %3, %4
br i1 %5, label %6, label %10
6: ; preds = %1
store i8 94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
%7 = trunc i32 %0 to i8
%8 = add i8 %7, 64
%9 = select i1 %4, i8 63, i8 %8
store i8 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 1)
br label %12
10: ; preds = %1
%11 = trunc i32 %0 to i8
store i8 %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
br label %12
12: ; preds = %10, %6
%13 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 1), %10 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 2), %6 ]
store i8 0, i8* %13
ret i8* getelementptr inbounds ([3 x i8], [3 x i8]* @ctrl.s, i64 0, i64 0)
}